libusb help

I am having problem in bulk reading/writing. Pls guide me.

Source Code:
#include
#include
#include

usb_dev_handle *locate(void);

int main (int argc,char **argv)
{
struct usb_dev_handle *handle;
struct usb_device *device;
int send_status;
int open_status;
unsigned char send_data=0xff;
unsigned char receive_data=0;

usb_init();
usb_set_debug(2);
if ((handle = locate())==0)
{
printf("Could not open the device
");
return (-1);
}

open_status = usb_set_configuration(handle, 1);
printf("conf_stat=%d
", open_status);

open_status = usb_detach_kernel_driver_np(handle, 0);
printf("detach_kernel_stat=%d
", open_status);

open_status = usb_claim_interface(handle, 0);
printf("claim_stat=%d
", open_status);

open_status = usb_set_altinterface(handle, 0);
printf("alt_stat=%d
", open_status);

send_status=usb_bulk_write(handle, 2, &send_data, 1, 1500);
printf("TX stat=%d
", send_status);

usb_bulk_read(handle, 1, &receive_data, 1, 1500);
printf("RX stat=%d -> RX char=%d
", send_status,receive_data);

/* Write the data2send bytes to the 7-segs */
/* send_status = usb_control_msg(xsv_handle,0x20,0x09,0x0200,0x0001,send_data,2,500);
printf("TX stat=%d
",send_status);
usleep(10000);
*/
/* Read the bytes that were just sent to the 7-segs */
/*
send_status = usb_control_msg(xsv_handle,0xA0,0x01,0x0100,0x0001,receive_data,2,500);
printf("RX stat=%d data=0x%x,0x%x
",send_status,receive_data[0],receive_data[1]);
usleep(10000);
*/
usb_close(handle);
}

usb_dev_handle *locate(void)
{
unsigned char located = 0;
struct usb_bus *bus;
struct usb_device *dev;
usb_dev_handle *device_handle = 0;

usb_find_busses();
usb_find_devices();

for (bus = usb_busses; bus; bus = bus->next)
{
for (dev = bus->devices; dev; dev = dev->next)
{
if (dev->descriptor.idVendor == 0x0EA0 && dev->descriptor.idProduct == 0x6803)
{
located++;
device_handle = usb_open(dev);
printf("device handle = %d
", device_handle);
if(device_handle != 0)
{
printf("Device Found @ Address %s
", dev->filename);
printf("Vendor ID 0x0%x
",dev->descriptor.idVendor);
printf("Product ID 0x0%x
",dev->descriptor.idProduct);
return (device_handle);
}
else
{
printf("device Handle is zero
");
return (0);
}
}
else printf("** usb device %s found **
", dev->filename);
}
}
return (0);
}



The output:
usb_set_debug: Setting debugging level to 2 (on)
usb_os_find_busses: Skipping non bus directory devices
usb_os_find_busses: Skipping non bus directory drivers
usb_os_find_busses: Found 004
usb_os_find_busses: Found 003
usb_os_find_busses: Found 002
usb_os_find_busses: Found 001
usb_os_find_devices: Found 001 on 004
usb_os_find_devices: Found 002 on 004
usb_os_find_devices: Found 001 on 003
usb_os_find_devices: Found 001 on 002
usb_os_find_devices: Found 001 on 001
** usb device 001 found **
device handle = 134520552
Device Found @ Address 002
Vendor ID 0x0ea0
Product ID 0x06803
USB error: could not set config 1: Invalid argument conf_stat=-22 USB error: could not detach kernel driver from interface 0: Invalid argument detach_kernel_stat=-22 claim_stat=0 alt_stat=0 USB error: error writing to bulk endpoint 2: Connection timed out TX stat=-110 USB error: error reading from bulk endpoint 0x81: Invalid or incomplete multibyte or wide character RX stat=-110 -> RX char=0


/proc/bus/usb/devices gives
T: Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 0.00
S: Product=USB UHCI Root Hub
S: SerialNumber=ff40
C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms
T: Bus=04 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=0ea0 ProdID=6803 Rev= 1.00
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls=08(stor.) Sub=06 Prot=50 Driver=(none)
E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=83(I) Atr=03(Int.) MxPS= 2 Ivl=1ms
T: Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 0.00
S: Product=USB UHCI Root Hub
S: SerialNumber=ff60
C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms
T: Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 0.00
S: Product=USB UHCI Root Hub
S: SerialNumber=ff80
C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms
T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=480 MxCh= 6
B: Alloc= 0/800 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=01 MxPS= 8 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 2.04
S: Manufacturer=Linux 2.4.20-8 ehci-hcd
S: Product=Intel Corp. 82801DB USB EHCI Controller
S: SerialNumber=00:1d.7
C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=256ms




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories