Page
Library
Module
Module type
Parameter
Class
Class type
Source
USBModule for USB communication
handle_error f x applies f to x and returns the result. If the exception Error or Transport is raised, it prints a message describing the error and exits with code 2.
type error = | Error_ioError on IOs
*)| Error_invalid_paramInvalid parameter. If this error is raised, then there is a bug in ocaml-usb. Please fill a bug report in this case.
*)| Error_accessAccess denied to a peripheral
*)| Error_no_deviceNo such device (it may have been disconnected)
*)| Error_not_foundEntity not found
*)| Error_busyResource busy
*)| Error_timeoutOperation timed out
*)| Error_overflowOverflow
*)| Error_pipePipe error
*)| Error_interruptedSystem call interrupted (perhaps due to signal)
*)| Error_no_memInsufficient memory
*)| Error_not_supportedOperation not supported or unimplemented on this platform
*)| Error_otherOther error
*)Any function of this module may raise one of the following errors:
exception Error of error * stringError(error, func_name) is raised when libusb returns an error. func_name is a the name of the function which failed.
val error_message : error -> stringerror_message error returns a human readable description of the error
val init : unit Lazy.tWhen forced, init initialises libusb. This is automatically done so you do not need to do it manually. By the way you can do it to catch initialisation errors.
set_debug level set the debug level.
val get_device_list : unit -> device listReturns a list of USB devices currently attached to the system.
val get_bus_number : device -> intGet the number of the bus that a device is connected to.
val get_device_address : device -> intGet the address of the device on the bus it is connected to.
get_max_packet_size ~device ~direction ~endpoint Convenience function to retrieve the wMaxPacketSize value for a particular endpoint in the active device configuration.
Open a device and obtain a device handle.
A handle allows you to perform I/O on the device in question.
val close : handle -> unitClose a previously opened device handle
val open_device_with : vendor_id:int -> product_id:int -> handleopen_device_with ~vendor_id ~product_id
Convenience function for finding a device with a particular idVendor/idProduct combination.
Determine if a kernel driver is active on an interface.
If a kernel driver is active, you cannot claim the interface, and libusb will be unable to perform I/O.
Detach a kernel driver from an interface.
If successful, you will then be able to claim the interface and perform I/O.
Re-attach an interface's kernel driver, which was previously detached using detach_kernel_driver.
claim_interface handle interface_number
Claim an interface on a given device handle.
You must claim the interface you wish to use before you can perform I/O on any of its endpoints.
Release an interface previously claimed with libusb_claim_interface().
You should release all claimed interfaces before closing a device handle.
This is a blocking function. A SET_INTERFACE control request will be sent to the device, resetting interface state to the first alternate setting.
val get_configuration : handle -> configuration Lwt.tget_configuration handle returns the current configuration of a device
val set_configuration : handle -> configuration -> unit Lwt.tset_configuration handle conf change the current configuration of a device
set_interface_alt_setting handle interface alternate_setting activates an alternate setting for an interface.
clear_halt handle endpoint clears the halt/stall condition for an endpoint.
val reset_device : handle -> unit Lwt.treset_device handle reset the given device
module Class : sig ... endDevice class codes
type device_descriptor = {dd_usb : int;USB specification release number in binary-coded decimal.
A value of 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc.
*)dd_device_class : Class.t;USB-IF class code for the device.
*)dd_device_sub_class : int;USB-IF subclass code for the device, qualified by the dd_device_class value.
dd_device_protocol : int;USB-IF protocol code for the device, qualified by the dd_device_class and dd_device_subclass values.
dd_max_packet_size : int;Maximum packet size for endpoint 0.
*)dd_vendor_id : int;USB-IF vendor ID.
*)dd_product_id : int;USB-IF product ID.
*)dd_device : int;Device release number in binary-coded decimal.
*)dd_index_manufacturer : int;Index of string descriptor describing manufacturer.
*)dd_index_product : int;Index of string descriptor describing product.
*)dd_index_serial_number : int;Index of string descriptor containing device serial number.
*)dd_configurations : int;Number of possible configurations.
*)}val get_device_descriptor : device -> device_descriptorGet the USB device descriptor for a given device.
type endpoint_descriptor = {ed_endpoint_address : int;The address of the endpoint described by this descriptor.
*)ed_attributes : int;ed_max_packet_size : int;Maximum packet size this endpoint is capable of sending/receiving.
*)ed_interval : int;Interval for polling endpoint for data transfers.
*)ed_refresh : int;For audio devices only: the rate at which synchronization feedback is provided.
*)ed_synch_address : int;For audio devices only: the address if the synch endpoint.
*)}type interface_descriptor = {id_interface : int;Number of this interface.
*)id_alternate_setting : int;Value used to select this alternate setting for this interface.
*)id_interface_class : Class.t;USB-IF class code for this interface.
*)id_interface_sub_class : int;USB-IF subclass code for this interface, qualified by the id_interface_class value.
id_interface_protocol : int;USB-IF protocol code for this interface, qualified by the id_interface_class and id_interface_sub_class values.
id_index_interface : int;Index of string descriptor describing this interface.
*)id_endpoints : endpoint_descriptor array;Array of endpoint descriptors.
*)}type config_descriptor = {cd_configuration_value : int;Identifier value for this configuration
*)cd_index_configuration : int;Index of string descriptor describing this configuration.
*)cd_attributes : int;A bitmask, representing configuration characteristics.
*)cd_max_power : int;Maximum power consumption of the USB device from this bus in this configuration when the device is fully opreation.
Expressed in units of 2 mA.
*)cd_interfaces : interface_descriptor array array;Array of interfaces supported by this configuration.
cd_interface.(iface).(altsetting) designate the interface descriptor for interface iface with alternate setting altsetting.
}val get_active_config_descriptor : device -> config_descriptorGet the USB configuration descriptor for the currently active configuration.
val get_config_descriptor : device -> int -> config_descriptorGet a USB configuration descriptor based on its index.
val get_config_descriptor_by_value : device -> int -> config_descriptorGet a USB configuration descriptor with a specific cd_configuration_value.
module DT : sig ... endDescriptor types
val get_string_descriptor :
handle ->
?timeout:float ->
?lang_id:int ->
index:int ->
string Lwt.tRetrieve a string descriptor from a device.
type transfer_error = | Transfer_errorTransfer failed
*)| Transfer_timed_outTransfer timed out
*)| Transfer_cancelledTransfer was cancelled
*)| Transfer_stallFor bulk/interrupt endpoints: halt condition detected (endpoint stalled). For control endpoints: control request not supported.
*)| Transfer_no_deviceDevice was disconnected
*)| Transfer_overflowDevice sent more data than requested
*)Transfers may fails with any of the following error:
exception Transfer of transfer_error * stringTransfer(error, func_name) Exception raised when a transfer fail.
val transfer_error_message : transfer_error -> stringtransfer_error_message error
val bulk_recv :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
string ->
int ->
int ->
int Lwt.tbulk_recv ~handle ~endpoint ?timeout buffer offset length
val bulk_send :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
string ->
int ->
int ->
int Lwt.tbulk_send ~handle ~endpoint ?timeout buffer offset length
val interrupt_recv :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
string ->
int ->
int ->
int Lwt.tinterrupt_recv ~handle ~endpoint ?timeout buffer offset length
val interrupt_send :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
string ->
int ->
int ->
int Lwt.tinterrupt_send ~handle ~endpoint ?timeout buffer offset length
type iso_result = | Iso_ok of intThe packet has been transfered successfully
*)| Iso_error of transfer_error * stringIso_error(error, func_name) An error occured
Result of the transfer of one packet in an isochronous transfer:
val iso_recv :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
string ->
int ->
int list ->
iso_result list Lwt.tval iso_send :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
string ->
int ->
int list ->
iso_result list Lwt.tval control_send :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
?recipient:recipient ->
?request_type:request_type ->
request:request ->
value:int ->
index:int ->
string ->
int ->
int ->
int Lwt.tSends a control packet.
val control_recv :
handle:handle ->
endpoint:endpoint ->
?timeout:float ->
?recipient:recipient ->
?request_type:request_type ->
request:request ->
value:int ->
index:int ->
string ->
int ->
int ->
int Lwt.tReceives a control packet.
module Request : sig ... endStandard requests