> -----Original Message-----
> From: m. allan noah
> Sent: 8. december 2006 22:07
> To: Ren? Kjellerup
> Cc: [email protected]
> Subject: Re: [sane-devel] Libusb - reads and writes?
>
> On Fri, 8 Dec 2006, Ren? Kjellerup wrote:
>
> >
> >
> > On Fri, 8 Dec 2006, m. allan noah
> >
> >> On Thu, 7 Dec 2006, Ren? Kjellerup wrote:
> >>
> >>> So the primary question is, which endpoint does one write to, and
> >>> which does one read from?
> >>
> >> the in/out identifiers are written from the perspective of
> the host, not
> > the device. so you read in and write out. just as a check,
> the IN endpoint
> > will > have its high bit set (0x80).
> >>
> > Thanks
> >
> >> it is not unusual to get timeout errors and other
> weirdness on your first
> > command to the device, some fujitsu scanners require you to
> call TEST UNIT
> > READY several times with a really short timeout and ignore
> the errors before
> > they will play.
> >
> > :) well being used to TCP connections, I'd never expected
> USB communication
> > to be so inconsistent.
> >
> > Should I fill the scanner's endpoint buffer before reading?
> Or will a few
> > one byte writes do?
> > Anyone know how Canon's scanners like it? [:)]
>
> haha- oh, you're serious? you have to write a properly formatted
> command before you read. sending single bytes is a great way to
> confuse the scanner.
Indeed I was serious. I was writing a single byte (in range 0x00-0x0f
approx.) to the scanner and I've even tried with 4 random bytes. Then tried
to Read up to the max of that endpoint (either 512 or 1 byte) (for those
inclined see the appended source code)
>
> get a trace on windows using benoit's usbsniffer, and work from that.
>
> post links to the traces on this list if you need some help.
Well I need the help in generating the traces, as the only windows machine I
own is a Windows x64 Pro, and there's no drivers for it.
Vmware doesn't help :( And no I wont setup a multi boot with 2 windowses.
>
> allan
>
> >
> > Best regards
> > Ren? Kjellerup
> > -- as life grows older, I gain experience.
> >
> >>
> >> allan
> >>
> >> --
> >> "so don't tell us it can't be done, putting down what you
> don't know.
> >> money isn't our god, integrity will free our souls" - Max Cavalera
> >
> >
>
> --
> "so don't tell us it can't be done, putting down what you don't know.
> money isn't our god, integrity will free our souls" - Max Cavalera
>
-------------- next part --------------
#include <usb.h>
// gets a pointer to the usb device
struct usb_device* get_device(u_int16_t v, u_int16_t p, struct usb_bus *b);
// the function to handle the communication with the scanner
void device_function(struct usb_dev_handle* dhnd, struct usb_device*,int);
int
main(int argc, char *argv[])
{
struct usb_bus *busses;
struct usb_device *dev;
u_int16_t vend = 0x04a9; // Canon
u_int16_t prod = 0x221b; // CanoScan 4200F
int index = 0;
if(argc > 1) index = atoi(argv[1]);
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
dev = get_device(vend,prod,busses);
if(dev == 0) {
printf("CanoScan 4200F not found\n");
return;
}
device_function(usb_open(dev),dev,index);
return 0;
}
struct usb_device*
get_device(u_int16_t v, u_int16_t p, struct usb_bus *b)
{
struct usb_bus *bus;
struct usb_device *dev;
for(bus = b; bus; bus = bus->next)
{
for(dev = bus->devices; dev; dev = dev->next)
{
if(dev->descriptor.idVendor == v)
if(dev->descriptor.idProduct == p)
return dev;
}
}
return (0);
}
/* this is a mess and I won't bother explaining why it looks as it does.
* Sufficiently to say that trial/error has something to do with it.
*/
void
device_function(struct usb_dev_handle *dhnd, struct usb_device* dev, int idx)
{
struct usb_endpoint_descriptor *endpoints, *endp;
char buf[520], irq;
char *ii;
int i;
bzero(buf,520);
if(dhnd) {
i = usb_set_configuration(dhnd,dev->config->bConfigurationValue);
if(i<0) printf("set config failed\n");
endpoints = dev->config->interface->altsetting->endpoint;
i = usb_claim_interface(dhnd,0);
if(i < 0) { printf("error no: %d\n",i); goto endf; }
i =
usb_set_altinterface(dhnd,dev->config->interface->altsetting->bAlternateSetting);
printf("Interface Claimed\n");
irq = idx;
ii = (char*)&idx;
buf[0] = ii[0];
buf[1] = ii[1];
buf[2] = ii[2];
buf[3] = ii[3];
printf("0x%02x 0x%02x 0x%02x 0x%02x\n",buf[0],buf[1],buf[2],buf[3]);
i = usb_bulk_write(dhnd,1,buf,4,15);
if(i<0){
printf("bulk write failed %d\n",i);
usb_release_interface(dhnd,0); goto endf;
}
bzero(buf,520);
i = usb_interrupt_read(dhnd,3,buf,1,0);
if(i<0) printf("read failed %d\n",i);
usb_release_interface(dhnd,0);
printf("Interface Released\n");
printf("out: '%s'\n",buf);
endf:
usb_close(dhnd);
return;
}
printf("No device found\n");
}
From [email protected] Sat Dec 9 22:26:10 2006
From: [email protected] (Buttay cyril)
Date: Sat Dec 9 22:33:06 2006
Subject: [sane-devel] scanner not detected
In-Reply-To: <20061208232056.323cc02c@inspiron>
References: <[email protected]> <20061208232056.323cc02c@inspiron>
Message-ID: <[email protected]>
Alessandro Zummo wrote:
> On Fri, 08 Dec 2006 21:40:56 +0000
> Buttay cyril <[email protected]> wrote:
>
>>
>>
>> My scanner is an Agfa snapscan e25, but when I run scanimage, it replies
>> "found USB scanner (vendor=0x06b9, product=0x4061) at libusb:001:003",
>> whereas in snapscan.conf, the values for an e25 are "usb 0x06bd 0x2095".
>> Is that normal?
>>
>
> 06b9/4061 is an Alcatel modem... you might want to post
> the results of lsusb -vv
>
You're right, this is my modem!
Also, I tried to disconnect the usb from the scanner, and to replug it.
When I do so, the white light of the scanner starts briefly, and then
shuts down (instead of the usual warm-up cycle where the motor starts).
The scanner is connected to a usb hub, whose led lights up when I
connect the scanner, and then shuts down again (if I remember correctly,
the light stayed on before)
I tried to connect a memory stick, which was recognised OK. My printer
is on the same hub as the scanner and works fine.
Thanks
Cyril
The results of lsusb -vv are (long) :
Bus 004 Device 029: ID 04b4:6560 Cypress Semiconductor Corp. CY7C65640
USB-2.0 "TetraHub"
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 2 TT per port
bMaxPacketSize0 64
idVendor 0x04b4 Cypress Semiconductor Corp.
idProduct 0x6560 CY7C65640 USB-2.0 "TetraHub"
bcdDevice 0.08
iManufacturer 0
iProduct 0
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 1 Single TT
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 12
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 2 TT per port
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 12
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 4
wHubCharacteristic 0x0089
Per-port power switching
Per-port overcurrent protection
TT think time 8 FS bits
Port indicators
bPwrOn2PwrGood 50 * 2 milli seconds
bHubContrCurrent 100 milli Ampere
DeviceRemovable 0x58
PortPwrCtrlMask 0xc0
Hub Port Status:
Port 1: 0000.0101 power connect
Port 2: 0000.0100 power
Port 3: 0000.0100 power
Port 4: 0000.0100 power
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 0
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0001
Self Powered
Bus 004 Device 001: ID 0000:0000
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 1 Single TT
bMaxPacketSize0 64
idVendor 0x0000
idProduct 0x0000
bcdDevice 2.06
iManufacturer 3 Linux 2.6.15-27-386 ehci_hcd
iProduct 2 EHCI Host Controller
iSerial 1 0000:00:10.3
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 25
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0002 1x 2 bytes
bInterval 12
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 6
wHubCharacteristic 0x000a
No power switching (usb 1.0)
Per-port overcurrent protection
TT think time 8 FS bits
bPwrOn2PwrGood 10 * 2 milli seconds
bHubContrCurrent 0 milli Ampere
DeviceRemovable 0x48
PortPwrCtrlMask 0xc0
Hub Port Status:
Port 1: 0000.0503 highspeed power enable connect
Port 2: 0000.0000
Port 3: 0000.0100 power
Port 4: 0000.0100 power
Port 5: 0000.0100 power
Port 6: 0000.0100 power
Device Status: 0x0001
Self Powered
Bus 001 Device 003: ID 06b9:4061 Alcatel Telecom SpeedTouch ISDN or ADSL
Modem
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 255 Vendor Specific Class
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x06b9 Alcatel Telecom
idProduct 0x4061 SpeedTouch ISDN or ADSL Modem
bcdDevice 4.00
iManufacturer 1 THOMSON
iProduct 2 Speed Touch 330
iSerial 3 0090D0C7DC0A
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 147
bNumInterfaces 3
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0010 1x 16 bytes
bInterval 50
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x06 EP 6 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x07 EP 7 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x87 EP 7 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 2
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x06 EP 6 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x07 EP 7 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x87 EP 7 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0280 1x 640 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 3
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x06 EP 6 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x07 EP 7 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x87 EP 7 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x03c0 1x 960 bytes
bInterval 1
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x05 EP 5 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x85 EP 5 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 0
Device Status: 0x0000
(Bus Powered)
Bus 001 Device 001: ID 0000:0000
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0000
idProduct 0x0000
bcdDevice 2.06
iManufacturer 3 Linux 2.6.15-27-386 uhci_hcd
iProduct 2 UHCI Host Controller
iSerial 1 0000:00:10.0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 25
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0002 1x 2 bytes
bInterval 255
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 2
wHubCharacteristic 0x000a
No power switching (usb 1.0)
Per-port overcurrent protection
bPwrOn2PwrGood 1 * 2 milli seconds
bHubContrCurrent 0 milli Ampere
DeviceRemovable 0xc0
PortPwrCtrlMask 0x83
Hub Port Status:
Port 1: 0000.0100 power
Port 2: 0000.0103 power enable connect
Device Status: 0x0003
Self Powered
Remote Wakeup Enabled
Bus 003 Device 001: ID 0000:0000
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0000
idProduct 0x0000
bcdDevice 2.06
iManufacturer 3 Linux 2.6.15-27-386 uhci_hcd
iProduct 2 UHCI Host Controller
iSerial 1 0000:00:10.2
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 25
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0002 1x 2 bytes
bInterval 255
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 2
wHubCharacteristic 0x000a
No power switching (usb 1.0)
Per-port overcurrent protection
bPwrOn2PwrGood 1 * 2 milli seconds
bHubContrCurrent 0 milli Ampere
DeviceRemovable 0x78
PortPwrCtrlMask 0x82
Hub Port Status:
Port 1: 0000.0300 lowspeed power
Port 2: 0000.0100 power
Device Status: 0x0003
Self Powered
Remote Wakeup Enabled
Bus 002 Device 001: ID 0000:0000
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0000
idProduct 0x0000
bcdDevice 2.06
iManufacturer 3 Linux 2.6.15-27-386 uhci_hcd
iProduct 2 UHCI Host Controller
iSerial 1 0000:00:10.1
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 25
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0002 1x 2 bytes
bInterval 255
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 2
wHubCharacteristic 0x000a
No power switching (usb 1.0)
Per-port overcurrent protection
bPwrOn2PwrGood 1 * 2 milli seconds
bHubContrCurrent 0 milli Ampere
DeviceRemovable 0xf0
PortPwrCtrlMask 0x00
Hub Port Status:
Port 1: 0000.0100 power
Port 2: 0000.0100 power
Device Status: 0x0003
Self Powered
Remote Wakeup Enabled