Quantcast
Channel: Interpreting serial data via bash - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

Interpreting serial data via bash

$
0
0

I am trying to write a bash script that is able to interpreter data coming from a serial device. I configure the port in raw and then I am able to do a simple cat of /dev/ttyUSB0 and see the data. My issue is how to get the single line of data that the device sends in a bash variable so I can freely manipulate it.

I would like to have it in bash before going to Python so I always have a script that I know it works on every linux machine.

The data I receive has the following format: STX<26 x 4Bit-Nibbles codded as ASCII Payload>ETX

Ideally I could just store the new payload (so without STX and ETX) in a Bash variable every time I get a new string of data.

Solution

with the help of @icarus answer, I cooked up something that works like a charm. First I configure the serial port to generate the interrupt with STX value:

stty /dev/ttyUSB0 115200 intr 0x02

then to get the info I wanted, I use this loop:

ETX=$'\003'
while read -d "$ETX" line; do echo $line; done < /dev/ttyUSB0

Thanks again for the help, really great first experience in this website. Cheers


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images