PDA

View Full Version : Qt Serial seems to be deaf on Ubuntu 12.04



Royce
2nd December 2012, 23:50
I have a continuous-duty program that polls an embedded RS-485 serial device periodically. It had been running fine on Ubuntu 10.04 with Qt 2010.05.1 and QExtSerial 1.1. That installation ran through an FTDI based USB to serial convertor. I found the FTDI device to be a little annoying in that it would spontaneously change the tty device it was listed under. I was able to work around that behavior and the program ran fine for a couple of years.

I would now like to upgrade to Ubuntu 12.04. Initially I attempted to use the Ubuntu qt-sdk package and QExtSerial 1.2beta 2 from Google Code. I found that the FTDI driver issues seemed a lot worse and my program would occasionally freeze (about once per a week). So I gave up on the USB based serial converter and created a custom RS-232 to RS-485 convertor using the RTS line to toggle the RS-485 transmit enable.

What I've found with that setup is that while transmission works just fine, the program never gets any bytes in return even though the embedded devices (and a logic analyzer) indicate bytes are in fact being sent to the RS-232 port in reply to the Qt program's transmissions. Further, they return to the RS-232 port within about 70ms. (My timeout is set to 300ms). Nonetheless, readyRead() never fires. When the time out fires, I check bytesAvailable and it always says zero.

Maddeningly, on the command line, if I run 'cat /dev/ttyS0' I can clearly see the reply bytes from the embedded devices. So the reply bytes are definitely inside the operating system, they just don't make it to my program.

I thought that perhaps QExtSerial might have some issue, so I dropped back a version. Same symptom. I then ported the code to use the newer QSerialDevice library. Again same symptom. I thought that perhaps the ubuntu spin of qt-sdk was bugged so I removed it and installed 2010.05.01 from the old binary installer. Once more, same symptom.

On Windows XP this code works fine whether via the RS-232 port or via the USB port.

My original code from 2010. (https://github.com/roycepipkins/MakerAccessControl/blob/master/server/AccessServer/busmngr.cpp)

Has anyone seen anything like this? Why can cat see the reply bytes but Qt is convinced there are no such bytes?

Thanks for any tips or ideas on things I can try. I'm about to surrender and just require this program be hosted on windows. Its just that the whole point of writing it in Qt was to get cross platform functionality.

kuzulis
3rd December 2012, 06:59
I then ported the code to use the newer QSerialDevice library. Again same symptom.
1. Instead of QSerialDevice need use QtSerialPort (http://qt-project.org/wiki/QtSerialPort).
2. Provide your source code.
3. Use "normal" RS-485 convertor with autodetecting I/O direction.

Otherwise, all that you wrote is totally uninformative.

Royce
3rd December 2012, 13:17
1. Instead of QSerialDevice need use QtSerialPort.

A third serial library? Ok. I'll give it a go. Any notion why QExtSerial works so well under Ubuntu 10.04 but so poorly under Ubuntu 12.04?


2. Provide your source code.

I did.


3. Use "normal" RS-485 convertor with autodetecting I/O direction.

I thought about that, but the thing is that I have not one but two mechanisms confirming to me that the reply bytes are in fact being properly received. First up is the logic analyzer which clearly shows the RS-232 data flowing to the machine. The logic analyzer has no problems decoding the data it sees on the PC's RX line. The second confirmation comes the command line utility cat. #cat /dev/ttyS0 prints out the received data from the serial port properly. The data is ASCII and its clearly visible. It's not corrupt and even if it were, it wouldn't result in a receive timeout.



Anyway, thanks for your replies.

kuzulis
3rd December 2012, 17:42
A third serial library?
Not. This is the first and only "normal" library.


Any notion why QExtSerial works so well under Ubuntu 10.04 but so poorly under Ubuntu 12.04?
I have no idea.

Royce
3rd December 2012, 18:33
Not. This is the first and only "normal" library.

That doesn't seem to be the case. From the QtSerialPort page you linked me to:


QtSerialPort originated from the third-party library QSerialDevice [gitorious.org] (branch 2.0), which was recently moved to a repository on https://codereview.qt-project.org/

From what I understood of QSerialDevice's web page, the QSerialDevice project itself started out as a re-factoring of QExtSerial that wound up becoming a re-write. I think QSerialDevice is simply the first serial class to be adopted into the official code. The class didn't exist in 2010 when I wrote the code. Only QExtSerial existed.

Anyway, I'm now now more guarded about whether it will work, but since it does appear to be a newer version of the QSerialDevice library I tried previously, perhaps I'll find its been updated to reflect whatever may have changed in Ubuntu. Hopefully I'll be able to try this latest version out tomorrow. I'll report back.

Thanks!