/*!
\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
__poly__
- 粉丝: 0
- 资源: 11
最新资源
- Laravel4.0参考手册中文CHM版最新版本
- teamteam下载包
- Laravel4.1参考手册中文CHM版最新版本
- 内墙装修涂料行业发展趋势:预计2030年年复合增长率(CAGR)为5.6%(2024-2030)
- seata运行时所需要的配置文件
- PowerBI-svg 仪表盘图
- 操作系统原理期末复习题(附答案)(摘自汤小丹《计算机操作系统》慕课版课后习题)
- 中国省级产业结构高级化、合理化数据测算(2000-2023年).zip
- Laravel5.1参考手册中文CHM版最新版本
- AI基础3-Pyqt.mp4
- WebSocket基础介绍.pdf
- VMWware全部版本下载地址
- 44e82cfa75fa0244b3037221d2eb830d.zip
- dkd-parent.zip
- dkd-vue.zip
- WiFi助手调试软件,有六个按键,可以设置IP地址,端口号,安卓手机安装,实现网口助手功能!
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
前往页