1

I'm trying something like Linux serial port listener and interpreter?

However, I want a timeout

#!/bin/bash
stty -F /dev/ttyUSB1 300 cs7 parenb -parodd
echo -n -e 'Sending '
echo -n -e "\x2F\x3F\x21\x0D\x0A">/dev/ttyUSB1
read LINE -r -t1 </dev/ttyUSB1
echo -n "Read "
echo $LINE

I'd like to continue if I do not get input; it just hangs.

(It is part of an input routine for reading a powermeter https://electronics.stackexchange.com/questions/305745/ir-data-from-landisgyr-e350)

Leif Neland
  • 1,416
  • 1
  • 17
  • 40

1 Answers1

0

Based on this answer, I think you can use the timeout function to get what you want.
You'll probably have to do a bit of formatting and redirect the file to stdout, like in this answer, so it would look like this :

LINE="$(timeout 1 cat /dev/ttyUSB1)"  
echo -n "Read "  
echo $LINE

You can also just use a combination of sleep and kill, like in here.

Prewitt
  • 33
  • 2
  • 10
  • I couldn't get read from serial to work, so I did this instead: https://electronics.stackexchange.com/questions/305745/ir-data-from-landisgyr-e350/344460#344460 – Leif Neland Dec 11 '17 at 16:17