PDA

View Full Version : Qserial Read Problem



vishme7
24th October 2013, 07:52
hiii,

I tried some Stuff on QSerialPort.
Having some protocol which is Tx and Rx the bytes.
i Monitored the serial port through Sniffer data will be sent through UI successfully but receiving acknowledge cant received in UI but the controller sent Ack on Port ,sniffer will detect it, but my UI application cant received the data.

unsigned char Buffer[64];

//TX
SerialPort->write((const char *)Buffer,1);

//RX
SerialPort->read(char *)Buffer,1);

i put some delay between TX n RX but still QT Ui doesn't get response.

kuzulis
24th October 2013, 09:24
Use the signal/slot's approach. E.g. the readyRead signal to know when data is available to read.

In your current case all wrong.

UPD: At least you should use waitForX() methods (in case you do not use the signal/slot), e.g.:



//TX
SerialPort->write((const char *)Buffer,1);
SerialPort->waitForBytesWritten(5000);

//RX
SerialPort->waitForReadyRead(5000);
SerialPort->read(char *)Buffer,1);


But I don't recommend use the waitForX() methods because they still have some bugs.

pkj
25th October 2013, 06:09
But I don't recommend use the waitForX() methods because they still have some bugs.

I have used the library for asynchronous communication in many production environments and never received ONE complaint. But as kuzulis says, there is some bug in synchronous communication. Try async methods, it is anyway a better design. It will work like a charm.

And Thank you kuzulis for this lovely library. Hope the sync methods can be resolved soon.