Null character transmission in QTcpSocket
hi
I am transmitting a sequence of bytes from my Qt application onto a microcontroller. The bytes contain NULL(0x00) bytes.
The transmission of the packet is terminated as soon as the NULL byte is encountered and the rest of the packet is discarded.
I am using a QTcpSocket class.
....
tcpSocket->write(*barr);
while(tcpSocket->bytesToWrite() > 0)
{
tcpSocket->waitForBytesWritten();
}
....
Is there any way that the required number of bytes are transmitted regardless of the NULL byte? I am new to Qt so any help would be useful.
Thanks and Regards
Manish.S
Re: Null character transmission in QTcpSocket
You should use this form of QIODevice::write functioin:
Quote:
qint64 QIODevice::write ( const char * data, qint64 maxSize )
Re: Null character transmission in QTcpSocket
hi
thanks a lot for the reply
I tried the following code but nothing seemed to work out.
...
tcpSocket->write(*barr, 10);
...
Though the following code gives the debug output as 10 bytes but the data is truncated as soon as the NULL bytes are encountered.
int bytes= tcpSocket->write(*barr, 10);
qDebug()<<"Bytes"<< bytes;
Thanks and Regards
Manish.S
Re: Null character transmission in QTcpSocket
1. what is a barr ?
2. try
Quote:
qint64 QIODevice::writeData ( const char * data, qint64 maxSize )
instead of write function
3. try to write byte by byte like this
Code:
for ( int i = 0; i < 10; i++ )
{
tcpSocket->write( &arr[ i ], 1 );
}
4. How do you see, that not all of written bytes are received ?
Re: Null character transmission in QTcpSocket
Hi
Thanks a lot.
The problem was at my end. I apologize to start this thread before checking the receiving system also.
Thanks and Regards
Manish.S