Article 52WTD Read data from USB to 485 converter, send out a line from a file, repeat.

Read data from USB to 485 converter, send out a line from a file, repeat.

by
Bill_Blessing
from LinuxQuestions.org on (#52WTD)
I'm using Ubuntu 18.04.4 by way of background. I'm trying to create a small bash script that will read from a USB port and, if that reading matches a predefined string, output a line from a file. This can go on until EOF is reached. The reason that I would like something like this is that it will allow me to run some basic tests on our equipment.

There I can loop on reading any line from the USB - I'll make it more specific later - but get hung up on reading from a file. There are many, many examples of reading files line by line, but none quite like what I'm trying to do.

Here is my attempt at a shell script:

Code:#!/bin/bash
echo Test comms
stty -F /dev/ttyUSB0 19200 raw -echo #CONFIGURE SERIAL PORT
inFile="~/Documents/test/messages.txt"
IFS= read -r -d '' inText <"$inFile"
while read INPUT </dev/ttyUSB0
do
echo $inText
inText=$(( inText + 1 ))
doneI plan on reading up more on shell scripts, but for now this would be a big help.latest?d=yIl2AUoC8zA latest?i=C8i0p7b8nco:i55u_zgmXB4:F7zBnMy latest?i=C8i0p7b8nco:i55u_zgmXB4:V_sGLiP latest?d=qj6IDK7rITs latest?i=C8i0p7b8nco:i55u_zgmXB4:gIN9vFwC8i0p7b8nco
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments