PDA

View Full Version : Null character transmission in QTcpSocket



Manish.S
18th June 2010, 06:25
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

borisbn
18th June 2010, 07:18
You should use this form of QIODevice::write functioin:

qint64 QIODevice::write ( const char * data, qint64 maxSize )

Manish.S
18th June 2010, 07:53
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

borisbn
18th June 2010, 08:29
1. what is a barr ?
2. try

qint64 QIODevice::writeData ( const char * data, qint64 maxSize )
instead of write function
3. try to write byte by byte like this


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 ?

Manish.S
18th June 2010, 08:31
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