none
USB Serial Communication, ReadFile() returns zero bytes read RRS feed

  • Question

  • I am trying to implement serial communication (Wince device <-> PC) by using USB function serial client. On PC side, I am using WinUSB, on Device/WinCE side, CreateFile on COM port and using ReadFile/WriteFile. On WinCE, I can open COM port, ReadFile succeeds, but it always returns 0 for "NumberOfBytesRead".

    Device does seem to receive data, because I can see this in debug window when sending data from PC:

    3936716 PID:400002 TID:1fb0002 [d0491a90]OUT Transfer : 0x200 bytes received
    3936716 PID:400002 TID:1fb0002 [0xd0491a90]m_state = EPT_IDLE;
    3936716 PID:400002 TID:1fb0002 UsbFnMdd!CPipeBase::TransferComplete: Completing transfer 0xd04966d0 on pipe at address 2 (0xd0492390)
    3936716 PID:400002 TID:1fb0002 [d0491a90] Issue transfer OUT begin for 0x200 bytes
    3936717 PID:400002 TID:100000a UsbFnMdd!CPipeBase::CloseTransfer: Closing transfer 0xd04966d0 on pipe at address 2 (0xd0492390)
    3936718 PID:400002 TID:100000a UsbFnMdd!CPipeBase::FreeTransfer: Placing transfer 0xd04966d0 on free list
    3936718 PID:400002 TID:100000a UsbFnMdd!CPipeBase::IssueTransfer: Issuing OUT transfer (0xd04966d0) on ep 2 (0x02) for 512 bytes

     However, that data never reaches my application... If I open USB as "COM4:", ReadFile succeeds. If I open as "UFN1:", ReadFile fails with error code 50 (The request is not supported). In both cases NumberOfBytesRead is always zero.

    Registry on device:

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers]
        "DefaultClientDriver"="Serial_Class"

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Serial_Class]
        "bcdDevice"=dword:0
        "DeviceArrayIndex"=dword:0
        "DeviceName"="USBFNS1:"
        "DeviceType"=dword:0
        "Dll"="serialusbfn.dll"
        "FriendlyName"="USB Cable Connection"
        "IClass"="{CC5195AC-BA49-48a0-BE17-DF6D1B0173DD}"
        "idProduct"=dword:CE
        "idVendor"=dword:45E
        "Index"=dword:4
        "Manufacturer"="Generic Manufacturer (PROTOTYPE--Remember to change idVendor)"
        "Prefix"="COM"
        "Product"="Generic Serial (PROTOTYPE--Remember to change idVendor)"
        "RxBufferSize"=dword:4000
        "Tsp"="Unimodem.dll"

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Serial_Class\Config]
        "EnableFlowHard"=dword:0
        "EnableFlowSoft"=dword:0

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\USBSER_Class]
        "bcdDevice"=dword:90
        "DeviceArrayIndex"=dword:1
        "DeviceName"="USBFNS2:"
        "DeviceType"=dword:0
        "Dll"="serialusbfn.dll"
        "IClass"=multi_sz:"{CC5195AC-BA49-48a0-BE17-DF6D1B0173DD}","{C375C787-B721-4b8e-B67F-A112D5C0A404}"
        "idProduct"=dword:79
        "idVendor"=dword:45E
        "Manufacturer"="Generic Manufacturer (PROTOTYPE--Remember to change idVendor)"
        "Prefix"="COM"
        "Product"="Generic Serial (PROTOTYPE--Remember to change idVendor)"
        "RxBufferSize"=dword:4000
        "Tsp"="Unimodem.dll"

     

    Questions:

    1. Can I use "serialusbfn.dll" for this purpose or I have to write my own driver?

    2. Do I have to include activesync in BSP?

    3. Is there anything else I am missing here?

     

    Friday, November 19, 2010 11:42 AM

Answers

  • I found the problem. I wasn't calling SetCommState(), and DCB structure was left uninitialized. Problem was actually caused by fDsrSensitivity member which was not set to FALSE, and any received data was ignored.

    • Marked as answer by Bulma Tuesday, November 23, 2010 8:36 AM
    Monday, November 22, 2010 8:38 AM