QSerialPort hangs on Windows works fine on ARM/LINUX
-
Hi Qt Experts,
I'm working on an opensource project writing a library for XIMU (IMU) devices. This library can be found on https://github.com/Auke-Dirk/x-IMU-CPP-API.
I've been asked by some users to provide an IO inteface (SerialPort) making it more easy for programmers to interface with the XIMU. Since i wanted platform independence thought Qt would be a good option.
On my ARM/Linux laptop all is fine and i recieve and parse the incomming data as expected. However on Window 7 i encounter problems with reading the SerialPort. I'm by far not an expert on Qt so hints/advice would be greatly appreciated.
The problem: The SerialPort sometimes initially recieves data, after which it never enters the if (sp.waitForReadyRead(_timeout_msec)) guard. If i turn the device offand on i get one readyRead and that is it.
Providing the code here would cause a mess and therefor i've added the necessary urls. The problems occurs in both gui and non-gui applications, i've added both a console and gui code.
Qt 5.2 and 5.4 where used.
The SerialPort: https://github.com/Auke-Dirk/x-IMU-CPP-API/blob/master/src/ximuapi/io/serial_port.cpp
Widget: http://github.com/Auke-Dirk/x-IMU-CPP-API/blob/master/src/ximugui/widgets/serialview.cpp
Commandline: http://github.com/Auke-Dirk/x-IMU-CPP-API/blob/master/apps/ximu_console.cpp
regards Auke-Dirk
-
Hi and welcome to devnet,
Not answer at first but why not make use of Qt's asynchronous capabilities for your serial port stuff ?
-
@SGaist said:
Not answer at first but why not make use of Qt's asynchronous capabilities for your serial port stuff ?
Hi SGaist,
thanx for the reply!
I've tried both approaches, yielding the same results.
The reason i chose this approach is, i like the fact that QSerialPort has a small scope.void SerialPort::run(){
_mutex.lock();
QSerialPort sp;
..
}for most of my hardware interfacing i follow that strategy, however since i'm Qt rookie i'm open for all ideas.
regards Auke
-
Then what do you mean by hangs ? If you take your command line application, you didn't wrote any logic to quit the running QCoreApplication.
On a side note, why go back and forth with std::string since you are using QString anyway ?
-
Hi SGaist,
thanx again for taking the time.
Then what do you mean by hangs ?
By hangs i mean that waitForReadyRead is never true, unless as i mentioned when i turn off/on the device after which i do recieve
a few bytes.On a side note, why go back and forth with std::string since you are using QString anyway ?
I don't want to expose Qt to much inside the SerialPort header (public functions) , someone might implement the serialort based boosts async_serial if Qt is not available.
If you take your command line application, you didn't wrote any logic to quit the running QCoreApplication.
Haven't gotten to that part yet, first like to get it running.
I extended the research by sending a dump file through an emulated (com0com) comport, this way the data is correctly recieved. result and setup
Are there any things/ideas i could test?
kind regards Auke-Dirk
-
Are you using a special device for the serial port on Windows ?
-
Hi Qt,
problem was quit easy and a bit annoying, different platform's require different Flow control. My first platform ARM all seemed fine, then on that Mac OS-X all was fine, windows however i needed to set setFlowControl(QSerialPort::HardwareControl);
-
different platform's require different Flow control.
it is not true