简体   繁体   English

qt串行通讯,readyRead不发出

[英]qt serial communication, readyRead not emitted

I'm communicating with a CameraLink camera using the CameraLink internal virtual COM-Port. 我正在使用CameraLink内部虚拟COM端口与CameraLink相机通信。 I wrote the following code: 我写了以下代码:

serial=new QSerialPort(this);
connect(serial,SIGNAL(readyRead()),SLOT(readFPN()));
serial->setPortName(comPort);
serial->setBaudRate(QSerialPort::Baud9600);
serial->setStopBits(QSerialPort::OneStop);
serial->setParity(QSerialPort::NoParity);
serial->open(QIODevice::ReadWrite);

QString comm=QString("r gwbr\r"); //read red channel gain
serial->write(comm.toUtf8(),comm.size());

QString comm=QString("r gwbb\r"); //read blue channel gain
serial->write(comm.toUtf8(),comm.size());

... more serial commands

The readFPN function does nothing by now except appending the data read to a QByteArray: 现在,除了将读取的数据附加到QByteArray之外,readFPN函数什么都不做:

void ts4control_calibrationdialog::readFPN()
{
    resp+=serial->readAll();
}

But the readFPN-function is never called. 但是从不调用readFPN函数。 I set a breakpoint and the program steps over the write commands without calling the callback. 我设置了一个断点,程序跳过了写命令,而没有调用回调。 The general communication with the device works in a COM-Port-terminal using the above settings. 使用以上设置,与设备的常规通信可在COM端口端口中进行。

What do I have to change to have the signal emitted? 要发出信号,我必须更改什么? Or how can I find out why it isn't working? 或者我怎么才能找出为什么它不起作用? Any debugging-ideas? 有任何调试思路吗?

完成编写串行命令后,请使用QSerialPort::flush()写入基础串行端口。

I had the same problem, read this, read a couple of other useless (for my case ) things, and then it finally ocurred to me, to look at one of the examples Qt provides abour QSerialPort (called terminal), in wich i saw the "connect" line was written differently Instead of: 我遇到了同样的问题,读了这本书,读了另外两本无用的东西(对我而言),然后终于出现在我身上,看看Qt提供的QSerialPort实例(称为终端),直到我看到为止“连接”行的写法不同,而不是:

connect(serial,SIGNAL(readyRead()),SLOT(readFPN()));

It would be: 这将是:

connect( serial, &QSerialPort::readyRead, this, &ts4control_calibrationdialog::readFPN );

I'm pretty much a noob, but i hope this works for you! 我几乎是菜鸟,但我希望这对您有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM