/****************************************************************************
** Copyright (c) 2000-2003 Wayne Roth
** Copyright (c) 2004-2007 Stefan Sander
** Copyright (c) 2007 Michal Policht
** Copyright (c) 2008 Brandon Fosdick
** Copyright (c) 2009-2010 Liam Staskawicz
** Copyright (c) 2011 Debao Zhang
** All right reserved.
** Web: http://code.google.com/p/qextserialport/
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
****************************************************************************/
#include "qextserialport.h"
#include "qextserialport_p.h"
#include <stdio.h>
#include <QtCore/QDebug>
#include <QtCore/QReadLocker>
#include <QtCore/QWriteLocker>
/*!
\class PortSettings
\brief The PortSettings class contain port settings
Structure to contain port settings.
\code
BaudRateType BaudRate;
DataBitsType DataBits;
ParityType Parity;
StopBitsType StopBits;
FlowType FlowControl;
long Timeout_Millisec;
\endcode
*/
QextSerialPortPrivate::QextSerialPortPrivate(QextSerialPort *q)
:lock(QReadWriteLock::Recursive), q_ptr(q)
{
lastErr = E_NO_ERROR;
settings.BaudRate = BAUD9600;
settings.Parity = PAR_NONE;
settings.FlowControl = FLOW_OFF;
settings.DataBits = DATA_8;
settings.StopBits = STOP_1;
settings.Timeout_Millisec = 10;
settingsDirtyFlags = DFE_ALL;
platformSpecificInit();
}
QextSerialPortPrivate::~QextSerialPortPrivate()
{
platformSpecificDestruct();
}
void QextSerialPortPrivate::setBaudRate(BaudRateType baudRate, bool update)
{
switch (baudRate) {
#ifdef Q_OS_WIN
//Windows Special
case BAUD14400:
case BAUD56000:
case BAUD128000:
case BAUD256000:
QESP_PORTABILITY_WARNING()<<"QextSerialPort Portability Warning: POSIX does not support baudRate:"<<baudRate;
#elif defined(Q_OS_UNIX)
//Unix Special
case BAUD50:
case BAUD75:
case BAUD134:
case BAUD150:
case BAUD200:
case BAUD1800:
# ifdef B76800
case BAUD76800:
# endif
# if defined(B230400) && defined(B4000000)
case BAUD230400:
case BAUD460800:
case BAUD500000:
case BAUD576000:
case BAUD921600:
case BAUD1000000:
case BAUD1152000:
case BAUD1500000:
case BAUD2000000:
case BAUD2500000:
case BAUD3000000:
case BAUD3500000:
case BAUD4000000:
# endif
QESP_PORTABILITY_WARNING()<<"QextSerialPort Portability Warning: Windows does not support baudRate:"<<baudRate;
#endif
case BAUD110:
case BAUD300:
case BAUD600:
case BAUD1200:
case BAUD2400:
case BAUD4800:
case BAUD9600:
case BAUD19200:
case BAUD38400:
case BAUD57600:
case BAUD115200:
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
default:
#endif
settings.BaudRate = baudRate;
settingsDirtyFlags |= DFE_BaudRate;
if (update && q_func()->isOpen())
updatePortSettings();
break;
#if !(defined(Q_OS_WIN) || defined(Q_OS_MAC))
default:
QESP_WARNING()<<"QextSerialPort does not support baudRate:"<<baudRate;
#endif
}
}
void QextSerialPortPrivate::setParity(ParityType parity, bool update)
{
switch (parity) {
case PAR_SPACE:
if (settings.DataBits == DATA_8) {
#ifdef Q_OS_WIN
QESP_PORTABILITY_WARNING("QextSerialPort Portability Warning: Space parity with 8 data bits is not supported by POSIX systems.");
#else
QESP_WARNING("Space parity with 8 data bits is not supported by POSIX systems.");
#endif
}
break;
#ifdef Q_OS_WIN
/*mark parity - WINDOWS ONLY*/
case PAR_MARK:
QESP_PORTABILITY_WARNING("QextSerialPort Portability Warning: Mark parity is not supported by POSIX systems");
break;
#endif
case PAR_NONE:
case PAR_EVEN:
case PAR_ODD:
break;
default:
QESP_WARNING()<<"QextSerialPort does not support Parity:" << parity;
}
settings.Parity = parity;
settingsDirtyFlags |= DFE_Parity;
if (update && q_func()->isOpen())
updatePortSettings();
}
void QextSerialPortPrivate::setDataBits(DataBitsType dataBits, bool update)
{
switch(dataBits) {
case DATA_5:
if (settings.StopBits == STOP_2) {
QESP_WARNING("QextSerialPort: 5 Data bits cannot be used with 2 stop bits.");
}
else {
settings.DataBits = dataBits;
settingsDirtyFlags |= DFE_DataBits;
}
break;
case DATA_6:
#ifdef Q_OS_WIN
if (settings.StopBits == STOP_1_5) {
QESP_WARNING("QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits.");
}
else
#endif
{
settings.DataBits = dataBits;
settingsDirtyFlags |= DFE_DataBits;
}
break;
case DATA_7:
#ifdef Q_OS_WIN
if (settings.StopBits == STOP_1_5) {
QESP_WARNING("QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits.");
}
else
#endif
{
settings.DataBits = dataBits;
settingsDirtyFlags |= DFE_DataBits;
}
break;
case DATA_8:
#ifdef Q_OS_WIN
if (settings.StopBits == STOP_1_5) {
QESP_WARNING("QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits.");
}
else
#endif
{
settings.DataBits = dataBits;
settingsDirtyFlags |= DFE_DataBits;
}
break;
default:
QESP_WARNING()<<"QextSerialPort does not support Data bits:"<<dataBits;
}
if (update && q_func()->isOpen())
updatePortSettings();
}
void QextSerialPortPrivate::setStopBits(StopBitsType stopBits, bool update)
{
switch (stopBits) {
/*one stop bit*/
case STOP_1:
settings.StopBits = stopBits;
settingsDirtyFlags |= DFE_StopBits;
break;
#ifdef Q_OS_WIN
/*1.5 stop bits*/
case STOP_1_5:
QESP_PORTABILITY_WARNING("QextSerialPort Portability Warning: 1.5 stop bit operation is not supported by POSIX.");
if (settings.DataBits != DATA_5) {
QESP_WARNING("QextSerialPort: 1.5 stop bits can only be used with 5 data bits");
}
else {
settings.StopBits = stopBits;
settingsDirtyFlags |= DFE_StopBits;
}
break;
#endif
/*two stop bits*/
case STOP_2:
if (settings.DataBits == DATA_5) {
QESP_WARNING("QextSerialPort: 2 stop bits cannot be used with 5 data bits");
}
else {
settings.StopBits = stopBits;
settingsDirtyFlags |= DFE_StopBits;
}
break;
default:
QESP_WARNING()<<"QextSerialPort does not support stop bits: "<<stopB
没有合适的资源?快使用搜索试试~ 我知道了~
SinoWealth.rar基于Qt4+qextserialport-1.2rc的串口接受发送程序,支持USB端口热插拔自动检测
共47个文件
obj:12个
cpp:11个
h:7个
需积分: 9 3 下载量 125 浏览量
2021-12-24
09:58:31
上传
评论
收藏 1.32MB RAR 举报
温馨提示
基于Qt4+qextserialport-1.2rc的串口接受发送程序,支持USB端口热插拔自动检测,自动关闭拔出端口
资源详情
资源评论
资源推荐
收起资源包目录
SinoWealth.rar (47个子文件)
SinoWealth
build-SinoWealth-桌面-Debug
Makefile.Debug 10KB
1 48B
5 48B
Makefile.Release 10KB
ui_mainwindow.h 139KB
2 48B
debug
qextserialport_win.obj 128KB
win_qextserialport.obj 107KB
SinoWealth.pdb 1.95MB
moc_qextserialport.obj 53KB
moc_mainwindow.cpp 4KB
qextserialenumerator_win.obj 160KB
mainwindow.obj 1.02MB
moc_win_qextserialport.obj 53KB
moc_qextserialport.cpp 6KB
SinoWealth.ilk 1.64MB
qextserialbase.obj 50KB
moc_mainwindow.obj 60KB
main.obj 54KB
SinoWealth.exe 391KB
moc_qextserialenumerator.cpp 4KB
moc_qextserialbase.cpp 3KB
moc_win_qextserialport.cpp 3KB
qextserialport.obj 159KB
SinoWealth.intermediate.manifest 638B
moc_qextserialbase.obj 39KB
qextserialenumerator.obj 82KB
Makefile 7KB
6 48B
3 48B
release
vc100.pdb 1020KB
SinoWealth
serialSrc
src
qextserialport.h 7KB
qextserialenumerator.h 3KB
qextserialport_global.h 3KB
qextserialport.pri 1KB
qextserialenumerator_p.h 4KB
qextserialport.cpp 32KB
qextserialenumerator_win.cpp 12KB
qextserialport_win.cpp 15KB
qextserialenumerator.cpp 6KB
qextserialport_p.h 7KB
SinoWealth.pro 428B
SinoWealth.pro.user 17KB
main.cpp 388B
mainwindow.ui 151KB
mainwindow.cpp 18KB
mainwindow.h 3KB
共 47 条
- 1
xingtianhn
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0