vendredi 5 juin 2015

Unable to send data using QSerialPort

I am trying to write a QT application that will be able to communicate with my embedded system using serial port. For now I am testing the config with Null Modem emulator as I dont have the embedded system ready yet. The emulator works fine as I have tested it in other software like Terraterm, RealTerm or Putty. My problem is that my example code doesnt work- It doesnt send the string to another com port. This is my code:

void CSettingsDialog::on_pbSerialCheck_clicked()
{
    QSerialPort serial;
    serial.setPortName(ui->cbSerialPort->currentText());

    if (!serial.open(QIODevice::ReadWrite))
    {
        QMessageBox::warning(this, tr("Serial port"),
                             tr("Serial port %1 is busy!")
                            .arg(ui->cbSerialPort->currentText()));
    }
    else
    {
        serial.setBaudRate(QSerialPort::Baud115200);
        serial.setDataBits(QSerialPort::Data8);
        serial.setParity(QSerialPort::NoParity);
        serial.setStopBits(QSerialPort::OneStop);
        serial.setFlowControl(QSerialPort::NoFlowControl);
        serial.write("TEST\n");
        serial.close();
    }
}

I am certain that I have everything set correctly looking at the QT examples. I would aprichiate all help!

Aucun commentaire:

Enregistrer un commentaire