On Tue, 24 Oct 2006, Alex Litvin wrote:

> I've succeeded with usb_bulk_write() but can't utilize
> usb_bulk_read(). It returns an error [i]open error 11 Resource
> temporarily unavailable[/i].
> 
> Here is the output of
> [i]cat /prog/bus/usb/devices[/i]:
> [code]T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  4 Spd=12  MxCh= 0
> D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=16 #Cfgs=  1
> P:  Vendor=1664 ProdID=d100 Rev= 2.00
> S:  Manufacturer=Argox Informations
> S:  Product=CRD -10
> S:  SerialNumber=60227075
> C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
> I:  If#= 0 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=(none)
> E:  Ad=82(I) Atr=03(Int.) MxPS=  64 Ivl=1ms
> E:  Ad=02(O) Atr=03(Int.) MxPS=  64 Ivl=1ms[/code]
> 
> The source code that utilizes the mentioned functions:
> [code]
> #include <usbpp.h>
> #include <stdio.h>
> #include <iostream.h>
> #include <errno.h>
> #define VENDOR_ARGOX 0x1664
> #define DEVICE_PT 0xd100
> int main(void)
> {
> struct usb_bus *bus;
> struct usb_device *dev;
> int n,m,ret;
> usb_init();
> char string[256];
> n=usb_find_busses();
> m=usb_find_devices();
> usb_dev_handle *udev;
> for (bus = usb_busses; bus; bus = bus->next) {
> for (dev = bus->devices; dev; dev = dev->next) {
> if (dev->descriptor.idVendor==VENDOR_ARGOX)
> if (dev->descriptor.idProduct==DEVICE_PT){
> udev = usb_open(dev);
> if (udev) {
> printf("found argox_PT dev-%s on bus-%s\n",dev->filename,bus->dirname);
> usb_detach_kernel_driver_np(udev, 0);
> usb_set_configuration(udev, 1);
> if (dev->descriptor.iManufacturer) {
> usb_get_string_simple(udev, dev->descriptor.iManufacturer, string,
> sizeof(string));
> if (ret > 0)
> printf("- Manufacturer : %s\n", string);
> else
> printf("- Unable to fetch manufacturer string\n");
> }
> if (dev->descriptor.iProduct) {
> ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string,
> sizeof(string));
> if (ret > 0)
> printf("- Product : %s\n", string);
> else
> printf("- Unable to fetch product string\n");
> }
> if (dev->descriptor.iSerialNumber) {
> ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber,
> string, sizeof(string));
> if (ret > 0)
> printf("- Serial Number: %s\n", string);
> else
> printf("- Unable to fetch serial number string\n");
> }
> ret = usb_claim_interface(udev,0);
> if (ret>=0) printf("device claimed!\n");
> else printf("open error %d %s\n", errno, strerror(errno));
> unsigned int 
> WRITE=dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress;
> unsigned int 
> READ=dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress;
> char * buff = new char[10];
> delete [] buff;
> char 
> bufferout[]={0x1b,0x02,0x00,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x02,0x1b,0x3f,0x00};
> char bufferin[256];
> int 
> sizein=dev->config[0].interface[0].altsetting[0].endpoint[1].wMaxPacketSize;
> int 
> sizeout=dev->config[0].interface[0].altsetting[0].endpoint[0].wMaxPacketSize;
> int pts=dev->config[0].interface[0].altsetting[0].endpoint[0].bInterval;
> int i;
> printf("WRITE TO %02xh READ FROM %02xh\n SIZEIN %d SIZEOUT %d\n PTS
> %d\n",WRITE,READ,sizein,sizeout,pts);
> for (i=0;i<14;i++){
> *(buff+i)=bufferout[i];
> ret=usb_interrupt_write(udev, WRITE, buff, 1, 100);
> if (ret>=0) printf("buf=%02x, transfered %d bytes \n",*buff+i,ret);
> else printf("open error %d %s\n", errno, strerror(errno));
> }
> for (i=0;i<14;i++){
> ret=usb_interrupt_read(udev, READ, buff, 1, 100);
> if (ret>=0) {printf("buf=%02x, read %d bytes \n",*buff+i,ret);
> bufferin[i]=*buff;}
> else printf("open error %d %s\n", errno, strerror(errno));
> }
> for(i=0;i<14;i++) printf("read:%02x \n",bufferin[i]);
> usb_release_interface(udev,0);
> usb_close (udev);
> }}
> else continue;
> }}
> return 0;
> }
> [/code]
> 
> Got no ideas of what am I doing wrong. Anyone faced such a problem,
> please give a hint.

There are several things you're doing wrong.  The first and most obvious 
is that you're not indenting the code, so it is almost unreadable.

The second problem is that you have three printf statements that say all
"open error", and none of them goes with an open() call!  One goes with
usb_claim_interface(), one with usb_interrupt_write(), and one with
usb_interrupt_read().  So we can't even tell which routine returned the
error.

The third problem is that you call usb_detach_kernel_driver_np() before 
calling usb_set_configuration().  I don't know why you want to call 
usb_set_configuration() at all, but if you do there's no point detaching 
the driver beforehand -- you need to detach it afterward, since the 
set_config call will rebind the driver.

Alan Stern


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to