/*!
\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
没有合适的资源?快使用搜索试试~ 我知道了~
wenshidu.rar_Qt温湿度_报警
共63个文件
svn-base:25个
h:12个
cpp:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 35 浏览量
2022-09-24
17:54:18
上传
评论 2
收藏 202KB RAR 举报
温馨提示
此代码很好的实现了温湿度的下位机显示报警等一系列功能。
资源推荐
资源详情
资源评论
收起资源包目录
wenshidu.rar (63个子文件)
wenshidu
imframe.cpp 1KB
set.cpp 6KB
mainw.ui 17KB
data.h 82B
shuju.cpp 196B
STANDIN.WAV 113KB
gongyong.h 83B
arm.h 49B
jianpan.h 436B
wenshidu.pro 711B
lishi.cpp 3KB
mainw.cpp 12KB
qextserialbase.h 7KB
imframe.h 453B
main.cpp 3KB
jianpan.cpp 2KB
posix_qextserialport.h 2KB
wenshidu.pro.user 13KB
lishi.h 684B
jianpan.ui 8KB
qextserialbase.cpp 6KB
set.ui 14KB
linux.cpp 252B
posix_qextserialport.cpp 37KB
.svn
prop-base
qextserialbase.cpp.svn-revert 4B
STANDIN.WAV.svn-base 53B
qextserialbase.h.svn-revert 4B
props
tmp
prop-base
tempfile.4.tmp 0B
tempfile.tmp 0B
tempfile.2.tmp 0B
props
text-base
tempfile.3.tmp 0B
text-base
jianpan.h.svn-base 436B
mainw.cpp.svn-base 11KB
set.cpp.svn-base 5KB
data.h.svn-base 82B
wenshidu.pro.user.svn-base 13KB
lishi.cpp.svn-base 3KB
qextserialbase.cpp.svn-revert 6KB
win_qextserialport.cpp.svn-base 34KB
mainw.h.svn-base 2KB
jianpan.cpp.svn-base 2KB
wenshidu.pro.svn-base 817B
lishi.ui.svn-base 3KB
shuju.cpp.svn-base 210B
lishi.h.svn-base 628B
mainw.ui.svn-base 17KB
gongyong.h.svn-base 83B
jianpan.ui.svn-base 8KB
imframe.cpp.svn-base 1KB
main.cpp.svn-base 3KB
set.ui.svn-base 11KB
shuju.h.svn-base 346B
STANDIN.WAV.svn-base 113KB
qextserialbase.h.svn-revert 7KB
imframe.h.svn-base 453B
win_qextserialport.h.svn-base 4KB
set.h.svn-base 641B
entries 4KB
shuju.h 309B
linux.h 312B
mainw.h 2KB
set.h 656B
lishi.ui 3KB
共 63 条
- 1
资源评论
- m0_703465712024-04-25资源不错,很实用,内容全面,介绍详细,很好用,谢谢分享。
钱亚锋
- 粉丝: 88
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功