| 
      
      
      From: <li...@st...> - 2006-07-24 15:55:44
       | 
| Hello everybody,
after two days I'm quite happy with the integration of a usb printer into my 
application. I can write to the printer but not read from. I'v to say that I'm 
new to USB. The error happens when i call usb_bulk_read(...)
Version:
DLL version:	0.1.10.1
Driver version:	0.1.10.1
Following informations ...
1) Application code
2) Stdout of application
3) Output of TestLibUsb-win.exe
4) Output of Dbgview
I hope anybody can give me a hint
1) -- code of my application
     struct usb_bus *bus;
      int c, i, a;
      /* ... */
      for (bus = busses; bus; bus = bus->next) {
       struct usb_device *dev;
       for (dev = bus->devices; dev; dev = dev->next) {
        /* Check if this device is a printer */
        if (dev->descriptor.bDeviceClass == 7)
        {
         /* Open the device, claim the interface and do your processing */
         cout << "+++++" << endl;
        }
        /* Loop through all of the configurations */
        for (c = 0; c < dev->descriptor.bNumConfigurations; c++)
        {
         /* Loop through all of the interfaces */
         for (i = 0; i < dev->config[c].bNumInterfaces; i++)
         {
          /* Loop through all of the alternate settings */
          for (a = 0; a < dev->config[c].interface[i].num_altsetting; a++)
          {
           /* Check if this interface is a printer */
           if (dev->config[c].interface[i].altsetting[a].bInterfaceClass == 7)
           {
            /* Open the device, set the alternate setting, claim the interface 
and do your processing */
            usb_set_debug(255);
            usb_dev_handle* aH;
            void *context0 = NULL;
            int aRc = 0;
            aH = usb_open(dev);
            aRc = usb_set_configuration(aH, 1);
            if (usb_claim_interface(aH, 0))
            {
             cout << "Error usb_claim_interface" << endl;
             return;
            }
            int aNumBytes = 0;
            char aBuf[64*20+11];
            int aSz = sizeof(aBuf);
            memset(aBuf, 0, aSz );
            SetLastError(0);
            // ---- Write ----
            aNumBytes = usb_bulk_write(aH, 0x06, "MI\r", 3, 1000);
            if (aNumBytes < 0) {
            } else {
             cout << aNumBytes << " Bytes written" << endl;
            }
            // --- Read ---
           SetLastError(0);
           aNumBytes = usb_bulk_read(aH, 0x85, aBuf, aSz, 1000);
           if (aNumBytes < 0) {
            cout << "Error usb_bulk_read: " << aNumBytes << endl;
            DWORD aErr = GetLastError();
            printf("%s (%d)\n", usb_strerror(), aErr);
           }
           aRc = usb_release_interface(aH, 0);
           aRc = usb_reset(aH);
           aRc = usb_close(aH);
           cout << "----- Sucess -----" << endl
           }
          }
         }
        }
       }
      }
2) --- stdout
found 1 busses
usb_set_debug: Setting debugging level to 255 (on)
3 Bytes written
LIBUSB_DLL error: usb_reap_async: timeout error
Error usb_bulk_read: -116
usb_reap_async: timeout error (2)
----- Sucess -----
3) --- what TestLibUsb-win.exe reports
bus-0/\\.\libusb0-0001--0x0a5f-0x4e00     0A5F/4E00
- Manufacturer : Eltron
- Product      : P330i
- Serial Number: P330009314
   wTotalLength:         32
   bNumInterfaces:       1
   bConfigurationValue:  1
   iConfiguration:       86
   bmAttributes:         c0h
   MaxPower:             0
     bInterfaceNumber:   0
     bAlternateSetting:  0
     bNumEndpoints:      2
     bInterfaceClass:    7
     bInterfaceSubClass: 1
     bInterfaceProtocol: 2
     iInterface:         132
       bEndpointAddress: 85h
       bmAttributes:     02h
       wMaxPacketSize:   64
       bInterval:        0
       bRefresh:         0
       bSynchAddress:    0
       bEndpointAddress: 06h
       bmAttributes:     02h
       wMaxPacketSize:   64
       bInterval:        0
       bRefresh:         0
       bSynchAddress:    0
4) ---- And finally output of Dbgview
LIBUSB-DRIVER - release_interface(): releasing all interfaces
LIBUSB-DRIVER - set_configuration(): configuration 1
LIBUSB-DRIVER - set_configuration(): timeout 5000
LIBUSB-DRIVER - get_descriptor(): buffer size 18
LIBUSB-DRIVER - get_descriptor(): type 0001
LIBUSB-DRIVER - get_descriptor(): index 0000
LIBUSB-DRIVER - get_descriptor(): language id 0000
LIBUSB-DRIVER - get_descriptor(): timeout 5000
LIBUSB-DRIVER - get_descriptor(): buffer size 9
LIBUSB-DRIVER - get_descriptor(): type 0002
LIBUSB-DRIVER - get_descriptor(): index 0000
LIBUSB-DRIVER - get_descriptor(): language id 0000
LIBUSB-DRIVER - get_descriptor(): timeout 5000
LIBUSB-DRIVER - get_descriptor(): buffer size 32
LIBUSB-DRIVER - get_descriptor(): type 0002
LIBUSB-DRIVER - get_descriptor(): index 0000
LIBUSB-DRIVER - get_descriptor(): language id 0000
LIBUSB-DRIVER - get_descriptor(): timeout 5000
LIBUSB-DRIVER - set_configuration(): interface 0 found
LIBUSB-DRIVER - update_pipe_info(): interface 0
LIBUSB-DRIVER - update_pipe_info(): endpoint address 0x85
LIBUSB-DRIVER - update_pipe_info(): endpoint address 0x06
LIBUSB-DRIVER - claim_interface(): interface 0
LIBUSB-DRIVER - transfer(): bulk or interrupt transfer
LIBUSB-DRIVER - transfer(): direction out
LIBUSB-DRIVER - transfer(): endpoint 0x06
LIBUSB-DRIVER - transfer(): size 3
LIBUSB-DRIVER - transfer_complete(): 3 bytes transmitted
LIBUSB-DRIVER - transfer(): bulk or interrupt transfer
LIBUSB-DRIVER - transfer(): direction in
LIBUSB-DRIVER - transfer(): endpoint 0x85
LIBUSB-DRIVER - transfer(): size 1291
LIBUSB-DRIVER - transfer_cancel(): timeout error
[2772] LIBUSB_DLL error: usb_reap_async: timeout error
LIBUSB-DRIVER - release_interface(): interface 0
LIBUSB-DRIVER - reset_device()
Regards
Alexander
 |