|
From: pauldamool <pau...@gm...> - 2011-04-14 08:55:16
|
Hi !
I am trying to communicate with an usb device (NI GPIB-USB-B) to get some
physical measurements...
I find the device, but the function usb_bulk_write returns the following
error :
error submitting URB: No such file or directory
I am probably doing something wrong, and I spent lots of time to find my
mistake... Any help pointing out my error would be appreciated.
#################################################"
#include
#include
#include
#include
#include
/*CONSTANTS*/
#define VENDOR_ID 0x3923
#define PRODUCT_ID 0x702B
#define EP_IN 0x82
#define EP_OUT 0x2
#define BULK_TIMEOUT 1000
//struct usb_dev_handle *usb_handle = NULL;
int verbose_mode = 0;
static struct usb_device *device_search(void)
{
struct usb_bus *usb_bus;
struct usb_device *dev;
usb_init();
usb_find_busses();
usb_find_devices();
for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) {
for (dev = usb_bus->devices; dev; dev = dev->next) {
if ((dev->descriptor.idVendor == VENDOR_ID) && (dev->descriptor.idProduct
== PRODUCT_ID))
return dev;
}
}
return NULL;
}
int connectGPIB(){
struct usb_device *usb_dev;
usb_dev = device_search();
int returnValue;
if(usb_dev == NULL){
fprintf(stderr, "Device not found\n");
return -1;
}
usb_handle = usb_open(usb_dev);
if(usb_handle == NULL){
fprintf(stderr, "Cannot connect the device\n");
return -1;
}
if (usb_handle) {
returnValue = usb_set_configuration(usb_handle, 1);
if (returnValue < 0) { // Linux only
returnValue = usb_detach_kernel_driver_np(usb_handle,0);
if (returnValue < 0) {
fprintf(stderr, "Detach_kernel failed.\n");
//return -1;
}
returnValue = usb_set_configuration(usb_handle, 1);
if (returnValue < 0) {
fprintf(stderr, "Set_configuration failed.\n");
return -1;
}
}
returnValue = usb_claim_interface(usb_handle, 0);
if (returnValue < 0) {
fprintf(stderr, "Claim_interface failed.\n");
return -1;
}
}
/*GPIB connection : OK*/
return 1;
}
void disconnectGPIB(){
if(usb_handle != NULL){
usb_resetep(usb_handle, EP_IN);
usb_release_interface(usb_handle, 0);
usb_close(usb_handle);
}
}
/***********************************************/
// MAIN
/***********************************************/
int main(void){
int i;
int returnValue = connectGPIB();
if(returnValue < 0){
fprintf(stderr, "Connexion : failed\n");
return -1;
}
else{printf("Connexion : succeeded\n");}
char dataInit[72] = "/0x09/0x1A/0x00/0x03/0x10/0x00/0x01/0x33";
for(i=0;i<2;i++){
returnValue = usb_bulk_write(usb_handle, EP_OUT , dataInit, 8,
BULK_TIMEOUT);
}
if(returnValue < 0){
fprintf(stderr, "%s\n", usb_strerror());
}
disconnectGPIB();
return 1;
}
/***********************************************/
// END MAIN
/***********************************************/
--
View this message in context: http://libusb.6.n5.nabble.com/error-submitting-URB-No-such-file-or-directory-tp4302480p4302480.html
Sent from the LibUSB Dev mailing list archive at Nabble.com.
|