1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include <stdio.h>
#include "/usr/include/usb.h"
#include <stdlib.h>
#define EXIT_SUCCESS 0
#define MY_VENDOR_ID 0x066f
#define MY_PRODUCT_ID 0x8000
struct usb_bus *bus;
struct usb_device *dev, *my_dev = NULL;
int main (int argc,char **argv)
{
FILE* fichier = NULL;
int receive = 0;
int len = 64;
char buffer[len];
struct usb_dev_handle *device_handle = 0;
usb_init();// Initiaser libusb
usb_find_busses();//Trouver tous les bus
usb_find_devices();//Trouver tous les peripheriques sur tous les bus find_busses
//sses = usb_get_busses();int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout);
for (bus = usb_busses; bus; bus = bus->next){
for (dev = bus->devices; dev; dev = dev->next)
{
{
printf("bus : %s Device %s \n id Vendor: %x | id Product : %x \n", bus->dirname,dev->filename ,dev->descriptor.idVendor,dev->descriptor.idProduct);
}
if ((dev->descriptor.idVendor == MY_VENDOR_ID) && (dev->descriptor.idProduct == MY_PRODUCT_ID))
my_dev = dev;
/*{
printf("my_dev %x idV et %x idP", MY_VENDOR_ID, MY_PRODUCT_ID);
}*/
}
}
if (my_dev == NULL)
{
{
printf("aucun périphérique ne cerrespond\n");
return 0;
}
device_handle = usb_open(my_dev);
if (device_handle == NULL)
{
{
printf("usb_open : %s\n", usb_strerror());
return 1;
}
fichier = fopen("test", "wb+");
if (fichier == NULL)
while
(receive = usb_bulk_read(device_handle , 1, buffer, sizeof(buffer), 500) > 0)
{
fputs(buffer, fichier);
fclose(fichier);
}
printf("RX stat=%d -> RX char=%d\n", receive, len);
//nt usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout);
//int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout);
}
usb_close(device_handle);
}
return(0);
} |
Partager