qextserialport strange read

1k Views Asked by At

Im using Window 7 x64 Problem in that that I send with Arduino on PC information, and when reading port, I receive the strange artifact of Arduino send(0000000) PC reads (0000+000) or something similar (00000+00) - (0+000000) and so on.

For an example I will show a screenshot

enter image description here

and

enter image description here

Open port

bool MainWindow::openPort()
{

    QString strPort = LineConnect->currentText();
    port = new QextSerialPort(strPort, QextSerialPort::EventDriven);

    if (port->open(QIODevice::ReadWrite | QIODevice::Unbuffered) == true) {


        port->setBaudRate(BAUD9600);
        port->setDataBits(DATA_8);
        port->setParity(PAR_NONE);
        port->setStopBits(STOP_1);
        port->setFlowControl(FLOW_OFF);
        port->setTimeout(100);
        port->waitForReadyRead(10);
        port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
        connect(port,SIGNAL(readyRead()), this, SLOT(onReadyRead()));
        INFO_conn->append("port "+ port->portName() + " opened..");
        INFO_conn->append("port " + port->portName() + " reading..");

        return true;
    } else {
        INFO_conn->append("port " + port->portName() + " error connection..");
    }
    return false;
}

Read data

void MainWindow::onReadyRead()
{
        /*first option read data*/
        QByteArray msg = port->readAll();
        int size = msg.size();
        QString data = "Data: " + msg + " size: " + QString::number(size);
        INFO_conn->append(data);

        /*second option read data*/
    //    char data[1024];
    //    QTextStream out(stdout);

    //    out << "data received: ";
    //    int bytesRead = port->read(data, 1024);
    //    data[bytesRead] = '\0';
    //    out << data << " (" << bytesRead << " bytes)" << endl;
    //    //QString messRead = "data received: " + data +" "+ bytesRead + " bytes";
    //    INFO_conn->append(data);

}

send data arduino for PC

void setup()
{
   Serial.begin(9600);

   .....
}
void loop()
{
   Serial.print(K38);
   Serial.print(K40);
   Serial.print(K42);
   Serial.print(K44);
   Serial.print(K46);
   Serial.print(K48);
   Serial.print(K50);

   or

   Serial.print("0000000"); // result same

}

I can't understand in what there can be a problem, tried everything. Examples from QexSerialPort library read too most. Need help.Thanks for any help.

1

There are 1 best solutions below

3
On

I would suggest debugging your serial port code using a serial terminal application (Putty, TeraTerm, Hyperterminal). Connect a serial terminal application to the Arduino and see if get the output you expect. Also connect it to your Qt application and see if you can send text to your Qt application and get sane output. You should be able to tell better if the problem is with the code on the Arduino or on the PC.