Answer the question
In order to leave comments, you need to log in
How to use QtSerialPort?
QByteArray message;
message.resize(7);
message[0] = (char)':';
message[1] = 0x1A;
message[2] = 0x03;
message[3] = 0x00;
message[4] = 0x00;
message[5] = 0x00;
message[6] = 0x04;
serialport->write(message);
serialport->setPortName("COM6");
if(!serialport->open(QIODevice::ReadWrite) )
{
QMessageBox *msg = new QMessageBox();
msg->setText("fail");
msg->show();
}
serialport->setBaudRate(QSerialPort::Baud9600);
serialport->setDataBits(QSerialPort::Data8);
serialport->setStopBits(QSerialPort::OneStop);
serialport->setFlowControl(QSerialPort::NoFlowControl);
serialport->setParity(QSerialPort::NoParity);
}
Answer the question
In order to leave comments, you need to log in
As Armenian Radio
noted - you need to check the return code first.
Second, perhaps calling bool QSerialPort::waitForBytesWritten(int msecs) might help.
The semantics of all such calls is the same - you specify how much you want to transfer, write gives you how much you actually transferred, or -1. Check the return code (and read the documentation ), of course you didn't bother
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question