Results 1 to 14 of 14

Thread: Receive a raw data via serial port (qExtSerialPort)

  1. #1
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Receive a raw data via serial port (qExtSerialPort)

    Hello everyone,

    I'm now here, thank you for your forum,

    I have a problem in receiving data via serial port (Raspberry pi)..
    I use the QextSerialPort,
    I'm sure that data sent by the other device is correct, i have in the oscilloscope the uart trames
    but when i send this data, i receive a strange data
    this is my code :


    in this fuction , i call the slot function :

    if(msgBoxConfirmerReception->exec() == QMessageBox::Yes){

    portReception->setBaudRate(BAUD115200);
    portReception->setFlowControl(FLOW_OFF);
    portReception->setParity(PAR_NONE);
    portReception->setDataBits(DATA_8);
    portReception->setStopBits(STOP_1);

    if(portReception->open(QIODevice::ReadOnly)==true){

    connect(portReception, SIGNAL(readyRead()), this, SLOT(receiveTrames()));
    qDebug()<<"listenning for data on";

    }

    else{
    QMessageBox::critical(this,"ERREUR","le port UART n'est pas connecté");
    qDebug()<<"device failed to open:"<<portReception->errorString();
    portReception->close();
    exit(1);

    }




    }

    ----------------------------------------------------

    void AffichageTrames::receiveTrames()

    {

    StopAff->setEnabled(true);
    QByteArray bytes;
    int a = portReception->bytesAvailable();
    bytes.resize(a);
    qDebug() << "nb data availble = " <<a;
    portReception->read(bytes.data(), bytes.size());
    qDebug() << QString(bytes.toHex())<<"\n";

    }

    for exemple if i send a value = 1
    I receive : fe (Hexadecimal)

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    Why do you use the QextSerialPort, what reason?

    It is better to use QtSerialPort instead. The QtSerialPort already are present in Qt5 (also this module can be compiled and for Qt4, see wiki).

  3. The following user says thank you to kuzulis for this useful post:

    AUDI_ENG (2nd July 2014)

  4. #3
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    thank you for your reply,

    i don't have any reason, i don't know other library to send data by serial port
    i know qtExtSerialPort and QtSerialPort

    I use Qt 4.7 so QtSerialPort can be used in Qt4 ? because when i give a search in google, i see that its only used in Qt5
    Last edited by AUDI_ENG; 2nd July 2014 at 15:29.

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    1. Are you sure that parameters (speed, parity etc) are OK ?
    2. How method AffichageTrames::receiveTrames() is activated ?

  6. The following user says thank you to Lesiok for this useful post:

    AUDI_ENG (3rd July 2014)

  7. #5
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    @AUDI_ENG,

    I use Qt 4.7 so QtSerialPort can be used in Qt4 ? because when i give a search in google, i see that its only used in Qt5
    you can see similar my reply on another forum.

  8. The following user says thank you to kuzulis for this useful post:

    AUDI_ENG (3rd July 2014)

  9. #6
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    Quote Originally Posted by kuzulis View Post
    @AUDI_ENG,



    you can see similar my reply on another forum.

    thank you,
    I will try this library today

    Quote Originally Posted by Lesiok View Post
    1. Are you sure that parameters (speed, parity etc) are OK ?
    2. How method AffichageTrames::receiveTrames() is activated ?
    I active this fonction with the readyRead() signal :

    connect(portReception, SIGNAL(readyRead()), this, SLOT(receiveTrames()));

    In the other device, i have the same baude : 115200 and i didn't integrate the parity mode in the uart trames

  10. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    Quote Originally Posted by AUDI_ENG View Post
    I active this fonction with the readyRead() signal :

    connect(portReception, SIGNAL(readyRead()), this, SLOT(receiveTrames()));

    In the other device, i have the same baude : 115200 and i didn't integrate the parity mode in the uart trames
    1. All parameters (speed, parity, word length, stop bits) must be the same on both ends.
    2. How value 1 is sent ? As one byte, as ASCII character or integer ?

  11. The following user says thank you to Lesiok for this useful post:

    AUDI_ENG (3rd July 2014)

  12. #8
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    Quote Originally Posted by Lesiok View Post
    1. All parameters (speed, parity, word length, stop bits) must be the same on both ends.
    2. How value 1 is sent ? As one byte, as ASCII character or integer ?
    I have a pic microcontroller, so i use the TX/RX (UART) port.. i send a "bytes" data ..
    for example in the output (oscilloscope) i have :
    start bit | data byte | stop bit
    ___0____10000000____1___

    this correspond to "1" value

    on both devices, i disable the parity mode, i have 115200, i have stop bits, and the word length is a "byte"
    Last edited by AUDI_ENG; 3rd July 2014 at 12:11.

  13. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    What happen if You change code to this :
    Qt Code:
    1. void AffichageTrames::receiveTrames()
    2. {
    3. StopAff->setEnabled(true);
    4. QByteArray bytes;
    5. bytes = portReception->readAll();
    6. qDebug() << "nb data read = " << bytes.size() << " bytes = " << QString(bytes.toHex())<<"\n";
    7. }
    To copy to clipboard, switch view to plain text mode 
    P.S.
    I hope You have latest version of QExtSerialPort library

  14. The following user says thank you to Lesiok for this useful post:

    AUDI_ENG (3rd July 2014)

  15. #10
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    Hi,

    I also recommend you to use a serial port sniffer to ensure that the data you are sending is the data you are receiving.
    Òscar Llarch i Galán

  16. The following user says thank you to ^NyAw^ for this useful post:

    AUDI_ENG (3rd July 2014)

  17. #11
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Receive a raw data via serial port (qExtSerialPort)

    Quote Originally Posted by Lesiok View Post
    What happen if You change code to this :
    Qt Code:
    1. void AffichageTrames::receiveTrames()
    2. {
    3. StopAff->setEnabled(true);
    4. QByteArray bytes;
    5. bytes = portReception->readAll();
    6. qDebug() << "nb data read = " << bytes.size() << " bytes = " << QString(bytes.toHex())<<"\n";
    7. }
    To copy to clipboard, switch view to plain text mode 
    P.S.
    I hope You have latest version of QExtSerialPort library
    Now, I have the qtSerialPort library,

    I test this code ..

    I receive :
    nb data read = 1 bytes = "FE"
    but in the oscilloscope i have one byte :
    start bit | data byte | stop bit
    ___0___10000000____1___

    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    I also recommend you to use a serial port sniffer to ensure that the data you are sending is the data you are receiving.
    thank u, i will try this now

  18. #12
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [RESOLVED] Re: Receive a raw data via serial port (qExtSerialPort)

    HI
    I"m solving the problem..
    its consist on value of baud rate in the other device (microcontroller PIC)
    im using a cristal with 10 Mhz and the PLL in the pic is enabled so (Frequency of system = 4*Fosc = 40 Mhz) --> so the baud rate is not the same if we considerate that frequency are only 10 Mhz

    Thank you so much !

  19. #13
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [RESOLVED] Re: Receive a raw data via serial port (qExtSerialPort)

    Quote Originally Posted by AUDI_ENG View Post
    HI
    I"m solving the problem..
    its consist on value of baud rate in the other device (microcontroller PIC)
    im using a cristal with 10 Mhz and the PLL in the pic is enabled so (Frequency of system = 4*Fosc = 40 Mhz) --> so the baud rate is not the same if we considerate that frequency are only 10 Mhz

    Thank you so much !
    I told you so

  20. The following user says thank you to Lesiok for this useful post:

    AUDI_ENG (4th July 2014)

  21. #14
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [RESOLVED] Re: Receive a raw data via serial port (qExtSerialPort)

    Quote Originally Posted by Lesiok View Post
    I told you so
    yes Thank you so much

Similar Threads

  1. Replies: 4
    Last Post: 14th August 2013, 19:15
  2. Replies: 7
    Last Post: 19th April 2013, 12:46
  3. Serial port timeout - Qextserialport
    By h-n-s in forum Newbie
    Replies: 1
    Last Post: 9th April 2013, 07:42
  4. Replies: 1
    Last Post: 13th March 2013, 09:44
  5. Replies: 1
    Last Post: 1st July 2009, 01:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.