Qserialport Arduino garbage data



  • I am attempting to read through the serialport from an arduino. I just receive weird characters.
    Here is a screenshot
    http://tinypic.com/r/2vhulae/9

    #include <QCoreApplication>
    #include <QDebug>
    #include <QSerialPort>
    #include <QSerialPortInfo>
    #include <iostream>
    #include <QTimer>
    #include "event.h"
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QSerialPort *arduino = new QSerialPort();
        //QSerialPortInfo info = new QSerialPortInfo();
        //QSerialPort *arduino;
        static const quint16 arduino_uno_vendor_id = 9025;
        static const quint16 arduino_uno_product_id = 67;
        QString arduino_port_name;
        bool arduino_is_available;
    
    
       qDebug() <<QSerialPortInfo::availablePorts().length();
       //qDebug() <<info.portName();
       arduino_is_available = false;
       arduino_port_name = "";
       arduino = new QSerialPort;
    
      foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
           //if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
               //if(serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id){
                //   if(serialPortInfo.productIdentifier() == arduino_uno_product_id){
                       arduino_port_name = serialPortInfo.portName();
                       arduino_is_available = true;
                   }
               //}
    //       }
    //   }
    
        qDebug()<<arduino_is_available;
       arduino->setPortName(arduino_port_name);
       arduino->open(QSerialPort::ReadOnly);
       arduino->setBaudRate(QSerialPort::Baud115200);
    
       char buf[1024];
           qint64 lineLength = arduino->readLine(buf, sizeof(buf));
           if (lineLength != -1) {
               // the line is available in buf
           for(int i = 0; i < 1024; i++){
               qDebug()<<buf[i];
            }
        }
           QString x = QString(arduino->readAll());
           qDebug()<<x;
       //event *j = new event();
    
       //while(true){
      // j->pulse(arduino);
      // QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
      // }
        return a.exec();
    }
    
    
    

    Has anyone seen this before?



  • Did you try to read data using putty or other serial port terminal?
    I think its also good idea to set DataBits, FlowControl and StopBits


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.