Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |
---|
This module provides functionality for performing control, bulk and interrupt transfers.
- type ReadAction = Size -> Timeout -> IO (ByteString, TimedOut)
- type WriteAction = ByteString -> Timeout -> IO (Size, TimedOut)
- type Timeout = Int
- type TimedOut = Bool
- type Size = Int
- type ControlAction α = RequestType -> Recipient -> Request -> Value -> Index -> α
- data RequestType
- data Recipient
- = ToDevice
- | ToInterface
- | ToEndpoint
- | ToOther
- type Request = Word8
- type Value = Word16
- type Index = Word16
- control :: DeviceHandle -> ControlAction (Timeout -> IO ())
- readControl :: DeviceHandle -> ControlAction ReadAction
- readControlExact :: DeviceHandle -> ControlAction (Size -> Timeout -> IO ByteString)
- writeControl :: DeviceHandle -> ControlAction WriteAction
- readBulk :: DeviceHandle -> EndpointAddress -> ReadAction
- writeBulk :: DeviceHandle -> EndpointAddress -> WriteAction
- readInterrupt :: DeviceHandle -> EndpointAddress -> ReadAction
- writeInterrupt :: DeviceHandle -> EndpointAddress -> WriteAction
Documentation
type ReadAction = Size -> Timeout -> IO (ByteString, TimedOut)Source
Handy type synonym for read transfers.
A ReadAction
is a function which takes a Size
which defines how many bytes
to read and a Timeout
. The function returns an IO
action which, when
executed, performs the actual read and returns the ByteString
that was read
paired with a flag which indicates whether a transfer timed out.
type WriteAction = ByteString -> Timeout -> IO (Size, TimedOut)Source
Handy type synonym for write transfers.
A WriteAction
is a function which takes a ByteString
to write and a
Timeout
. The function returns an IO
action which, when exectued, returns the
number of bytes that were actually written paired with an flag which indicates
whether a transfer timed out.
A timeout in milliseconds. A timeout defines how long a transfer should wait before giving up due to no response being received. For no timeout, use value 0.
Control transfers
type ControlAction α = RequestType -> Recipient -> Request -> Value -> Index -> αSource
Handy type synonym that names the parameters of a control transfer.
data RequestType Source
control :: DeviceHandle -> ControlAction (Timeout -> IO ())Source
Perform a USB control request that does not transfer data.
Exceptions:
-
TimeoutException
if the transfer timed out. -
PipeException
if the control request was not supported by the device -
NoDeviceException
if the device has been disconnected. - Another
USBException
.
readControl :: DeviceHandle -> ControlAction ReadActionSource
Perform a USB control read.
Exceptions:
-
PipeException
if the control request was not supported by the device -
NoDeviceException
if the device has been disconnected. - Another
USBException
.
readControlExact :: DeviceHandle -> ControlAction (Size -> Timeout -> IO ByteString)Source
A convenience function similar to readControl
which checks if the
specified number of bytes to read were actually read. Throws an IOException
if this is not the case.
writeControl :: DeviceHandle -> ControlAction WriteActionSource
Perform a USB control write.
Exceptions:
-
PipeException
if the control request was not supported by the device -
NoDeviceException
if the device has been disconnected. - Another
USBException
.
Bulk transfers
:: DeviceHandle | A handle for the device to communicate with. |
-> EndpointAddress | The address of a valid |
-> ReadAction |
Perform a USB bulk read.
Exceptions:
-
PipeException
if the endpoint halted. -
OverflowException
if the device offered more data, see Packets and overflows in thelibusb
documentation: http://libusb.sourceforge.net/api-1.0/packetoverflow.html. -
NoDeviceException
if the device has been disconnected. - Another
USBException
.
:: DeviceHandle | A handle for the device to communicate with. |
-> EndpointAddress | The address of a valid |
-> WriteAction |
Perform a USB bulk write.
Exceptions:
-
PipeException
if the endpoint halted. -
OverflowException
if the device offered more data, see Packets and overflows in thelibusb
documentation: http://libusb.sourceforge.net/api-1.0/packetoverflow.html. -
NoDeviceException
if the device has been disconnected. - Another
USBException
.
Interrupt transfers
:: DeviceHandle | A handle for the device to communicate with. |
-> EndpointAddress | The address of a valid |
-> ReadAction |
Perform a USB interrupt read.
Exceptions:
-
PipeException
if the endpoint halted. -
OverflowException
if the device offered more data, see Packets and overflows in the libusb documentation: http://libusb.sourceforge.net/api-1.0/packetoverflow.html. -
NoDeviceException
if the device has been disconnected. - Another
USBException
.
:: DeviceHandle | A handle for the device to communicate with. |
-> EndpointAddress | The address of a valid |
-> WriteAction |
Perform a USB interrupt write.
Exceptions:
-
PipeException
if the endpoint halted. -
OverflowException
if the device offered more data, see Packets and overflows in thelibusb
documentation: http://libusb.sourceforge.net/api-1.0/packetoverflow.html. -
NoDeviceException
if the device has been disconnected. - Another
USBException
.