pyserial / pyserial

Python serial port access library
Other
3.25k stars 1.12k forks source link

USB CDC/ACM: hangs on non implemented optional class-specific request codes in Win10 #739

Open kimstik opened 9 months ago

kimstik commented 9 months ago

I have my own minimalistic implementation of a USB CDC device stack. It does not implement any optional (as per ACM) class-specific request codes such as GET_LINE_CODING. The caps fields of ACM Functional Descriptor are set to zero accordingly.

There are no visible problems under Linux. Under Win10 it only works with the Bray terminal.

Simple code

import serial
ser = serial.Serial('com3')

hangs with error

  File "C:\test\test.py", line 2, in <module>
    ser = serial.Serial('com3')
  File "C:\Python\lib\site-packages\serial\serialwin32.py", line 33, in __init__
    super(Serial, self).__init__(*args, **kwargs)
  File "C:\Python\lib\site-packages\serial\serialutil.py", line 244, in __init__
    self.open()
  File "C:\Python\lib\site-packages\serial\serialwin32.py", line 80, in open
    self._reconfigure_port()
  File "C:\Python\lib\site-packages\serial\serialwin32.py", line 222, in _reconfigure_port
    raise SerialException(
serial.serialutil.SerialException: Cannot configure port, something went wrong. Original message: PermissionError(13, 'A device attached to the system is not functioning.', None, 31)

image

kimstik commented 9 months ago

Since the system is throwing unexpected requests, it looks like the problem is a little deeper in the stack.

In the code of serialwin32.py file, the GetCommState return code is not checked. But the return of SetCommState is checked and returns 0. Is it appropriate to throw SerialException in this case?

kimstik commented 9 months ago

It seems "USB/CDC with unimplemented optional features" issue is know quite long time: SetCommState() returns FALSE GetLastError() returns 31 which is "A device attached to the system is not functioning".