Thread: Reading from a serial device

  1. #1
    Registered User
    Join Date
    Aug 2008

    Reading from a serial device

    Hello, I am trying to read from a device that spits out 2 values simultaneously per line when i read from the device through cat /dev/device. These readings are split up by a comma.

    249, 371

    165, 398
    etc ...

    I am programming on a Linux machine and using the read() function. I have never done any serial programming. Is there a flag I can use in the read() function to read until a newline delimiter or the like. If I am on the computer and use the cat command it spits it out perfect, but when I read from the code it only outputs in proper format when I use 1 for the count parameter. I tried multiple values and none of them would give me an output like the examples above. The other way around this was created a loop to read until the comma then store as one value, then read till the newline and store as the second value. Is there a more efficient way to read from my serial device?


  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Are you doing this on Windows or Linux or both? Because I've already answered the Linux post, and it would have been good to understand if you need to support multiple platforms - if so, you can't use read(), since there isn't any corresponding function to "tc(g,s)etattr()" function in Windows.

    If you have no intention of using Windows, I don't understand the purpose of this post.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Device Driver: sysfs confusion
    By filker0 in forum Linux Programming
    Replies: 0
    Last Post: 12-02-2005, 11:36 AM
  3. Linux device files
    By ojschubert in forum C Programming
    Replies: 4
    Last Post: 04-25-2005, 10:41 AM
  4. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 09:41 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM