We have code that speaks to our USB class USB device, which works fine in Windows XP but doesn't work under Windows 7. In particular, the call to SetCommState does not work. Here's a simplified snippet. Please note that in this case we do not even change any fields from GetCommState, but the result is that the SetCommState code fails with error code 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 could go wrong? One thought is that the USB device descriptor is incorrect, and Win7 is more stringent for double checking (but I'm a bit skeptical about this, since the device works fine under MacOS X and Linux without problems). I'm at a dead end!
source share