Menu

#65 pySerial cuts off text in file

v1.0 (example)
closed
None
5
2015-08-05
2015-02-08
No

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.

Discussion

  • Chris Liechti

    Chris Liechti - 2015-02-09

    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)

     
  • Chris Liechti

    Chris Liechti - 2015-02-09
    • assigned_to: Chris Liechti
     
  • Chris Liechti

    Chris Liechti - 2015-08-05

    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)

     
  • Chris Liechti

    Chris Liechti - 2015-08-05
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.