Weird result when reading from /dev/ttyS0 in a bash script
<p>I try to send a command to an hardware and want to grab the result back. I am sure that when I send a command like: <code>echo "read" &gt; /dev/ttyS0</code>, the command will be executed. The problem comes up while grabbing the feedback. For that, I want to use this script:</p>

<pre><code>#!/bin/bash

echo "READ" &gt; /dev/ttyS0

#stty -F /dev/ttyS0 9600
stty -F /dev/ttyS0 raw
stty -F /dev/ttyS0 -echo

STR="result "

while read -r -s -t 1 -n 1 c &amp;&amp; [[ $c != '&gt;' ]]
do
    STR+=$c
done &lt; /dev/ttyS0

echo $STR
</code></pre>

<p>The result should something like that.</p>

<pre><code>Level 0
001,001, 002,002;&gt;
</code></pre>

<p>But when I execute the script, sometimes I get the right result, but most times I get nothing back.</p>