pySerial cuts off text in file
Brought to you by:
cliechti
Hello,
I'm using pyserial to access ADB in my Android device and have some problems. I'm trying to print out the content of a file and it just print out half it.
My code look like this:
ser = Serial('/dev/ttyUSB0', 115200, timeout=0) ser.write(' cat /sdcard/dump.xml \r\n') sleep(5) while ser.inWaiting(): print ser.readline() ser.close()
Cat works without any problems inside my serial port terminal so must be some setting with the Serial class. Does it have some maxlimit or not flush correctly? I have tried to play around a bit with it's variables but can't seem to find anything that work.
you are opening the serial port without flow control. this means that when the internal buffers of the OS as full, it will drop further incoming data. so the sleep() call is the problem here.
you could try using flow control (hardware or software, if the device supports it) or try to read fast enough (no sleep call, maybe add a reader thread and do your own buffering)
also ser.inWaiting() may be unreliable to detect the end of a data stream. the available data in the buffer may drop to zero when all is read and the data on the serial port is received slowly (low baud rate) or a pause in the stream)