method to capture serial data from /dev/ttyACM0 or /dev/rfcomm0 in linux?

Status
Not open for further replies.

linuxgeek

Well-known member
I'm looking for a quick and dirty way to capture serial data over the USB serial, or a bluetooth serial connection in linux.

I can use 'cat' in a loop, but apparently it drops a lot of lines.

The serial monitor in arduino works, but I want something from a command line.

I can write something in java, but serial is kinda clunky in java, and I really just want a quick-and-dirty solution. Anyone have any ideas?

I tried ttylog, which I suspect is working, but the text is garbled, as if it's expecting binary.

Here's the basic sketch:

Code:
int i=0, msecElapseFromStart=0;
int msecElapseFromPrior = 0;

void setup() {
  while (!Serial && (millis () <= 3000));
  Serial.begin(9600);
}

void loop() {
  msecElapseFromPrior = millis() - msecElapseFromStart;
  if (msecElapseFromPrior >= 100) { // update LCD once per half-second independent of read rate
    Serial.print("0");
    Serial.print(",");
    Serial.print("1");
    Serial.print(",");
    Serial.print(i);
    Serial.print(",");
    Serial.print(msecElapseFromPrior);
    Serial.print(",");
    Serial.println(msecElapseFromStart);
    Serial.flush();
    i++;
    msecElapseFromStart = millis();
  }
}

Using cat like below

Code:
#!/bin/sh

echo "Usage: <program> <OUTPUT>"

INPUT="/dev/ttyACM0"
OUTPUT="$1"

while true; do
    cat "$INPUT" >> "$OUTPUT"
done

I get something like this

Code:
0,1,0,809,0
0,1,6,100,1309
0,1,7,100,1409
0,1,27,100,3409
0,1,49,100,5609
0,1,56,100,6309
0,1,58,100,6509
0,1,65,100,7209
0,1,89,100,9609
0,1,91,100,9809

Using
"ttylog -b 9600 -d /dev/ttyACM0"

I get something like this:

Code:
X<o��
X<o��
X<o��
X<o��
X<o��
X<o��
X<o��
X<o��
X<o��
 
On the TYQT thread - there is a command line 'TYC monitor' that I had working for this as I recall on Windows and it was developed on Linux and works there. I tried Putty and maybe TeraTerm as well to some good effect.
 
I started working off some example java code, but as expected, that proved problematic. Didn't recognize the port for some reason that I think is probably related to the RXTX libraries.

I just resolved it by using something called grabserial, in case anyone else is interested:
https://github.com/tbird20d/grabserial

It's funny coming across the same users by googling for answers. It looks like jbeale wrote something that I'm guessing is probably pretty good. It worked for me:
https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=64545

Python seems pretty useful, but I still have a very hard time with the whole whitespace dependency. Makes me uneasy.
 
Some weeks back another person ended up getting good results for Serial collection with Python after he had early issues.
 
... why do you need to use cat in a loop?

I just open a terminal and use:
cat < /dev/ttyACM0

This function is basically the only reason I moved over to linux. It just makes serial communication so much easier.

You can also output to files using:
cat /dev/ttyACM0 > output.txt

Or my personal favourite both:
cat /dev/ttyACM0 | tee output.txt


Or even a hex dump:
od -x < /dev/ttyS0

Use stty to configure baud rates

I've received a 100MB file at 4000000 baud without any lines missed using this method
 
Last edited:
I use cat in a loop cause it stops as soon as the buffer is empty (at least that's what I think was happening)

I'll try all of them tho and double-check.

BTW, in case others are curious, grabserial worked for /dev/ttyACM0 but did not work bluetooth serial (ie /dev/rfcomm0), but jbeale's pythone code did.
 
Status
Not open for further replies.
Back
Top