Re: SetCommState() fails with "A device attached to the system is not functioning"

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



My suspicion would be that the virtual control does not successfully implement all the
IOCTL codes required. There are something like 40 IOCTLs that a serial port must support.
If it would fail to support one of these, the consequence would probably be the error you
are seeing.

It sounds like the fix is not in SetCommState, but in the device driver for the virtual
device.

Short of exploring the DDK documentation in detail, to see what IOCTL is failing, I don't
have any effective way to isolate the failure. Note that SetCommState is nothing more
than a high-level wrapper around a set of DeviceIoControl calls.

I'd suggest downloading the file monitor from www.sysinternals.com and study what IOCTLs
are being sent to your device (look for IRP_MJ_DEVICE_CONTROL requests) and which one is
failing.
joe

On Fri, 15 Feb 2008 19:46:45 GMT, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:

Hello,

I have successfully opened a COM port, COM6. It is actually a virtual COM
port provided by a Microchip USB device. I can read/write to the device
using the default parameters fine.

But when I try to set the parameters with SetCommState(), the function
returns FALSE, and GetLastError() is 31 which is "A device attached to the
system is not functioning".

Here is the DCB that SetCommState gets, nothing unusual:

DCBlength: 28
BaudRate: 9600
fBinary: 1
fParity: 0
fOutxCtsFlow: 0
fOutxDsrFlow: 0
fDtrControl: 0
fDsrSensitivity: 0
fTXContinueOnXoff: 0
fOutX: 0
fInX: 0
fErrorChar: 0
fNull: 0
fRtsControl: 1
fAbortOnError: 0
fDummy2: 0
wReserved: 0
XonLim: 0
XoffLim: 0
ByteSize: 8
Parity: 0
StopBits: 0
XonChar: 0
XoffChar: 0
ErrorChar: 0
EofChar: 0
EvtChar: 0
wReserved1: 0


The same code works fine for ordinary COM ports, but not for the MicroChip
CDC USB one. This is a pain because most serial port libraries call
SetCommState() after the CreateFile() succeeds, and when SetCommState()
fails, the library reports the port cannot be opened. Thus, we are severely
limited in the serial port libraries we can use.

Is there any way SetCommState() can be fixed?

Thanks,
David

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: rs485 on SBC84500
    ... > data to a serial port. ... If a sufficient driver was never created, you end up using ioctl ... to control the devices registers directly from user space. ...
    (comp.os.linux.embedded)
  • Re: Serial port problem,i can write but cant read!!
    ... Did you call SetCommState()? ... I've attempted to use ReadFile and I get odd results. ... CE app gets nothing but jibberish), even when I just do a read. ... with the COM port. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: How to timeout SetCommState?
    ... Thanks for the suggestion. ... It may not work because when SetCommState gets ... between the bluetooth devices and it is not clean. ... the com port is a bluetooth port. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Can Python serial support run at 45.45 baud?
    ... ser = serial.Serial(port, baudrate=baud, ... ValueError: Cannot configure port, some setting was wrong. ... (87, 'SetCommState', 'The parameter is incorrect.') ...
    (comp.lang.python)
  • SetCommState() fails with "A device attached to the system is not functioning"
    ... I have successfully opened a COM port, ... port provided by a Microchip USB device. ... But when I try to set the parameters with SetCommState(), ... This is a pain because most serial port libraries call ...
    (microsoft.public.vc.mfc)