Go to the source code of this file.
Defines | |
| #define | HAVE_SANEI_USB_SET_TIMEOUT |
| Check if sanei_usb_set_timeout() is available. | |
Device and/or interface class codes | |
USB descriptor types | |
Descriptor sizes per descriptor type | |
Endpoint descriptors | |
Standard requests | |
USB types | |
USB recipients | |
USB Masks | |
USB directions | |
Functions | |
| void | sanei_usb_init (void) |
| Initialize sanei_usb. | |
| SANE_Status | sanei_usb_get_vendor_product_byname (SANE_String_Const devname, SANE_Word *vendor, SANE_Word *product) |
| Get the vendor and product ids by device name. | |
| SANE_Status | sanei_usb_get_vendor_product (SANE_Int dn, SANE_Word *vendor, SANE_Word *product) |
| Get the vendor and product ids. | |
| SANE_Status | sanei_usb_find_devices (SANE_Int vendor, SANE_Int product, SANE_Status(*attach)(SANE_String_Const devname)) |
| Find devices that match given vendor and product ids. | |
| SANE_Status | sanei_usb_open (SANE_String_Const devname, SANE_Int *dn) |
| Open a USB device. | |
| void | sanei_usb_close (SANE_Int dn) |
| Close a USB device. | |
| void | sanei_usb_set_timeout (SANE_Int timeout) |
| Set the libusb timeout for bulk and interrupt reads. | |
| SANE_Status | sanei_usb_read_bulk (SANE_Int dn, SANE_Byte *buffer, size_t *size) |
| Initiate a bulk transfer read. | |
| SANE_Status | sanei_usb_write_bulk (SANE_Int dn, const SANE_Byte *buffer, size_t *size) |
| Initiate a bulk transfer write. | |
| SANE_Status | sanei_usb_control_msg (SANE_Int dn, SANE_Int rtype, SANE_Int req, SANE_Int value, SANE_Int index, SANE_Int len, SANE_Byte *data) |
| Send/receive a control message to/from a USB device. | |
| SANE_Status | sanei_usb_read_int (SANE_Int dn, SANE_Byte *buffer, size_t *size) |
| Initiate a interrupt transfer read. | |
| void | sanei_usb_attach_matching_devices (const char *name, SANE_Status(*attach)(const char *dev)) |
| Expand device name patterns into a list of devices. | |
| SANE_Status | sanei_usb_set_configuration (SANE_Int dn, SANE_Int configuration) |
| Initiate set configuration. | |
| SANE_Status | sanei_usb_claim_interface (SANE_Int dn, SANE_Int interface_number) |
| Initiate claim interface. | |
| SANE_Status | sanei_usb_release_interface (SANE_Int dn, SANE_Int interface_number) |
| Initiate release interface. | |
| SANE_Status | sanei_usb_set_altinterface (SANE_Int dn, SANE_Int alternate) |
| Initiate a set altinterface. | |
| SANE_Status | sanei_usb_get_descriptor (SANE_Int dn, struct sanei_usb_dev_descriptor *desc) |
| Get some information from the device descriptor. | |
Currently, two access methods to USB devices are provided:
A general remark: Do not mix sanei_usb functions with "normal" file-related libc functions like open() or close. The device numbers used in sanei_usb are not file descriptors.
| void sanei_usb_init | ( | void | ) |
Initialize sanei_usb.
Call this before any other sanei_usb function.
| SANE_Status sanei_usb_get_vendor_product_byname | ( | SANE_String_Const | devname, | |
| SANE_Word * | vendor, | |||
| SANE_Word * | product | |||
| ) |
Get the vendor and product ids by device name.
| devname | ||
| vendor | vendor id | |
| product | product id |
| SANE_Status sanei_usb_get_vendor_product | ( | SANE_Int | dn, | |
| SANE_Word * | vendor, | |||
| SANE_Word * | product | |||
| ) |
Get the vendor and product ids.
Currently, only libusb devices and scanners supported by the Linux USB scanner module can be found. For the latter method, the Linux version must be 2.4.8 or higher.
| dn | device number of an already sanei_usb_opened device | |
| vendor | vendor id | |
| product | product id |
| SANE_Status sanei_usb_find_devices | ( | SANE_Int | vendor, | |
| SANE_Int | product, | |||
| SANE_Status(*)(SANE_String_Const devname) | attach | |||
| ) |
Find devices that match given vendor and product ids.
For limitations, see function sanei_usb_get_vendor_product(). The function attach is called for every device which has been found.
| vendor | vendor id | |
| product | product id | |
| attach | attach function |
| SANE_Status sanei_usb_open | ( | SANE_String_Const | devname, | |
| SANE_Int * | dn | |||
| ) |
Open a USB device.
The device is opened by its name devname and the device number is returned in dn on success.
Device names can be either device file names for direct access over kernel drivers (like /dev/usb/scanner) or libusb names. The libusb format looks like this: "libusb:bus-id:device-id". Bus-id and device-id are platform-dependent. An example could look like this: "libusb:001:002" (Linux).
| devname | name of the device to open | |
| dn | device number |
| void sanei_usb_close | ( | SANE_Int | dn | ) |
Close a USB device.
| dn | device number |
| void sanei_usb_set_timeout | ( | SANE_Int | timeout | ) |
Set the libusb timeout for bulk and interrupt reads.
| timeout | the new timeout in ms |
| SANE_Status sanei_usb_read_bulk | ( | SANE_Int | dn, | |
| SANE_Byte * | buffer, | |||
| size_t * | size | |||
| ) |
Initiate a bulk transfer read.
Read up to size bytes from the device to buffer. After the read, size contains the number of bytes actually read.
| dn | device number | |
| buffer | buffer to store read data in | |
| size | size of the data |
| SANE_Status sanei_usb_write_bulk | ( | SANE_Int | dn, | |
| const SANE_Byte * | buffer, | |||
| size_t * | size | |||
| ) |
Initiate a bulk transfer write.
Write up to size bytes from buffer to the device. After the write size contains the number of bytes actually written.
| dn | device number | |
| buffer | buffer to write to device | |
| size | size of the data |
| SANE_Status sanei_usb_control_msg | ( | SANE_Int | dn, | |
| SANE_Int | rtype, | |||
| SANE_Int | req, | |||
| SANE_Int | value, | |||
| SANE_Int | index, | |||
| SANE_Int | len, | |||
| SANE_Byte * | data | |||
| ) |
Send/receive a control message to/from a USB device.
This function is only supported for libusb devices and kernel acces with Linux 2.4.13 and newer. For a detailed explanation of the parameters, have a look at the USB specification at the www.usb.org developers information page.
| dn | device number | |
| rtype | specifies the characteristics of the request (e.g. data direction) | |
| req | actual request | |
| value | parameter specific to the request | |
| index | parameter specific to the request (often used to select endpoint) | |
| len | length of data to send/receive | |
| data | buffer to send/receive data |
| SANE_Status sanei_usb_read_int | ( | SANE_Int | dn, | |
| SANE_Byte * | buffer, | |||
| size_t * | size | |||
| ) |
Initiate a interrupt transfer read.
Read up to size bytes from the interrupt endpoint from the device to buffer. After the read, size contains the number of bytes actually read.
| dn | device number | |
| buffer | buffer to store read data in | |
| size | size of the data |
| void sanei_usb_attach_matching_devices | ( | const char * | name, | |
| SANE_Status(*)(const char *dev) | attach | |||
| ) |
Expand device name patterns into a list of devices.
Apart from a normal device name (such as /dev/usb/scanner0 or libusb:002:003), this function currently supports USB device specifications of the form:
usb VENDOR PRODUCT
VENDOR and PRODUCT are non-negative integer numbers in decimal or hexadecimal format. A similar function for SCSI devices can be found in include/sane/config.h.
| name | device name pattern | |
| attach | attach function |
| SANE_Status sanei_usb_set_configuration | ( | SANE_Int | dn, | |
| SANE_Int | configuration | |||
| ) |
Initiate set configuration.
Change set configuration
| dn | device number | |
| configuration,configuration | nummber |
| SANE_Status sanei_usb_claim_interface | ( | SANE_Int | dn, | |
| SANE_Int | interface_number | |||
| ) |
Initiate claim interface.
Change claim interface
| dn | device number | |
| interface_number | interface number |
| SANE_Status sanei_usb_release_interface | ( | SANE_Int | dn, | |
| SANE_Int | interface_number | |||
| ) |
Initiate release interface.
Change release interface
| dn | device number | |
| interface_number | interface number |
| SANE_Status sanei_usb_set_altinterface | ( | SANE_Int | dn, | |
| SANE_Int | alternate | |||
| ) |
Initiate a set altinterface.
Change set alternate
| dn | device number | |
| alternate,alternate | nummber |
| SANE_Status sanei_usb_get_descriptor | ( | SANE_Int | dn, | |
| struct sanei_usb_dev_descriptor * | desc | |||
| ) |
Get some information from the device descriptor.
Sometimes it's useful to know something about revisions and other stuff reported by the USB system
| dn | device number | |
| desc | where to put the information to |
1.5.1