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)

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I couldn't get read from serial to work, so I did this instead: electronics.stackexchange.com/questions/305745/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.