/*!
\class Posix_QextSerialPort
\version 1.0.0
\author Stefan Sander
\author Michal Policht
A cross-platform serial port class.
This class encapsulates the POSIX portion of QextSerialPort. The user will be notified of errors
and possible portability conflicts at run-time by default - this behavior can be turned off by
defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off portability
warnings) in the project. Note that _TTY_NOWARN_ will also turn off portability warnings.
*/
#include <stdio.h>
#include "posix_qextserialport.h"
/*!
\fn Posix_QextSerialPort::Posix_QextSerialPort()
Default constructor. Note that the name of the device used by a QextSerialPort constructed with
this constructor will be determined by #defined constants, or lack thereof - the default behavior
is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are:
\verbatim
Constant Used By Naming Convention
---------- ------------- ------------------------
_TTY_WIN_ Windows COM1, COM2
_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2
_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0
_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb
_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02
_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1
_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1
<none> Linux /dev/ttyS0, /dev/ttyS1
\endverbatim
This constructor assigns the device name to the name of the first port on the specified system.
See the other constructors if you need to open a different port.
*/
Posix_QextSerialPort::Posix_QextSerialPort()
: QextSerialBase()
{
Posix_File=new QFile();
}
/*!
\fn Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort&)
Copy constructor.
*/
Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort& s)
: QextSerialBase(s.port)
{
setOpenMode(s.openMode());
port = s.port;
Settings.BaudRate=s.Settings.BaudRate;
Settings.DataBits=s.Settings.DataBits;
Settings.Parity=s.Settings.Parity;
Settings.StopBits=s.Settings.StopBits;
Settings.FlowControl=s.Settings.FlowControl;
lastErr=s.lastErr;
Posix_File=new QFile();
Posix_File=s.Posix_File;
memcpy(&Posix_Timeout, &s.Posix_Timeout, sizeof(struct timeval));
memcpy(&Posix_Copy_Timeout, &s.Posix_Copy_Timeout, sizeof(struct timeval));
memcpy(&Posix_CommConfig, &s.Posix_CommConfig, sizeof(struct termios));
}
/*!
\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name)
Constructs a serial port attached to the port specified by name.
name is the name of the device, which is windowsystem-specific,
e.g."COM1" or "/dev/ttyS0".
*/
Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode)
: QextSerialBase(name)
{
Posix_File=new QFile();
setQueryMode(mode);
init();
}
/*!
\fn Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings)
Constructs a port with default name and specified settings.
*/
Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode)
: QextSerialBase()
{
setBaudRate(settings.BaudRate);
setDataBits(settings.DataBits);
setParity(settings.Parity);
setStopBits(settings.StopBits);
setFlowControl(settings.FlowControl);
Posix_File=new QFile();
setTimeout(settings.Timeout_Millisec);
setQueryMode(mode);
init();
}
/*!
\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings)
Constructs a port with specified name and settings.
*/
Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode)
: QextSerialBase(name)
{
setBaudRate(settings.BaudRate);
setDataBits(settings.DataBits);
setParity(settings.Parity);
setStopBits(settings.StopBits);
setFlowControl(settings.FlowControl);
Posix_File=new QFile();
setTimeout(settings.Timeout_Millisec);
setQueryMode(mode);
init();
}
/*!
\fn Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s)
Override the = operator.
*/
Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s)
{
setOpenMode(s.openMode());
port = s.port;
Settings.BaudRate=s.Settings.BaudRate;
Settings.DataBits=s.Settings.DataBits;
Settings.Parity=s.Settings.Parity;
Settings.StopBits=s.Settings.StopBits;
Settings.FlowControl=s.Settings.FlowControl;
lastErr=s.lastErr;
Posix_File=s.Posix_File;
memcpy(&Posix_Timeout, &(s.Posix_Timeout), sizeof(struct timeval));
memcpy(&Posix_Copy_Timeout, &(s.Posix_Copy_Timeout), sizeof(struct timeval));
memcpy(&Posix_CommConfig, &(s.Posix_CommConfig), sizeof(struct termios));
return *this;
}
void Posix_QextSerialPort::init()
{
if (queryMode() == QextSerialBase::EventDriven)
qWarning("POSIX doesn't have event driven mechanism implemented yet");
}
/*!
\fn Posix_QextSerialPort::~Posix_QextSerialPort()
Standard destructor.
*/
Posix_QextSerialPort::~Posix_QextSerialPort()
{
if (isOpen()) {
close();
}
Posix_File->close();
delete Posix_File;
}
/*!
\fn void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate)
Sets the baud rate of the serial port. Note that not all rates are applicable on
all platforms. The following table shows translations of the various baud rate
constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an *
are speeds that are usable on both Windows and POSIX.
\note
BAUD76800 may not be supported on all POSIX systems. SGI/IRIX systems do not support
BAUD1800.
\verbatim
RATE Windows Speed POSIX Speed
----------- ------------- -----------
BAUD50 110 50
BAUD75 110 75
*BAUD110 110 110
BAUD134 110 134.5
BAUD150 110 150
BAUD200 110 200
*BAUD300 300 300
*BAUD600 600 600
*BAUD1200 1200 1200
BAUD1800 1200 1800
*BAUD2400 2400 2400
*BAUD4800 4800 4800
*BAUD9600 9600 9600
BAUD14400 14400 9600
*BAUD19200 19200 19200
*BAUD38400 38400 38400
BAUD56000 56000 38400
*BAUD57600 57600 57600
BAUD76800 57600 76800
*BAUD115200 115200 115200
BAUD128000 128000 115200
BAUD256000 256000 115200
\endverbatim
*/
void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate)
{
LOCK_MUTEX();
if (Settings.BaudRate!=baudRate) {
switch (baudRate) {
case BAUD14400:
Settings.BaudRate=BAUD9600;
break;
case BAUD56000:
Settings.BaudRate=BAUD38400;
break;
case BAUD76800:
#ifndef B76800
Settings.BaudRate=BAUD57600;
#else
Settings.BaudRate=baudRate;
#endif
break;
case BAUD128000:
case BAUD256000:
Settings.BaudRate=BAUD115200;
break;
default:
Settings.BaudRate=baudRate;
break;
}
}
if (isOpen()) {
switch (baudRate) {
/*50 baud*/
case BAUD50:
TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 50 baud operation.");
#if
没有合适的资源?快使用搜索试试~ 我知道了~
Qt串口编程第三方类qextserialport-1.2win-alpha.zip
共94个文件
html:35个
png:18个
cpp:12个
需积分: 11 14 下载量 85 浏览量
2015-01-11
22:30:54
上传
评论
收藏 270KB ZIP 举报
温馨提示
Qt没有自带的串口编程类,一般我们都使用这了第三方编写的类qextserialport,
资源推荐
资源详情
资源评论
收起资源包目录
qextserialport-1.2win-alpha.zip (94个子文件)
qextserialport-1.2win-alpha
qextserialport.h 867B
qextserialenumerator.h 2KB
win_qextserialport.cpp 34KB
win_qextserialport.h 4KB
CHANGES 12KB
Doxyfile 9KB
html
ftv2vertline.png 229B
qextserialport_8cpp.html 1KB
files.html 3KB
classQextSerialBase-members.html 20KB
ftv2folderclosed.png 259B
main.html 1KB
ftv2doc.png 255B
qextbasetype_8dox.html 1KB
hierarchy.html 2KB
classQextBaseType.html 305KB
classQextBaseType.png 1KB
classPosix__QextSerialPort.png 852B
classQextSerialBase.html 74KB
classPosix__QextSerialPort.html 196KB
posix__qextserialport_8cpp.html 1KB
classQextSerialPort.png 1KB
classes.html 3KB
ftv2blank.png 174B
functions.html 19KB
globals_eval.html 9KB
annotated.html 3KB
ftv2folderopen.png 261B
classQextSerialPort-members.html 48KB
tree.html 14KB
installdox 3KB
ftv2link.png 358B
index.html 318B
win__qextserialport_8cpp.html 1KB
doxygen.png 1KB
ftv2lastnode.png 233B
classWin__QextSerialPort.html 195KB
structPortSettings.html 8KB
classQextBaseType-members.html 46KB
globals.html 10KB
classWin__QextSerialPort.png 863B
ftv2node.png 235B
functions_vars.html 7KB
doxygen.css 8KB
posix__qextserialport_8h.html 2KB
mainpage_8dox.html 1KB
tab_r.gif 3KB
ftv2plastnode.png 165B
classWin__QextSerialPort-members.html 26KB
classQextSerialBase.png 1KB
globals_enum.html 2KB
tab_b.gif 35B
functions_func.html 15KB
ftv2mnode.png 194B
qextserialbase_8h.html 32KB
ftv2pnode.png 200B
tabs.css 2KB
ftv2mlastnode.png 160B
win__qextserialport_8h.html 2KB
qextserialport_8h.html 1KB
qextserialbase_8cpp.html 1KB
classQextSerialPort.html 314KB
tab_l.gif 706B
classPosix__QextSerialPort-members.html 24KB
structPortSettings-members.html 3KB
qextserialbase.h 7KB
qextserialport.cpp 3KB
doc
qiodevice.tag 6KB
qextbasetype.dox 304B
mainpage.dox 344B
examples
qespta
MessageWindow.cpp 3KB
Makefile.Debug 6KB
QespTest.cpp 3KB
MessageWindow.h 2KB
README 120B
Makefile.Release 6KB
QespTest.h 591B
MainWindow.h 853B
main.cpp 509B
MainWindow.cpp 2KB
Makefile 5KB
defs.h 334B
QESPTA.pro 699B
event
main.cpp 2KB
PortListener.h 869B
event.pro 605B
PortListener.cpp 1KB
enumerator
enumerator.pro 551B
main.cpp 704B
posix_qextserialport.h 2KB
qextserialport.pro 1KB
qextserialbase.cpp 6KB
posix_qextserialport.cpp 37KB
qextserialenumerator.cpp 5KB
共 94 条
- 1
资源评论
stabgever
- 粉丝: 4
- 资源: 91
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功