Device::USB::Win32Async - Add async functions to Device::USB
Version 0.31
Device::USB provides a Perl wrapper around the libusb library.
Device::USB::Win32Async adds the async functions from libusb-win32 to Device::USB. This is only available for Win32 systems.
use Device::USB; use Device::USB::Win32Async; my $usb = Device::USB->new(); my $dev = $usb->find_device( $VENDOR, $PRODUCT ); ... my $Context; # Context variable for asynch I/O my $Buffer; # Buffer for results (input) or to transmit (output) my $NumBytes = 5000; # of bytes to transfer $dev->bulk_setup_async($Context,$Endpoint); $Status = $dev->submit_async($Context,$Buffer,$NumBytes); # Start the transfer while( 1 ) { $Response = $dev->reap_async_nocancel($Context,50); # 50 mS wait time last if $Response != Device::USB::Device::ETIMEDOUT; # # Do other tasks while waiting, such as update the GUI # # For example, a TK program might call $MainWindow->update(); # <Other Task code> }
See the libusb-win32 manual for more information about the methods. The functionality is the same as the libusb function whose name is the method name prepended with "usb_".
Generally, define a $Context variable which the library will use to keep track of the asynchronous call. Activate the transfer (read or write, depending on the endpoint) using submit_async() as shown, then loop calling reap_async_nocancel() while checking the return code.
You can have any number of async operations pending on different endpoints - just define multiple context variables as needed (ie - $Context1, $Context2, &c).
Setup a Context for use in subsequent asynchronous operations
A scalar to store opaque information about the operation
The endpoint the asynchronous operation will use
The size of the isochronous packets
Returns 0 on success, < 0 on error (consult errno.h for explanation)
Start an asynchronous I/O operation
A previously prepared context generated by one of the xxx_setup_async functions above
A string buffer to receive the resulting data
The number of bytes to pre-allocate to hold the incoming data.
Get the results of an asynchronous operation and cancel if not complete.
Number of milliseconds to wait before timeout
Get the results of an asynchronous operation, but continue request (return Device::USB::Device::ETIMEDOUT => -116) if not complete yet.
Cancel an asynchronous operation in progress
Free up resources allocated for the asynchrounous context
Carp, Inline::C, and Device::USB.
Also depends on the libusb-win32 library.
Rajstennaj Barrabas wrote the code.
The module is maintained by G. Wade Johnson (wade at anomaly dot org).
Please report any bugs or feature requests to bug-device-usb-win32async@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Device::USB::Win32Async. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-device-usb-win32async@rt.cpan.org
This module depends on extensions to the libusb library added in the LibUsb-Win32 library. As such, the module is only expected to work on a Win32-based system.
Copyright 2009 Rajstennaj Barrabas
This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Device::USB::Win32Async, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::USB::Win32Async
CPAN shell
perl -MCPAN -e shell install Device::USB::Win32Async
For more information on module installation, please visit the detailed CPAN module installation guide.