Re: SetCommState() fails with "A device attached to the system is not functioning"
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 15 Feb 2008 19:45:39 -0500
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,Joseph M. Newcomer [MVP]
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
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- References:
- Prev by Date: Re: What the?
- Next by Date: Re: wizard wont recognize old dialog/cpp relationships
- Previous by thread: SetCommState() fails with "A device attached to the system is not functioning"
- Next by thread: Re: SetCommState() fails with "A device attached to the system is not functioning"
- Index(es):
Relevant Pages
|