none
reader.LoadAsync() don't work for ShortPacket receiving RRS feed

  • Question

  • Hi,
    I'm testing USB communication using WinUSB on Raspberry Pi2(RP2).
    This project is working on 'Windows 10 IoT Core' and with 'Visual Studio 2015 - UWP(C#)'.
    There is not the problem about the transmission toward the USB device from RP2 (OK), but there is malfunction to receive data toward RP2 from a USB device.
    In the case of quantity of data is less than 6 bytes, there is no problem for reception.
    However, an error occurs by the reception when the data exceed 7 bytes.
    In this application, I use chra equal to or less than 60 bytes as data of the transmission and reception.
    The codes of the reception department are as follows.
        public static String gRcv;
        public static Boolean rcvOk = false;
        public async static Task BulkRead()
        {
            UInt32 bytesToRead = System.Convert.ToUInt32(64);
            UInt32 bytesRead = 0;
            if (OpenFlag == true)
            {
                UsbBulkInPipe readPipe = usbDevice.DefaultInterface.BulkInPipes[0];
                readPipe.ReadOptions |= UsbReadOptions.None;
                var stream = readPipe.InputStream;
                DataReader reader = new DataReader(stream);
                try
                {
                    bytesRead = await reader.LoadAsync(bytesToRead);     //Number of the receive letters
                }
                catch (Exception exception)
                {
                    DspMessage(exception.Message.ToString());
                }
                finally
                {
                    gRcv = reader.ReadString(bytesRead);
                    if (gRcv == "") { rcvOk = false; } else { rcvOk = true; }
                }
            }
        }

    The line that an error produces is a line with rem(//Number of the receive letters).
    An exception occurs in 'reader.LoadAsync(bytesToRead)' and stops.
    It do not return to the original state of PC when this occurs once, and should reboot RP2.
    This cord refers to the following link.
    https://msdn.microsoft.com/en-us/library/windows/hardware/dn303346(v=vs.85).aspx
    With the sample, I change 'readPipe.ReadOptions | = UsbReadOptions.IgnoreShortPacket; ' to  'readPipe.ReadOptions | = UsbReadOptions.None;'.
    Because, this application use ShortPacket (less than 60 bytes).
    It do not make any problem at all when USB device send the data equal to or less than 6 bytes. (With this code, I tried transmission and reception consecutively for 30 hours, and It's OK.) But, there is not the need limiting such data at all and can use it commonly when I run this UWP application as LOCAL computer. (on LOCAL computer, I do not have any such problem at all) I thought that even a REMOTE computer should have worked because it moved with a LOCAL computer.
    I do not understand the solution of this problem.
    Please please teach a solution.
    ----------------
    In conjunction with this, there is a thing slightly anxious.
    There is similar application (transmission and reception is ShortPacket) that I made as FORM application using WinUSB.
    Though this FORM application moves without a problem with the PC which I upgraded to Windows 10 Pro Anniversary(32,64bit) from Windows 7 Pro(32,64bit), but I  get a report from some customer.
    This FORM application does not work with the PC which they introduced newly. (but It moved with the old PC) And the report says that ShortPacket from a USB device cannot receive.
    For reference, I show the part of the INF file of this below.
    [CoInstallers_AddReg]
    HKR,,CoInstallers32,0x00010000,"WdfCoInstaller01009.dll,WdfCoInstaller","WinUSBCoInstaller2.dll,WinUSBCoInstaller"
    [CoInstallers_CopyFiles]
    WinUSBCoInstaller2.dll
    WdfCoInstaller01009.dll
    We used it without a problem with this INF file for a long time.
    This problem must be fixed immediately, but thinks whether this is related to an upper problem.
    I thank for your having read to here.
    If there is a method of the solution, please please teach me it.

    Sunday, December 4, 2016 10:45 AM

All replies

  • >An exception occurs in 'reader.LoadAsync(bytesToRead)' and stops.

    Which exception? Do you see any message, or stack trace, or something else informative ?

    Please note: in this line: 

    readPipe.ReadOptions |= UsbReadOptions.None;

    You do not actually assign any options to readPipe, because UsbReadOptions.None = 0.

    Maybe you wanted to add AllowPartialReads  , or try:

    readPipe.ReadOptions  = UsbReadOptions.None


    -- pa


    • Edited by Pavel A Sunday, December 4, 2016 1:54 PM
    Sunday, December 4, 2016 1:50 PM
  • Thank you for your reply.
    > Which exception? Do you see any message, or stack trace, or something else?informative ?
    When USB device send the data exceed 7 byte, the debugger stop in folllow.
    App.g.i.cs
    #if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
                UnhandledException += (sender, e) =>
                {
                    if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
                };
    #endif

    > Maybe you wanted to add AllowPartialReads? , or try:
    When I try to use 'AllowPartialReads', its movement was the same as 'None'.

    Sunday, December 4, 2016 3:12 PM
  • Which I wrote last of the question.....

    > There is similar application (transmission and reception is ShortPacket) that I made as FORM application using WinUSB.
    Though this FORM application moves without a problem with the PC which I upgraded to Windows 10 Pro Anniversary(32,64bit) from Windows 7 Pro(32,64bit), but I  get a report from some customer.
    This FORM application does not work with the PC which they introduced newly. (but It moved with the old PC) And the report says that ShortPacket from a USB device cannot receive.

    ..... about this, I report what I understood afterwards.

    This was because the default setting of the USB port was set by BIOS by USB3.0.
    It came to work without a problem when it's changed this in USB 2.0.

    But, about Raspberry Pi 2, the situation does not change.

    Tuesday, December 13, 2016 11:16 AM