/*!
\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.");
#ifdef CBAUD
Posix_CommConfig.c_cflag &= (~CBAUD);
Posix_CommConfig.c_cflag |= B50;
#else
cfsetispeed(&Posix_CommConfig, B50);
cfsetospeed(&Posix_CommConfig, B50);
#endif
break;
/*75 baud*/
case BAUD75:
TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 75 baud operation
没有合适的资源?快使用搜索试试~ 我知道了~
linux平台的串口助手
共22个文件
h:7个
cpp:7个
ui:2个
4星 · 超过85%的资源 需积分: 9 146 下载量 166 浏览量
2012-05-24
13:45:31
上传
评论 2
收藏 33KB RAR 举报
温馨提示
linux平台的串口助手 非常好用,功能强大 (我灰常需要积分下载这里的资源,谢谢好心人)
资源推荐
资源详情
资源评论
收起资源包目录
ComDebugger.rar (22个子文件)
ComDebugger
ComDebugger.pro 881B
comdebugger.ui 1KB
Makefile.Debug 11KB
comdebugger.h 2KB
comdebugger.cpp 16KB
uiInputFileName.h 441B
src
armapi
qextserialbase.h 7KB
posix_qextserialport.h 2KB
qextserialbase.cpp 6KB
posix_qextserialport.cpp 33KB
uStruct.h 672B
widget
uiSetComPara.cpp 7KB
uiSetComPara.h 356B
MyTextEdit.h 451B
MyTextEdit.cpp 949B
uiSetComPara.ui 5KB
Makefile.Release 11KB
.project 2KB
uiInputFileName.cpp 1KB
.cproject 27KB
main.cpp 701B
Makefile 12KB
共 22 条
- 1
__poly__
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页