From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id ce43d7ee for ; Fri, 15 Feb 2019 01:03:04 +0000 (UTC) Received: (qmail 8781 invoked by alias); 15 Feb 2019 01:02:51 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23872 Received: (qmail 24520 invoked by uid 1010); 15 Feb 2019 01:02:51 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf1-f54.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25112. spamassassin: 3.4.2. Clear:RC:0(209.85.167.54):SA:0(-1.9/5.0):. Processed in 3.458043 secs); 15 Feb 2019 01:02:51 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=2waB8SJTTA59GmqA2Hh/vSAjVGvERVhs4nSrg7GaBdM=; b=WlvSGGoOMxZx8hycFBDOmdcyRo9r5zZjw7P9wPVGjWVcQjtZNUoOILQ8rLx4XHWV9S F0jFkep6IEj7e6as1Il9vKA3BmExZjc4rPNjTTpeKTNZhk/DgRzgG5THWtvvxuZ3rJuT bgqFPREKSSC7VwrsSijE6/Xz1wLlkLtvLKRDlfEHrQdbMnU2JUM1iNX2G+Fi+sM4xyZ2 YJ6zIBK8WboGmJfbu7IBQQOlgwsrQJGTxT0B3n8OfdzYotjyiH+ltaCxfXM3Tgh42zFN noaVLF/tD/l6+GVfVeFBdppBAQaQYoRs25m6V/FZbhb+Qf1kB/cMs6fpM5funtqZ0zJc aXfw== X-Gm-Message-State: AHQUAuYJnyQod777z++M6kZOSSVFoXepcRCrqQmrNoLfSP3dClcB8Lar i7KRCGmjt/YDw+vmTTxJK3pciCfVzPDzy7ZnKLsyQQ== X-Google-Smtp-Source: AHgI3IaWlDZwgDewS6djMQg8WtaF1VzGoc+8MOBxIHzbJfkygLo2wF3WphfQ35wrfYq/V26MREEUdCsAV3O8pimJfBA= X-Received: by 2002:ac2:5085:: with SMTP id f5mr3916678lfm.30.1550192563118; Thu, 14 Feb 2019 17:02:43 -0800 (PST) MIME-Version: 1.0 References: <20190214000042.ed73yom5s26pst5p@gmx.de> In-Reply-To: <20190214000042.ed73yom5s26pst5p@gmx.de> From: Bart Schaefer Date: Thu, 14 Feb 2019 17:02:30 -0800 Message-ID: Subject: Re: Shell io from and to serial device To: dominik.vogt@gmx.de, Zsh Users Content-Type: text/plain; charset="UTF-8" On Wed, Feb 13, 2019 at 4:01 PM Dominik Vogt 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 </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 $?