I have a question, writing a Qt GUI and I have the RTS line connected to a RS-485 driver transmit/receive control signal. I am sending out x number of bytes, I use the setRts(1) to make it go high (start of transmisson) and setRts(0) when I finish (as direction control). Does the waitForBytesWritten method work? I want it to wait until all the bytes have been transmitted out of the serial port, so I can setRts low. I see that sometimes the RTS signal is going low before all the bytes have been transferred. Any one have any ideas?
Do I have to set it up in unbuffered mode?
Here is a snippet of my code. Thanks in advance.
void TraceDialog::procSendButtonClick()
{
data.append(ui->lineEdit->text());
m_port->setRts(1);
if (data.size() > 0) {
m_port->write(data);
printTrace(data, false);
ui
->lbError
->setText
(QString::number(m_port
->error
()));
}
// Add in sleep timer
while(m_port->waitForBytesWritten(15)); // Time out for 15 ms
m_port->setRts(0);
}
void TraceDialog::procSendButtonClick()
{
QByteArray data;
data.append(ui->lineEdit->text());
m_port->setRts(1);
if (data.size() > 0) {
m_port->write(data);
printTrace(data, false);
ui->lbError->setText(QString::number(m_port->error()));
}
// Add in sleep timer
while(m_port->waitForBytesWritten(15)); // Time out for 15 ms
m_port->setRts(0);
}
To copy to clipboard, switch view to plain text mode
Bookmarks