Anybody know how to make stdin non-blocking?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Anybody know how to make stdin non-blocking?

Post by dhylands » Tue Apr 16, 2019 11:01 pm

I'm trying to improve rshell to handle dropped characters curing cp commands more robustly.

This means that I need to be able to detect dropped characters, which in turn means I need to be able to issue a read on stdin that will timeout.

I tested select/poll and those didn't work. There doesn't seem to be an any() method on stdin.

If non-blocking stdin isn't an option, then I'll probably do something like slip framing and then if the host side fails to get an ACK then it will start sending frame start sharacters until it gets an ACK/NAK (eventually it will send enough frame start characters to satisy the read).

chuckbook
Posts: 135
Joined: Fri Oct 30, 2015 11:55 pm

Re: Anybody know how to make stdin non-blocking?

Post by chuckbook » Wed Apr 17, 2019 8:48 am

Hi Dave,
I'm not quite sure I understood your problem but we always use termios with c_lflags ICANON == off and parameters:

Code: Select all

c_cc[VMIN] = 0
c_cc[VTIME] = 0
That makes perfect polling read.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Anybody know how to make stdin non-blocking?

Post by dhylands » Wed Apr 17, 2019 12:22 pm

Sorry, I meant make stdin on the MicroPython side non-blocking.

chuckbook
Posts: 135
Joined: Fri Oct 30, 2015 11:55 pm

Re: Anybody know how to make stdin non-blocking?

Post by chuckbook » Wed Apr 17, 2019 2:47 pm

I thought so. But I agree, having some of the termios features on MPY's stdin would be nice.
So far we are using pyb.USB_VCP() to do things like USB to UART converters on pyboards.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Anybody know how to make stdin non-blocking?

Post by dhylands » Wed Apr 17, 2019 3:40 pm

Yeah - if I were to use pyb.UART or pyb.USB_VSP (or the machine variants) then I could use the any() method.

rshell uses stdin since it doesn't know which UART (if any) is being used, or whether USB is being used.

Post Reply