Adding timeout to sys.stdin.read(1)
-
I am trying to read from the serial and telnet using sys.stdin.read(1). Since the function is blocking, I tried some suggested options with uselect:
import sys, uselect spoll=uselect.poll() spoll.register(sys.stdin, uselect.POLLIN) def read1(): return(sys.stdin.read(1) if spoll.poll(0) else None)However, I get the following error:
OSError: stream operation not supportedon the following line:spoll.register(sys.stdin, uselect.POLLIN)Any suggestion for non-blocking read of UART and Telnet using non-blocking calls?
Thank you in advance!
-
@berni have you tried setting it to non-blocking?
If using the UART directly there is an
anymethod which tells you if there’s data available, not sure if that is available via thestdininterface nor if that would work with telnet. -
@jcaron unfortunately, there is any method with the
stdinand I haven't found any way to interact directly with the telnet server.My previous implementation used the UART, but then I realized that I was able to read from Telnet, but no way to type anything. Also, the telnet connection was quite slow and unreliable for some reason (time out when login/password). With
stdinit works much better, but not typing anything will block the application forever.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login