[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libusb-devel
Subject:    [libusb] libusb_bulk_transfer returns 0 but data length is 0
From:       Abhishek Singh <aksonlyaks () gmail ! com>
Date:       2019-01-29 19:23:36
Message-ID: CAP078htzb_A4dwA81bCL2VzyU0hdh1aYNbWWPJpA-GfJQwa2LA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

I'm trying to communicate with my CDC/ACM usb device with WINUSB driver.
My function is as follows:
void *usb_read_thread(void* arg)
{
    int size = 100, actual_length = 0, i = 0;
    unsigned char data[100];

    _log_error(TAG, "usb read thread begin\n");
    while(indicate_readthread_exit == 0)
    {

        /* To receive characters from the device initiate a bulk_transfer
to the
         * Endpoint with address ep_in_addr.
         */
        int rc = libusb_bulk_transfer(devh, ep_in_addr, data, size,
&actual_length,
                                      1000);
        if (rc == LIBUSB_ERROR_TIMEOUT) {
            _log_error(TAG, "timeout (%d)\n", actual_length);
            //goto goout;
        } else if (rc < 0) {
            _log_error(TAG, "Error while waiting for char\n");
            goto goout;
        }
        else
        {
            _log_error(TAG, "USB read:%d len:%d\n", rc, actual_length);
            for(i = 0; i < actual_length; i++)
                _log_error(TAG, "%x ", data[i]);
            Tserial_cb->on_data_rx_cb((char *)data, actual_length);
        }
    }
goout:
    _log_error(TAG, "usb read thread end\n");
    return NULL;
}

Here, libusb_bulk_transfer returns continuously 0 with 0 length packet.
What could be the issue? Even with 0 timeout it does not wait it returns
immediately.

Kindly suggest what is wrong in the above portion of code.

Thanks and Regards
Abhishek



-- 
--------------------------------------------------------
Regards
Abhishek Singh

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><div>Hi,</div><div><br></div><div>I&#39;m trying to \
communicate with my CDC/ACM usb device with WINUSB driver. <br></div><div>My function \
is as follows:</div><div>void *usb_read_thread(void* arg)<br>{<br>       int size = \
100, actual_length = 0, i = 0;<br>       unsigned char data[100];<br><br>       \
_log_error(TAG, &quot;usb read thread begin\n&quot;);<br>       \
while(indicate_readthread_exit == 0)<br>       {<br><br>              /* To receive \
characters from the device initiate a bulk_transfer to the<br>                * \
Endpoint with address ep_in_addr.<br>                */<br>              int rc = \
libusb_bulk_transfer(devh, ep_in_addr, data, size, &amp;actual_length,<br>            \
1000);<br>              if (rc == LIBUSB_ERROR_TIMEOUT) {<br>                     \
_log_error(TAG, &quot;timeout (%d)\n&quot;, actual_length);<br>                     \
//goto goout;<br>              } else if (rc &lt; 0) {<br>                     \
_log_error(TAG, &quot;Error while waiting for char\n&quot;);<br>                     \
goto goout;<br>              }<br>              else<br>              {<br>           \
_log_error(TAG, &quot;USB read:%d len:%d\n&quot;, rc, actual_length);<br>             \
for(i = 0; i &lt; actual_length; i++)<br>                            _log_error(TAG, \
&quot;%x &quot;, data[i]);<br>                     Tserial_cb-&gt;on_data_rx_cb((char \
*)data, actual_length);<br>              }<br>       }<br>goout:<br>       \
_log_error(TAG, &quot;usb read thread end\n&quot;);<br>       return \
NULL;<br>}</div><div><br></div><div>Here, libusb_bulk_transfer returns continuously 0 \
with 0 length packet. What could be the issue? Even with 0 timeout it does not wait \
it returns immediately.</div><div><br></div><div>Kindly suggest what is wrong in the \
above portion of code.</div><div><br></div><div>Thanks and \
Regards<br></div><div>Abhishek<br></div><div><br></div><div><br></div><div><br>-- \
<br><div dir="ltr" class="gmail_signature"><div \
dir="ltr"><div>--------------------------------------------------------<br>Regards<br>Abhishek \
Singh<br></div></div></div></div></div></div>





_______________________________________________
libusb-devel mailing list
libusb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic