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 77 78 79 80 81 82
| #include <stdio.h>
#include <usb.h>
#include <string.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
const int IDPRODUCT = 0x0028;
const int IDVENDOR = 0x0590;
struct usb_bus *bus;
struct usb_device *appareil;
void driver_init(void) {
usb_init();
usb_find_busses();
usb_find_devices();
}
struct usb_device *usb_find_device(int idV, int idP) {
printf("\n -- Recherche de l'USB (%04X|%04X) -- \n", idV, idP);
for (bus = usb_busses; bus; bus = bus->next) {
for (appareil = bus->devices; appareil; appareil = appareil->next) {
if ((appareil->descriptor.idVendor == idV) && (appareil->descriptor.idProduct ==idP )) {
printf(" * Trouver\n");
return(appareil);
}
}
}
printf(" ! Absent\n");
return(0);
}
void resetDevice(usb_dev_handle *hdl) {
printf("\n -- Reset appareil -- \n");
if (usb_reset(hdl)<0) printf(" ! Echec du reset !\n"); else printf(" * Fait\n");
}
void initDevice(usb_dev_handle *hdl){
int ret;
char donnee[8];
memset(&donnee[0], 0, sizeof(donnee));
donnee[0] = 0x01;
donnee[1] = 0x01;
ret = usb_interrupt_write(hdl,0x02,donnee,sizeof(donnee),8);
printf("\n -- Init appareil -- \n");
printf(" * ret %d \n ",ret);
}
int main (void) {
char str[100];
// ************* Initialise le port usb *************
driver_init();
// ************* Recherche de l'apparei *************
struct usb_device *tensiometre = usb_find_device(IDVENDOR, IDPRODUCT);
if (tensiometre ==0) { // si on ne l'a pas trouvé ...
printf(" ! Tensiometre mal branche !\n");
return 0;
}
// ************* Ouverture de l'appareil *************
printf("\n -- Ouverture du port USB (Vendor, Product) = (0x%04X, 0x%04X) --\n", tensiometre->descriptor.idVendor, tensiometre->descriptor.idProduct);
usb_dev_handle *tensiometreHandle = usb_open(tensiometre);
if (!tensiometreHandle) {
printf(" ! Echec de l'ouveture !\n");
return 0;
} else printf(" * Appareil ouvert ");
usb_get_string_simple(tensiometreHandle, 1, &str[0], 50) >=0 ? printf("\n * %s", str) :printf("\n ! Echec de la recuperation du NOM !\n");
// ************* Opérations sur l'appareil *************
resetDevice(tensiometreHandle);
initDevice(tensiometreHandle);
} |
Partager