Ssending an int variable through serial using qextserialport
I am trying to send an int variable X though the serial port using qextserialport.
After setting up and port initialization I use
int x = 1;
port->open(QIDevice::ReadWrite);
port->write(x);
but I am not receiving anything on the other end. What am I missing? Program compiles and run fine. The baud rate settings all match.
Re: Ssending an int variable through serial using qextserialport
Which of the QIODevice::write() variants do you think accepts an int as its first argument? Your compiler will almost certainly be warning you about an " invalid conversion from ‘int’ to ‘const char*’ ", and mine flat out refused to compile this.
To send an int you need to send the four bytes in an agreed order: and you need to get them into a form that you can write().
Assuming you send write() valid parameters... the default operating mode of QExtSerialPort is event driven, so bytes are not sent until the program reaches the Qt event loop.