You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtimeimportusb_cdcserial=usb_cdc.data# serial.reset_input_buffer() # ensure a clean initial state during testing# serial.timeout = 0 # just to be sure but doesn't really change anythingwhileTrue:
in_waiting=serial.in_waitingifin_waiting>0:
print(f'time={time.time()} connected={serial.connected} in_waiting={in_waiting} data={serial.readline()}')
time.sleep(1)
Behavior
Sending data like this to the device works (note the sleep after the write!)
It seems like the read* functions only return data when a sender is connected. The data that was received (in_waiting > 0) should, however, be readable even if the sender disconnected before the device was able to read it.
Additional information
It's irrelevant whether readline() or read(in_waiting) is used. The current behavior is especially problematic since one cannot send data doing something like this: echo 'hi' > /dev/ttyACM1.
The text was updated successfully, but these errors were encountered:
In case anyone else runs into this, my current workaround is to write something back from the device (serial.write(b'ok\n')) after read, and make the sender wait and as such keep the connection open until it receives the response:
CircuitPython version
Code/REPL
Behavior
Sending data like this to the device works (note the sleep after the write!)
Sending data like this does NOT work (empty bytes). The data is there (in_waiting > 0) but it can't be read
As soon as one does establish a connection (without writing new data), the data from the previous command can be read
Description
It seems like the
read*
functions only return data when a sender is connected. The data that was received (in_waiting > 0) should, however, be readable even if the sender disconnected before the device was able to read it.Additional information
It's irrelevant whether
readline()
orread(in_waiting)
is used. The current behavior is especially problematic since one cannot send data doing something like this:echo 'hi' > /dev/ttyACM1
.The text was updated successfully, but these errors were encountered: