usb.h and libusb.
Posted: Tue Jan 21, 2014 7:17 pm
Hi:
This is part of an application program running on linux. Looking for documentation for usb_control_msg(), shown in the last lines above, I first went to /usr/include/usb.h, that is in the #include's (first lines), and the function was there. Looking for the source, I found /usr/src/linux-3.2.29/drivers/usb/core/message.c, where it is defined but, alas, here it has the arguments in different order and they are 9 instead of . As the author asks for the libusb library, the logical thing was to look in its sources, which I installed, just now, from the O.S. distribution disks. But here there is no usb_control_msg(), nor even the usb.h file!
So, what should the source for usb.h be?
Note: in usb.h there is declared a function usb_control_msg with the same number and order of parameters as in my source.
Code: Select all
#include <usb.h>
#include <stdio.h>
#include <string.h>
unsigned short IDVendor= 0x1384; /*VID must be changed. */
unsigned short IDProduct= 0x8888; /*PID must be changed. */
...........................
int main(int argc, char **argv)
{
usb_dev_handle *d=NULL;
unsigned char buffer[3];
int i, mode, ret;
char string[256];
if(argc <2)
{
printf("give the voltage value.\n");
exit(1);
}
i=floor(atof(argv[1])*51) ;
if(i>255){printf("value must be between 0 and 5V\n"); exit(1);}
mode=0;
usb_init();
ret=usbOpenDevice(&d, IDVendor,IDProduct);
if(ret!=0){printf("usbOpenDevice failed\n"); return 0;}
ret=usb_control_msg(d, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, mode, i, 0, (char *)buffer, sizeof(buffer), 5000);
// printf("buffer %d \n", buffer[0]);
return 0;
}
This is part of an application program running on linux. Looking for documentation for usb_control_msg(), shown in the last lines above, I first went to /usr/include/usb.h, that is in the #include's (first lines), and the function was there. Looking for the source, I found /usr/src/linux-3.2.29/drivers/usb/core/message.c, where it is defined but, alas, here it has the arguments in different order and they are 9 instead of . As the author asks for the libusb library, the logical thing was to look in its sources, which I installed, just now, from the O.S. distribution disks. But here there is no usb_control_msg(), nor even the usb.h file!
So, what should the source for usb.h be?
Note: in usb.h there is declared a function usb_control_msg with the same number and order of parameters as in my source.