Results 1 to 2 of 2

Thread: read from USB serial port of raspberry pi with serialGetchar()

  1. #1
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Question read from USB serial port of raspberry pi with serialGetchar()

    I use wiringSerial.h library to read from USB port of raspi in thread
    Qt Code:
    1. void MyThread::run()
    2. {
    3.  
    4. qDebug("Thread id inside run %d",(int)QThread::currentThreadId());
    5.  
    6. int fd ,value;
    7.  
    8. if ((fd = serialOpen ("/dev/ttyACM0",230400)) < 0)
    9. {
    10. fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
    11. }
    12.  
    13. while (serialDataAvail(fd)>-2)
    14. {
    15.  
    16. value=serialGetchar (fd) ;
    17.  
    18. msleep(1);
    19. emit signalValueUpdated(value);
    20. }
    21. serialClose(fd);
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

    the data that received is a number between -1 to 255
    when use value in emit signal Value Updated(value); or print it
    the value is not the same value that send to raspberry pi, what should I do?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,464
    Thanked 272 Times in 267 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: read from USB serial port of raspberry pi with serialGetchar()

    Show serialDataAvail() and serialGetChar().

Similar Threads

  1. Replies: 1
    Last Post: 2nd June 2018, 17:46
  2. Read data from serial port
    By hoangnguyen in forum Newbie
    Replies: 1
    Last Post: 5th September 2017, 08:30
  3. read and write in serial port
    By neda in forum Qt Programming
    Replies: 13
    Last Post: 10th February 2016, 13:07
  4. 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
  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.