Note that there are some explanatory texts on larger screens.

plurals
  1. POlibusb data output
    primarykey
    data
    text
    <p>I am trying to output a data by using <code>libusb_interrupt_transfer</code>, the function returns <code>0</code>, however, I cannot see any data transfer output from Wireshark (on the usb sniff mode) and the device does not respond the data that is supposed to be output. Does the return value <code>0</code> mean that data is sent out from the usb port? if it is so, do I use <code>libusb_interrupt_transfer</code> function wrong on my code?</p> <p>here is my code (I run the code on ubuntu 12.10 - Linux ubuntu 3.5.0-21-generic #32-Ubuntu SMP Tue Dec 11 18:52:46 UTC 2012 i686 i686 i686 GNU/Linux)</p> <pre><code>#include &lt;stdio.h&gt; //printf, etc. #include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; #include &lt;libusb.h&gt; //libusb functions #include &lt;inttypes.h&gt; //unit16t #include &lt;unistd.h&gt; //sleep function #include &lt;stdlib.h&gt; //exit() const uint16_t VENDOR = 6069; /* = 0x17b5 */ const uint16_t PRODUCT = 32; /* = 0x0020 */ const int CONFIGURATION_VALUE = 1; int msgsend(unsigned char data[64]) { libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices libusb_context *ctx = NULL; //a libusb session int r; //for return values ssize_t cnt; //holding number of devices in list r = libusb_init(&amp;ctx); //initialize a library session if (r &lt; 0){ exit(1);} libusb_set_debug(ctx, 3);//set verbosity level to 3 cnt = libusb_get_device_list(ctx, &amp;devs); if (cnt &lt; 0) return (int) cnt; libusb_device_handle *handle; handle = libusb_open_device_with_vid_pid(ctx, VENDOR, PRODUCT); if (handle==NULL) { fprintf(stderr, "No logging system found.\n"); libusb_free_device_list(devs, 1); libusb_exit(NULL); exit(1); } libusb_device *device = libusb_get_device(handle); struct libusb_config_descriptor *config = NULL; int err = libusb_get_config_descriptor_by_value(device, CONFIGURATION_VALUE, &amp;config); if (err != LIBUSB_SUCCESS){ printf("libusb_get_config_descriptor_by_value error\n"); exit(1); } if(config-&gt;bNumInterfaces == 1){ if(config-&gt;interface[0].num_altsetting ==1){ if(config-&gt;interface[0].altsetting[0].bNumEndpoints == 2) { libusb_free_config_descriptor(config); err = libusb_kernel_driver_active(handle, 0); if (err &gt;= LIBUSB_SUCCESS) { if (err == 1) { printf("Kernel driver is active, trying to detach\n"); err = libusb_detach_kernel_driver(handle, 0); if (err != LIBUSB_SUCCESS) { printf("Error detaching interface from kernel: libusb_error_string(err)\n"); } } err = libusb_set_configuration(handle, CONFIGURATION_VALUE); if (err == LIBUSB_SUCCESS) { err = libusb_claim_interface(handle, 0); if (err == LIBUSB_SUCCESS) { err = libusb_set_interface_alt_setting(handle, 0, 0); if (err == LIBUSB_SUCCESS) { unsigned char ENDPOINT_OUTPUT = 0x02; unsigned char ENDPOINT_INPUT = 0x81; int actual_length; int return_value = 0; return_value = libusb_interrupt_transfer(handle, ENDPOINT_OUTPUT, data, sizeof(data), &amp;actual_length, 0); if (return_value == 0){ printf("msg was sent successfully! return_value=%d\n",return_value); }else { printf("return_value=%d, something went wrong",return_value); perror( "libusb_submit_transfer\n" ); } } }else{ printf("cannot claim the interface\n"); exit(1); } } } } } } libusb_free_device_list(devs, 1); //free the list, unref the devices in it r = libusb_release_interface(handle, 0); libusb_close(handle); //close the device we opened libusb_exit(ctx);//needs to be called to end the return 0; } int main(){ unsigned char data[64]={0x12, 0x01,0x00,0x03,0x00,0x00,0xFF,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, unsigned char data2[64]={0x12, 0x02,0x00,0x03,0x00,0x00,0xFF,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned int seqnum = 0x01; while(1){ data[1] = seqnum; printf("max light is set\n"); msgsend(data); if(seqnum == 0xff){ seqnum = 0; }else{ seqnum++; } sleep(2); data2[1] = seqnum; printf("min light is set\n"); msgsend(data2); if(seqnum == 0xff){ seqnum = 0; }else{ seqnum++; } sleep(2); } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload