Find the answer to your Linux question:
Results 1 to 2 of 2
I am trying to write some code that interfaces with an AVR over a serial port. Basically I send a command then read the output which is 6 bytes. I ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    14

    Read x bytes from serial port

    I am trying to write some code that interfaces with an AVR over a serial port. Basically I send a command then read the output which is 6 bytes.

    I need to receive all 6 bytes before the program continues. Is there a way to do this? If I use read() it returns -1 unless I add a delay before reading the port. Is there a way to get it to read the 6 bytes as soon as they arrive?

    In python you simply say how many bytes you want and the max time you are willing to wait which seems a whole lot easier than read().

    Thanks for the help!
    Justin

  2. #2
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    Serial ports require some special handling for reading, due to the relatively slow, asynchronous, and unreliable nature of the input data. I reccommend review of the techniques explained in
    Serial Programming Guide for POSIX Operating Systems
    Serial Programming HOWTO
    Serial HOWTO

    --- rod.
    Stuff happens. Then stays happened.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...