usb-1.2.0.1: Communicate with USB devices

Copyright(c) 2009–2012 Bas van Dijk
LicenseBSD3 (see the file LICENSE)
MaintainerBas van Dijk <v.dijk.bas@gmail.com>
Safe HaskellTrustworthy
LanguageHaskell98

System.USB.IO

Contents

Description

This module provides functions for performing control, bulk and interrupt transfers.

When your system supports the GHC EventManager this module additionally exports functions for performing isochronous transfers. These are currently not available on Windows.

WARNING: You need to enable the threaded runtime (-threaded) when using the isochronous functions. They throw a runtime error otherwise!

Synopsis

Documentation

type ReadAction = Size -> Timeout -> IO (ByteString, Status) 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 Status flag which indicates whether the transfer Completed or TimedOut.

type ReadExactAction = Size -> Timeout -> IO ByteString Source

Handy type synonym for read transfers that must exactly read the specified number of bytes. An incompleteReadException is thrown otherwise.

type WriteAction = ByteString -> Timeout -> IO (Size, Status) 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 a Status flag which indicates whether the transfer Completed or TimedOut.

type WriteExactAction = ByteString -> Timeout -> IO () Source

Handy type synonym for write transfers that must exactly write all the given bytes. An incompleteWriteException is thrown otherwise.

type Size = Int Source

Number of bytes transferred.

type Timeout = Int Source

A timeout in milliseconds. A timeout defines how long a transfer should wait before giving up due to no response being received. Use noTimeout for no timeout.

noTimeout :: Timeout Source

A timeout of 0 denotes no timeout so: noTimeout = 0.

data Status Source

Status of a terminated transfer.

Constructors

Completed

All bytes were transferred within the maximum allowed Timeout period.

TimedOut

Not all bytes were transferred within the maximum allowed Timeout period.

Control transfers

type ControlAction a = RequestType -> Recipient -> Request -> Value -> Index -> a Source

Handy type synonym that names the parameters of a control transfer.

type Value = Word16 Source

(Host-endian)

type Index = Word16 Source

(Host-endian)

control :: DeviceHandle -> ControlAction (Timeout -> IO ()) Source

Perform a USB control request that does not transfer data.

Exceptions:

readControl :: DeviceHandle -> ControlAction ReadAction Source

Perform a USB control read.

Exceptions:

readControlExact :: DeviceHandle -> ControlAction ReadExactAction Source

A convenience function similar to readControl which checks if the specified number of bytes to read were actually read. Throws an incompleteReadException if this is not the case.

writeControl :: DeviceHandle -> ControlAction WriteAction Source

Perform a USB control write.

Exceptions:

writeControlExact :: DeviceHandle -> ControlAction WriteExactAction Source

A convenience function similar to writeControl which checks if the given bytes were actually fully written. Throws an incompleteWriteException if this is not the case.

Bulk transfers

readBulk :: DeviceHandle -> EndpointAddress -> ReadAction Source

Perform a USB bulk read.

Exceptions:

writeBulk :: DeviceHandle -> EndpointAddress -> WriteAction Source

Perform a USB bulk write.

Exceptions:

Interrupt transfers

readInterrupt :: DeviceHandle -> EndpointAddress -> ReadAction Source

Perform a USB interrupt read.

Exceptions:

writeInterrupt :: DeviceHandle -> EndpointAddress -> WriteAction Source

Perform a USB interrupt write.

Exceptions:

Isochronous transfers

WARNING: You need to enable the threaded runtime (-threaded) when using the isochronous functions. They throw a runtime error otherwise!

readIsochronous Source

Arguments

:: DeviceHandle 
-> EndpointAddress 
-> Vector Size

Sizes of isochronous packets

-> Timeout 
-> IO (Vector ByteString) 

Perform a USB isochronous read.

WARNING: You need to enable the threaded runtime (-threaded) for this function to work correctly. It throws a runtime error otherwise!

Exceptions:

writeIsochronous :: DeviceHandle -> EndpointAddress -> Vector ByteString -> Timeout -> IO (Vector Size) Source

Perform a USB isochronous write.

WARNING: You need to enable the threaded runtime (-threaded) for this function to work correctly. It throws a runtime error otherwise!

Exceptions: