Python serial.readline() not blocking -


i'm trying use hardware serial port devices python, i'm having timing issues. if send interrogation command device, should respond data. if try read incoming data quickly, receives nothing.

import serial device = serial.serial("/dev/ttyusb0", 9600, timeout=0) device.flushinput() device.write("command") response = device.readline() print response '' 

the readline() command isn't blocking , waiting new line should. there simple workaround?

i couldn't add commend add answer. can reference this stackoverflow thread. attempted similar question.

seems put data reading in loop , continuously looped on while data came in. have ask 1 thing if take approach, when stop collecting data , jump out of loop? can try , continue read data, when collecting, if nothing has come in few milliseconds, jump out , take data , want it.

you can try like:

while true:     serial.flushinput()     serial.write(command)     incommingbytes = serial.inwaiting()     serial.read(incommingbytes)     #rest of code down here 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -