We have code that talks to our USB COMM class device, which works fine under Windows XP but is failing under Windows 7. Specifically the call to SetCommState is failing. Here's a simplified snippet. Note that in this case we don't even change any fields from GetCommState, but the result is that SetCommState fails with an error code of 87 (illegal parameter).
DCB dcb;
SecureZeroMemory(&dcb, sizeof(DCB));
dcb.DCBlength = sizeof(DCB);
if (!GetCommState(m_hIDComDev, &dcb)) {
DWORD dwError = GetLastError();
CloseHandle(m_hIDComDev);
dlDebug(5, "SerialPort::openPort") << "GetCommState failed for" << m_portName << dwError;
return 0;
}
dlDebug(5, "SerialPort::openPort") << m_portName << "rate" << dcb.BaudRate << "size" << dcb.ByteSize;
// dcb.BaudRate = baud;
// dcb.ByteSize = 8;
if (!SetCommState(m_hIDComDev, &dcb)) {
DWORD dwError = GetLastError();
CloseHandle(m_hIDComDev);
dlDebug(5, "SerialPort::openPort") << "SetCommState failed for" << m_portName << dwError;
return 0;
}
Any ideas what might be going wrong? One thought is that the USB device descriptor is incorrect and Win7 is more rigorous about double-checking (but I'm a little skeptical about that as the device works fine under MacOS X and Linux with no issues). I'm stumped!