I have some device, connected to serial port. Actually, it is Arduino
based temperature sensor.
I wish to write a script, which will connect to serial port, send a command to device, receive it's answer, print it to stdout
and exit.
What is correct way to do this?
Usually, when accessing local program, it is ok to redirect it's output. For example, this is how I read CPU
temperature.
datetime=$(date +%Y%m%d%H%M%S)
cputemp=$(sensors atk0110-acpi-0 | sed "s/CPU Temperature:[^0-9]*\([0-9\.]\+\).*/\1/;tx;d;:x")
echo "$datetime\t$cputemp"
Unfortunately, $()
relies on explicit program end, which is not the case with serial communication. Serial server always online and has no explicit "sessions".
Of course, I can check to line feeds. But is this correct action? May be I should write my Arduino
program so that it send Ctrl-Z
after each response or something?