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);
//send a command (txbuf) to the gps
port->setTimeout(200);
port->write(txbuf, txlen);
// read the answer packet
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;
}
}
/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;
}
}
To copy to clipboard, switch view to plain text mode
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!
Bookmarks