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

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 


0
dc2983 (3206)
2/15/2008 7:46:45 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
2104 Views

Similar Articles

[PageSpeed] 46

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@remove-this.dcsoft.com> 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@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/16/2008 12:45:39 AM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:lfbcr35657sg92467bd6gte0gq4v6a0ieh@4ax.com...
> 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.

Thanks, Joe.  The driver is the standard usbser.sys (USB serial port driver 
that Windows provides).  But the firmware on the device may be suspect.  I 
just got a new build of the firmware and will let you know if it fixes the 
problem.

Thanks,
David 


0
dc2983 (3206)
2/16/2008 2:40:45 AM
"David Ching" <dc@remove-this.dcsoft.com> wrote in
news:F_ltj.10890$Ch6.5550@newssvr11.news.prodigy.net: 

Just curious... Which Microchip device is it? I am currently looking at 
Microchip devices for COM port via USB.

> 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.
> 
snip

0
2/19/2008 12:10:54 AM
"David Scambler" <dnospamscambler@bnospammm.com> wrote in message 
news:Xns9A497263E38DFDataScrambler@203.50.5.233...
> Just curious... Which Microchip device is it? I am currently looking at
> Microchip devices for COM port via USB.
>

It's a PIC18F4550.  Another team member reports that with a change in this 
chip's programming, SetCommState() now works.  But I have not been able to 
verify it yet.

Thanks again,
David



0
dc2983 (3206)
2/19/2008 8:58:40 PM
Reply:

Similar Artilces:

SetCommState() fails with "A device attached to the system is not functioning"
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 fTXConti...

Dial up networking error 31: A device attached to the system is not functioning
Dell Studio laptop Vista Home Premium SP2, no recent service packs, no newly installed software, no conflicts reported in Vista's device manager, external USB modem works fine on two other laptops. Attempting to use my dial-up account (that has been working fine for almost two years), I'm receiving an error just after the 'Verifying Username and Password..' message appears. Error 31: A device attached to the system is not functioning Entry in the event log: Source: RasClient The error code returned on failure is 31. Searching around, I found/downloaded...