Reading from a serial device

This is a discussion on Reading from a serial device within the C Programming forums, part of the General Programming Boards category; Hello, I am trying to read from a device that spits out 2 values simultaneously per line when i read ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    26

    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.

    Example:
    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?

    Thanks,
    Chris

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    --
    Mats
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 06:27 AM
  2. Device Driver: sysfs confusion
    By filker0 in forum Linux Programming
    Replies: 0
    Last Post: 12-02-2005, 10: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, 09:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21