//#include <stdio.h>
//#include <Process.h>
//#include <QCoreApplication>
//#include <QEvent>
#include <QReadWriteLock>
#include "win_qextserialport.h"
/*!
\fn Win_QextSerialPort::Win_QextSerialPort()
Default constructor. Note that the name of the device used by a Win_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 associates the object with the first port on the system, e.g. COM1 for Windows
platforms. See the other constructor if you need a port other than the first.
*/
Win_QextSerialPort::Win_QextSerialPort():
QextSerialBase()
{
Win_Handle=INVALID_HANDLE_VALUE;
init();
}
/*!Win_QextSerialPort::Win_QextSerialPort(const Win_QextSerialPort&)
Copy constructor.
*/
Win_QextSerialPort::Win_QextSerialPort(const Win_QextSerialPort& s):
QextSerialBase(s.port)
{
Win_Handle=INVALID_HANDLE_VALUE;
_queryMode = s._queryMode;
_bytesToWrite = s._bytesToWrite;
bytesToWriteLock = new QReadWriteLock;
overlapThread = new Win_QextSerialThread(this);
memcpy(& overlap, & s.overlap, sizeof(OVERLAPPED));
memcpy(& overlapWrite, & s.overlapWrite, sizeof(OVERLAPPED));
setOpenMode(s.openMode());
lastErr=s.lastErr;
port = s.port;
Settings.FlowControl=s.Settings.FlowControl;
Settings.Parity=s.Settings.Parity;
Settings.DataBits=s.Settings.DataBits;
Settings.StopBits=s.Settings.StopBits;
Settings.BaudRate=s.Settings.BaudRate;
Win_Handle=s.Win_Handle;
memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG));
memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS));
if (s.overlapThread->isRunning())
overlapThread->start();
}
/*!
\fn Win_QextSerialPort::Win_QextSerialPort(const QString & name)
Constructs a serial port attached to the port specified by devName.
devName is the name of the device, which is windowsystem-specific,
e.g."COM2" or "/dev/ttyS0".
*/
Win_QextSerialPort::Win_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode):
QextSerialBase(name)
{
Win_Handle=INVALID_HANDLE_VALUE;
setQueryMode(mode);
init();
}
/*!
\fn Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings)
Constructs a port with default name and specified settings.
*/
Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode) {
Win_Handle=INVALID_HANDLE_VALUE;
setBaudRate(settings.BaudRate);
setDataBits(settings.DataBits);
setStopBits(settings.StopBits);
setParity(settings.Parity);
setFlowControl(settings.FlowControl);
setTimeout(settings.Timeout_Millisec);
setQueryMode(mode);
init();
}
/*!
\fn Win_QextSerialPort::Win_QextSerialPort(const QString & name, const PortSettings& settings)
Constructs a port with specified name and settings.
*/
Win_QextSerialPort::Win_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode) {
Win_Handle=INVALID_HANDLE_VALUE;
setPortName(name);
setBaudRate(settings.BaudRate);
setDataBits(settings.DataBits);
setStopBits(settings.StopBits);
setParity(settings.Parity);
setFlowControl(settings.FlowControl);
setTimeout(settings.Timeout_Millisec);
setQueryMode(mode);
init();
}
void Win_QextSerialPort::init()
{
_bytesToWrite = 0;
overlap.Internal = 0;
overlap.InternalHigh = 0;
overlap.Offset = 0;
overlap.OffsetHigh = 0;
overlap.hEvent = CreateEvent(NULL, true, false, NULL);
overlapThread = new Win_QextSerialThread(this);
bytesToWriteLock = new QReadWriteLock;
}
/*!
\fn Win_QextSerialPort::~Win_QextSerialPort()
Standard destructor.
*/
Win_QextSerialPort::~Win_QextSerialPort() {
if (isOpen()) {
close();
}
CloseHandle(overlap.hEvent);
delete overlapThread;
delete bytesToWriteLock;
}
/*!
\fn Win_QextSerialPort& Win_QextSerialPort::operator=(const Win_QextSerialPort& s)
overrides the = operator
*/
Win_QextSerialPort& Win_QextSerialPort::operator=(const Win_QextSerialPort& s) {
setOpenMode(s.openMode());
_queryMode = s._queryMode;
_bytesToWrite = s._bytesToWrite;
bytesToWriteLock = new QReadWriteLock;
overlapThread = new Win_QextSerialThread(this);
memcpy(& overlap, & s.overlap, sizeof(OVERLAPPED));
memcpy(& overlapWrite, & s.overlapWrite, sizeof(OVERLAPPED));
lastErr=s.lastErr;
port = s.port;
Settings.FlowControl=s.Settings.FlowControl;
Settings.Parity=s.Settings.Parity;
Settings.DataBits=s.Settings.DataBits;
Settings.StopBits=s.Settings.StopBits;
Settings.BaudRate=s.Settings.BaudRate;
Win_Handle=s.Win_Handle;
memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG));
memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS));
if (s.overlapThread->isRunning())
overlapThread->start();
return *this;
}
/*!
\fn bool Win_QextSerialPort::open(OpenMode mode)
Opens a serial port. Note that this function does not specify which device to open. If you need
to open a device by name, see Win_QextSerialPort::open(const char*). This function has no effect
if the port associated with the class is already open. The port is also configured to the current
settings, as stored in the Settings structure.
*/
bool Win_QextSerialPort::open(OpenMode mode) {
unsigned long confSize = sizeof(COMMCONFIG);
Win_CommConfig.dwSize = confSize;
DWORD dwFlagsAndAttributes = 0;
if (queryMode() == QextSerialBase::EventDriven)
dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED;
LOCK_MUTEX();
if (mode == QIODevice::NotOpen)
return isOpen();
if (!isOpen()) {
/*open the port*/
Win_Handle=CreateFileA(port.toAscii(), GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
if (Win_Handle!=INVALID_HANDLE_VALUE) {
/*configure port settings*/
GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
GetCommState(Win_Handle, &(Win_CommConfig.dcb));
/*set up parameters*/
Win_CommConfig.dcb.fBinary=TRUE;
Win_CommConfig.dcb.fInX=FALSE;
Win_CommConfig.dcb.fOutX=FALSE;
Win_CommConfig.dcb.fAbortOnError=FALSE;
Win_CommConfig.dcb.fNull=FALSE;
setBaudRate(Settings.BaudRate);
setDataBits(Settings.DataBits);
setStopBits(Settings.StopBits);
setParity(Settings.Parity);
setFlowControl(Settings.FlowControl);
setTimeout(Settings.Timeout_Millisec);
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
//init event driven approach
if (queryMode() == QextSerialBase::EventDriven) {
Win_CommTimeouts.ReadIntervalTimeout = MAXDWORD;
Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
Win_CommTimeouts.WriteTotalTimeoutMultiplier = 0;
Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
没有合适的资源?快使用搜索试试~ 我知道了~
celiangyiGUI.rar_QT_QT 串口_qt串口_qt波形_串口qt波形
共51个文件
o:15个
cpp:15个
h:11个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 181 浏览量
2022-07-15
09:38:56
上传
评论
收藏 3.75MB RAR 举报
温馨提示
通过串口控制下位机的一个QT界面,有绘制波形,读取电压电流等参量的功能。
资源推荐
资源详情
资源评论
收起资源包目录
celiangyiGUI.rar (51个子文件)
qextserialport.h 867B
GraphicsView.cpp 238B
mydlg.h 365B
Makefile.Debug 10KB
object_script.cego.Debug 386B
cego.pro 603B
widget.h 1KB
ui_mydlg.h 2KB
widget.ui 7KB
win_qextserialport.cpp 34KB
win_qextserialport.h 4KB
GraphicsView.h 728B
mydlg.ui 1KB
head.h 162B
ThreadTest.h 2KB
qextserialbase.h 7KB
Makefile.Release 10KB
ui_widget.h 8KB
mydlg.cpp 423B
main.cpp 598B
qextserialport.cpp 3KB
debug
moc_widget.cpp 3KB
moc_SahuWaveScene.o 1.24MB
moc_ThreadTest.o 1.28MB
moc_win_qextserialport.o 1007KB
mydlg.o 701KB
moc_qextserialport.cpp 2KB
moc_mydlg.cpp 2KB
qextserialport.o 1000KB
cego.exe 7.8MB
moc_qextserialbase.cpp 2KB
moc_ThreadTest.cpp 2KB
moc_SahuWaveScene.cpp 2KB
moc_mydlg.o 459KB
moc_widget.o 1.3MB
moc_qextserialport.o 1005KB
moc_win_qextserialport.cpp 2KB
GraphicsView.o 1.96MB
moc_qextserialbase.o 290KB
widget.o 1.6MB
main.o 1.3MB
win_qextserialport.o 1.02MB
SahuWaveScene.o 1.33MB
qextserialbase.o 291KB
Makefile 5KB
SahuWaveScene.h 2KB
SahuWaveScene.cpp 8KB
qextserialbase.cpp 6KB
cego.pro.user 13KB
widget.cpp 10KB
object_script.cego.Release 416B
release
共 51 条
- 1
资源评论
- l9r2o0t7b4z2023-05-11这个资源值得下载,资源内容详细全面,与描述一致,受益匪浅。
weixin_42651887
- 粉丝: 97
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功