Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Shell io from and to serial device
- X-seq: zsh-users 23872
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: dominik.vogt@xxxxxx, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Shell io from and to serial device
- Date: Thu, 14 Feb 2019 17:02:30 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=2waB8SJTTA59GmqA2Hh/vSAjVGvERVhs4nSrg7GaBdM=; b=cjVkpLYjZ32gqeerpwdqFqJ/1l5o3W6+GsjiIlNx/dFTDRABzl1bJRCwMV3NfPICif oQzyf1TJ5IW7XzgtA6kLNdSYm7Xgw/ozUjHB9Vlo+R9yPe0wpnPni1/A06I9R13pEwpX WDLwyEBSPjGOmbotkJUJmoPlOzmz+O7pHrH1agiCSynsv1fA40bHaXFNnm5RhLL/amiM m8svppsXC3BzIEQCNK20Cfq4rNS+YGHvMytznm8HgG4LQzzmNJaSjKs/vdsXhocf7ErK qQrJojbjZ4U94vTcpYBUrvypjF+/xnmHy7y3rKs5iQ0XRMaK6GTIexTM4JZFQVhRLi4e m1BA==
- In-reply-to: <20190214000042.ed73yom5s26pst5p@gmx.de>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20190214000042.ed73yom5s26pst5p@gmx.de>
On Wed, Feb 13, 2019 at 4:01 PM Dominik Vogt <dominik.vogt@xxxxxx> wrote:
>
> 1. configure serial line, e.g. with
>
> $ stty -F /dev/ttyUSB0 speed 115200 cs8 -cstopb -parenb -echo
>
> 2. Send some string to the serial line
>
> $ echo foo > /dev/ttyUSB0
You might get better results using "printf" rather than "echo",
depending on how precise you need to be about what is sent to the
device (where newlines appear, etc.).
> 3. Grep for a certain reply with configurable, sub second timeout.
I think what you want to do here is use "read -E" combined with
"zselect -t" (assuming you have a recent zsh where zselect accepts
hundredths of a second timeouts).
I have a bit of trouble following your example script (what the heck
is that "cat <<EOF" doing in there?), and you haven't said anything
about the "protocol" used on the serial device (is every write by
either side supposed to end with a newline, for example?) so it's hard
to be specific, but something like:
trap "kill 0 2>/dev/null" EXIT
stty -F "$DEV" speed 115200 cs8 -cstopb -parenb -echo > /dev/null
{ zselect -t 1 -w 1 && printf "%s\n" "$SEND" > "$DEV" } &
# $TIMEOUT has to be adjusted to be 100ths before doing this;
# adjusted $TIMEOUT better be > 1 or this will always fail
coproc { zselect -t $TIMEOUT -r 0 || kill 0 2>/dev/null }
# This assumes the "other end" always sends full lines
while read -E LINE >> "$LOGFILE"; do
print -r -- "$LINE"
done | grep --max-lines=1 --quiet "$EXPECT"
# If not exiting here, "print -p $?" to end the coproc
exit $?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author