Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read from serial port and store in hexadecimal

I have a vhf radio which sent a status message continuosly through the serial port, and I need the messages that I got to be stored as hex data in a text file

I tried hexdump command as shown below, and the data that I've got from vhf radio is correct, but the problem with this script that when I execute it, it does not end until I press ctrl-c

d -A n -t x1 -w128 /dev/ttyS0 > file.txt

so I've tried another command which is read command as follow:

COUNTER=0
while [ $COUNTER -lt 10 ]; do
read -r -t1 -N128 DATA < /dev/ttyS0 
echo $DATA >> file1.txt
od -A n -t x1 -w128 file1.txt >> file2.txt
let COUNTER=COUNTER+1
done

but the data stored in file2.txt is not correct.

the message that I got from the radio is not in a format that I could interprete it as per the radio prtocol document. so when I said that the data is not correct I mean that the message is could not be interpreted (it received randomly)

note that I've setted the serial port before executing both scripts as follow:

stty -g /dev/ttyS0 raw
stty -F /dev/ttyS0 9600

so, please help me to figure this out. or gave me aother way to read from serial port.

Regards,

like image 279
Latifa Avatar asked Sep 28 '15 12:09

Latifa


1 Answers

The Problem is solved :)

I tried to use hexdump command by setting -N to KB and it works successfuly

it reads from serial port until 1000 bytes and it stops

od -A n -N KB -t x1 -w128 /dev/ttyS0 > /tmp/filename.txt

so, thank you guys for your cooperation. I really appriciated.

like image 181
Latifa Avatar answered Sep 23 '22 04:09

Latifa