Hi all,
I am trying to read back the udp data , sent from my stepper motor. Reply varies from 3-12 bytes.
I am currently doing this to read my udp data:
qint64 size = udpSocket->pendingDatagramSize();
quint16 senderPort;
char* reply = new char[size]
qint64 res = udpSocket->readDatagram( reply, size, &sender, &senderPort );
char buf[12];
for ( int i = 2; i <= 11; ++i )
buf[ i -2 ] = reply[ i ];
ui->Position->setText(buf);
qint64 size = udpSocket->pendingDatagramSize();
QHostAddress sender;
quint16 senderPort;
char* reply = new char[size]
qint64 res = udpSocket->readDatagram( reply, size, &sender, &senderPort );
char buf[12];
for ( int i = 2; i <= 11; ++i )
buf[ i -2 ] = reply[ i ];
ui->Position->setText(buf);
To copy to clipboard, switch view to plain text mode
The problem I am facing is that sometime there are only 4 bytes sometime there are 11 bytes and when there are less bytes suppose 4-5 my text box will be filled with weird characters of unreadable format.
how can I change my current code to just read proper bytes received.
Bookmarks