USB Serial Communication problems in Windows

Status
Not open for further replies.

DrM

Well-known member
On a windows 10 computer, using python with pyserial to read output from a Teensy 3.2.

The Teensy program generates about 4,000 lines of output, but on the desktop, it stops getting input at line 1600 and every call to serial.readline() after that timesout.

Everything works great when I run the same python program on a Linux desktop or laptop.

The Windows Device Manager shows a usb serial interface at com9:, and the driver is a Microsoft Serial driver from 2006.

Serial_install.exe, does not run. It reports that there is already a usb serial driver installed and does not offer an option to replace it.


So what do we do to get this working?

Thank you

From the Teensy code:

Code:
  for (int i=0; i<3694; i++){
    Serial.print (i);
    Serial.print (' ');
    Serial.println(4096-buffer[i]);
  }  
 Serial.println("done");


From the python code. After 1591 lines, every read elicits the "zero length line" message, at intervals corresponding to the timeout parameter for the serial interface.

Code:
   lines = []

    while True:
        l = ser.readline()

        if l is None:
            print( 'null read at', n )
            return lines

        if (sys.version_info > (3, 0)):
            l = l.decode("utf-8" )
            
        if debug:
            print( 'read ', l.strip() )
            
        l = l.strip()
        if len(l) == 0:
            print( 'zero length line at', n, 'count', m )
            m += 1
            continue
        
        if l.startswith('done' ):
            break

        lines.append(l)
 
Last edited:
The problem turns out to be a too small buffer in the Windows USB serial driver.

The solution is simply to read the input from the teensy faster, and buffer it up manually.
 
Status
Not open for further replies.
Back
Top