Find the answer to your Linux question:
Results 1 to 4 of 4
I am experimenting with reading an NMEA data stream from a Garmin GPS receiver via serial port in Ubuntu. Yesterday I was able to test the serial communication by executing ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    3

    Serial port problem

    I am experimenting with reading an NMEA data stream from a Garmin GPS receiver via serial port in Ubuntu. Yesterday I was able to test the serial communication by executing "cat /dev/ttyS0" and view the data stream. I was also able to run Windows in VMWare and communicate with the GPSr using a 3rd party program. The Windows test still works today. However, when I run "cat /dev/ttyS0" now hangs and shows no data. I've rebooted a couple of times, reset the GPSr, and basically done everything I can think of to read the serial port but still no luck. Does anyone have an idea what might be wrong? Can I reset the serial port or do I need to configure something differently in order to read it?

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Yesterday I was able to test the serial communication by executing "cat /dev/ttyS0" and view the data stream.
    You were very, very lucky that it worked. That's highly unusual. Usually you have to worry about setting serial characteristics like the baud rate, and terminal discipline details like echoing on/off.

    See if minicom can help you.

    By any chance are you going to do something in C with this?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    3
    Apparently I *did* get lucky. I was able to use minicom to capture the data stream but have been unable to use my C program to do so. Here is a snippet with error checking removed:

    FILE* const in = fopen("/dev/ttyS0", "r");
    char buf[80];
    while( fgets(buf, 80, in) != NULL )
    {
    printf("%s", buf);
    }


    I got lucky with this code yesterday also, but obviously I need to take a different approach. Can you point me in the right direction?

    Thanks!
    Richard

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Can you point me in the right direction?
    There are a couple of ways you could go.

    One way is to examine the source of minicom.

    Another way, which I recommend, is to look at the source of a program I wrote which actually uses the modem. But you can ignore the modem part and just go for the serial line handling part. The program is very well commented, and discusses interesting things about the minicom source code. (You don't have to have the minicom source code handy to understand these comments.)

    The code is available under GPL 3.0 here.

    Edit: I will keep that code there for at least two weeks.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

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