I'm communicating with a CameraLink camera using the CameraLink internal virtual COM-Port. 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:
void ts4control_calibrationdialog::readFPN()
{
resp+=serial->readAll();
}
But the readFPN-function is never called. 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.
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:
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.