USB Host Raw device pipe transfer

Hi,

I have updated a program from the firmware 4.2 to 4.3. This is a raw device that has 2 endpoints, one to send and one to get data. The problem is that now, with the 4.3 version, when no data are coming from the device, the methods transfer is not returning, and my thread stay there forever.

Where my 4.3 code is not returning :


static RawDevice.Pipe adbInPipe;
static byte[] adbData = new byte[65];

static void myFunction()
{
    int count = 0;
    while (true)
    {
        try
        {
            count = adbInPipe.Transfer(adbData, 0, adbData.Length);   //Where my program is not returning from when no data are coming from the device.
        }
        catch (Exception ex)
        {
            Debug.Print(ex.ToString());
        }
        
        //Do some stuff according to the reading.
    }
}

While in 4.2 it would just return 0, and continue in my code.


static USBH_RawDevice.Pipe adbInPipe;
static byte[] adbData = new byte[65];

static void myFunction()
{
    int count = 0;
    while (true)
    {
        try
        {
            count = adbInPipe.TransferData(adbData, 0, adbData.Length);   //If there is no data sent from the device, the TransferData return 0, and my code continue.
        }
        catch (Exception ex)
        {
            Debug.Print(ex.ToString());
        }
       
          //Do some stuff according to the reading.
    }
}

In both case the methods is in a thread called once the device in connected.

If I try to step-In the transfer methods, the output returns this:

And it keeps printing “Transfer → Transfer → TransferTimeout.get → Transfer → Transfer → Endpoint.get” forever.

Changing the timeout in the pipe object does not seem to have an effect.

If anyone has some advice or idea of what to do, this would be great, because I have no clue what to do now about this. (Apart from sticking with 4.2 firmware.)

@ Tulmandil -

Using a thread to stop it in 4.3, I think

1 Like

@ Tulmandil - There is a bug in the current release where the timeout value is not being respected. As a work around, you may be able to do the following. In place of calling adbInPipe.Transfer, use reflection to call the private instance member “int NativeTransfer(byte[] buffer, int offset, int count, int transferTimeout)”. You can pass 0 for the timeout. This method should return a zero immediately like 4.2 did. We will look into a fix for a coming release.

1 Like

@ John - Thanks for the answer. I’ll try your workaround.

@ John - Using reflection to call the private member is working as in the 4.2. Thanks for the help.

@ Tulmandil - Glad you got it working, we’re happy to help.

1 Like