Why “sudo cat /dev/ttyACM0” run only 1 time? (GPS)

Click For Summary

Discussion Overview

The discussion revolves around the issue of using the command `sudo cat /dev/ttyACM0` to read GPS data from a u-blox GNSS Evaluation Kit Time EVK-M8T. Participants explore why the command appears to run only once and then stops, despite the device seemingly continuing to function.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant describes successfully receiving NMEA messages through the command but notes that it stops without any apparent reason.
  • Another participant suggests that the `cat` command may not terminate because the tty device does not send an EOF character, leading to a misunderstanding of its operation.
  • A later reply acknowledges the possibility that the process is still running, as indicated by the blinking LED on the device, despite the terminal not displaying new data.
  • Some participants propose using the `dd` command as an alternative to `cat` for copying device data to a file, while others express confusion about how to implement this.
  • There is a suggestion to create a shell script that reads data until a specific end word is detected, which could simplify the process.
  • One participant questions the expected behavior of `cat`, suggesting that it typically does not wait for new data and may not be the appropriate tool for this task.

Areas of Agreement / Disagreement

Participants express varying understandings of how the `cat` command operates with tty devices, with some agreeing on the hypothesis that the command may be waiting for more data, while others question its expected behavior. The discussion remains unresolved regarding the best approach to handle the data reading process.

Contextual Notes

There are limitations in understanding the specific behavior of the GPS device and the commands being used, as well as the potential for different interpretations of how to manage data reading and termination in a shell environment.

Nate Duong
Messages
125
Reaction score
4
hi group,

I am working on the GPS data collection, I Need help. If anyone who has been working on the u-blox GNSS Evaluation Kit Time EVK-M8T before and have seen it, please help.
I do not know why sudo cat /dev/ttyACM0 only 1 time.

I have the U-blox EVK-M8T which can read the NMEA messages through the Ubuntu terminal window. When I have good set up, and type the command `sudo cat /dev/ttyACM0, it show me the NMEA meassages, such as:

$GLGSV,3,3,09,87,06,340,*52
$GNGLL,,,,,140236.00,V,N*56
$GNZDA,140236.00,10,03,2017,00,00*7C
$GNRMC,140236.85,V,,,,,,,100317,,,N*68
$GNVTG,,,,,,,,,N*2E
$GNGGA,140236.85,,,,,0,00,99.99,,,,,,*77
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
$GPGSV,3,1,12,10,76,330,52,11,03,322,44,12,23,100,47,14,32,270,44*7E
$GPGSV,3,2,12,15,10,077,,18,70,123,46,20,02,130,47,21,22,189,47*73
$GPGSV,3,3,12,24,40,050,49,25,16,142,39,31,13,211,48,32,52,288,50*72
$GLGSV,3,1,09,69,26,096,28,70,62,024,37,71,30,315,29,73,37,171,36*6A
$GLGSV,3,2,09,79,20,030,,80,64,095,31,85,09,235,27,86,20,287,33*62
$GNGLL,,,,,140236.85,V,N*5B
$GNZDA,140236.85,10,03,2017,00,00*71

but suddenly, it stopped running without touching anything, I did not know why, and I tried to run again but it did not run. Until, mechanically unplug USB cable and connect a gain, it worked.

it happened again again and again...

Does anyone know what is going on?

Thank you.
 
Engineering news on Phys.org
Nate Duong said:
I do not know why sudo cat /dev/ttyACM0 only 1 time.
I know nothing about your GPS data stuff. But if you are cat'ing a file the process will run until it encounters EOF. If your tty device does not send an EOF character then the cat process will just wait patiently for more data from that tty. So I think you are seeing the process run and not terminate, but you don't realize it. It is not terminating until you unplug things and ungraciously cause it to be killed.

Does that sound to be what's happening?
 
NascentOxygen said:
ungraciously
maybe it is true, because when it stops running on the Ubuntu terminal window, but the LED light of the device is still blinking every 1 second.

If you know something about it, can you tell me how to save those data into text file or dat file...

Thank you.
 
NascentOxygen said:
So I think you are seeing the process run and not terminate, but you don't realize it. It is not terminating until you unplug things and ungraciously cause it to be killed.

Kudos. That is exactly the kind of hypothesis that is the essence of effective software troubleshooting Think of a scenario that matches the evidence.
 
How quickly does it take for that complete data read, just a second or two?

You could start an asynchronous process that waits for sufficient time for cat to complete, then kills your cat.

In place of cat, consider dd as a utility to copy the device data to a file. dd has unusual syntax, so man dd
 
NascentOxygen said:
How quickly does it take for that complete data read, just a second or two?

You could start an asynchronous process that waits for sufficient time for cat to complete, then kills your cat.

In place of cat, consider dd as a utility to copy the device data to a file. dd has unusual syntax, so man dd

I think 1 second gives me info. of the list which I posted above, and every second gives update of value of the list.

And I do not understand how to kill cat, and man dd.

Could you please give me in a little detail, so i can understand.

Thank you very much.
 
'man' is the linux online manual, it returns documentation on linux commnds
man kill
man dd

Then google and look for examples in shell scripts where these are used.
 
Nate Duong said:
$GLGSV,
$GNGLL,,,,,
$GNZDA
I know nothing about GPS data. Does one of these 'words' indicate the end of your block of useful data? If so, it might be sufficient for your shell script to loop through reading and writing each line to a file until it finds that end word, then exiting the shell script. This approach would be simpler, and you'd not need to use kill.

The shell command for reading one line is: read -r

Is this problem part of some exercise or homework in your studies?
 
Wait, I'm confused, what do you expect cat to do? Cat doesn't stick around, it dumps the file and then closes.

Do you mean to use "tail -f"?
 
  • #10
I was a little surprised that cat did seem to be waiting. Poster can easily check if it is using: ps