title: Read from serial port and store in hexadecimal
body: <p>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</p>
  
  <p>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</p>
  
  <pre><code>d -A n -t x1 -w128 /dev/ttyS0 &gt; file.txt
  </code></pre>
  
  <p>so I've tried another command which is read command as follow:</p>
  
  <pre><code>COUNTER=0
  while [ $COUNTER -lt 10 ]; do
  read -r -t1 -N128 DATA &lt; /dev/ttyS0 
  echo $DATA &gt;&gt; file1.txt
  od -A n -t x1 -w128 file1.txt &gt;&gt; file2.txt
  let COUNTER=COUNTER+1
  done
  </code></pre>
  
  <p>but the data stored in file2.txt is not correct.</p>
  
  <p>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)</p>
  
  <p>note that I've setted the serial port before executing both scripts as follow:</p>
  
  <pre><code>stty -g /dev/ttyS0 raw
  stty -F /dev/ttyS0 9600
  </code></pre>
  
  <p>so, please help me to figure this out. or gave me aother way to read from serial port.</p>
  
  <p>Regards,</p>