PDA

View Full Version : QExtSerialPort binary serial port reading ignoring or disregarding 0x00 null char.



guillaus
3rd July 2012, 15:22
I am trying to read binary data from a serial port with qextserialport (getChar(), readAll(), readLine()) but the problem is that every 0x00 character are neglected by the read function. For example, instead of reading: "0x02 0x03 0x1a 0x00 0x00 0x1a 0x1b", i get "0x02 0x03 0x1a 0x1a 0x1b". I tried every reading function (getChar(), readAll(), readLine()). And i get the same problem. I tried to look only at the number of Bytes which are readed and i get every time the expected total - # of 0x00. Which means that my problem do not comes from the conversion of the QByteArray in Hex. I don't know what to do now and i would be very happy if someone could help me!!!

high_flyer
3rd July 2012, 15:59
I don't know what to do
post code.

guillaus
3rd July 2012, 16:42
ok my code look like:


/
/serial port settings
PortSettings ps;
ps.BaudRate = 9600;
ps.DataBits = DataBitsType(DB8);
ps.Parity = ParityType(P_NONE);
ps.StopBits = StopBitsType(SB1);
ps.FlowControl = FlowType(FC_NONE);

//open serial port for writing and reading
QextSerialPort port = new QextSerialPort("COM1", ps, QextSerialPort::Polling);
port->open(QIODevice::ReadWrite);

//send a command (txbuf) to the gps
port->setTimeout(200);
port->write(txbuf, txlen);

// read the answer packet
QByteArray binrx;
binrx.resize(128);
char* rxbuf = binrx.data();
int rxlen = binrx.size();

port->setTimeout(200);
// wait for the first character
forever
{
if (! port->getChar(rxbuf))
else
{
break;
}
}

// read until EOL
port->setTimeout(200);

for (int i = 1; i < rxlen; i++)
{
if (! port->getChar(rxbuf+i))
{
binrx.resize(i);
qDebug() << binrx.toHex();
return;
}
}

With this code i get the received data without every 0x00 character. The function getChar() seems to ignore the incoming 0x00 characters. I get the same result by using port->readAll() or port->read(). I absolutely need the COMPLETE answer of my GPS which contains 0x00 characters. Thanks for the help!