Results 1 to 4 of 4

Thread: send hexa data serial port and read it

  1. #1
    Join Date
    May 2018
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default send hexa data serial port and read it

    i have a problem here. i still can't figure out how to be able to communicate between raspberry and microcontroller.
    each time i send data to serial port i don't receive any answer. i notice that data is sent in ascii.
    Here's my code :
    if (serial->isOpen()) {
    qDebug() << "port is open: " ;
    QByteArray buff= {0xA1, 0xFF, 0xFF, 0x00,97};
    serial->write(buff);
    }
    if (serial->bytesAvailable()) { // If there are bytes available
    QByteArray f_data; // data container
    f_data.clear();

    while(serial->bytesAvailable()) { // Reading loop
    f_data.append(serial->readAll());


    serial->flush();
    }
    qDebug()<< "the result" << f_data; // Check the result
    }

    if(!serial->isOpen())
    qDebug() << "carte disconnect"<<serial->errorString();

    any help PLZ !!!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: send hexa data serial port and read it

    Since this has to do with hardware and another system the point of failure can be anywhere.
    You could help by post what are all the things you have checked to be ok such as:
    Did you make sure both devices use the same serial settings for example?
    The code you posted is too minimal and without a context so its hard to see if there are any problems in it as well...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    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: send hexa data serial port and read it

    This code is pointless. You are sending data, you are not waiting for the end of sending and you expect an immediate response. The serial port is a very slow device.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: send hexa data serial port and read it

    Lesioks point is correct.
    You can use the blocking calls waitForReadyRead() and waitForBytesWritten() to wait for the data to be written and or until it is received and ready to be read.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Read data from serial port
    By hoangnguyen in forum Newbie
    Replies: 1
    Last Post: 5th September 2017, 08:30
  2. Replies: 0
    Last Post: 4th February 2016, 11:48
  3. Serial read misses to read data from the serial port
    By mania in forum Qt for Embedded and Mobile
    Replies: 11
    Last Post: 18th August 2014, 09:49
  4. read data from serial port and display it
    By vanduongbk in forum Newbie
    Replies: 1
    Last Post: 30th June 2013, 04:46
  5. read data from serial port
    By amitpatel22 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 20th July 2011, 18:11

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.