Simon Reinhardt
and 1 contributors

NAME

USB::TMC - Perl interface to USB Test & Measurement (USBTMC) backend.

SYNOPSIS

 use USB::TMC;

 # Open usb connection to  Agilent 34410A digital multimeter
 my $usbtmc = USB::TMC->new(
     vid => 0x0957,
     pid => 0x0607,
     serial => 'MY47000419', # only needed if vid/pid is ambiguous
 );
 
 $usbtmc->write(data => "*CLS\n");
 $usbtmc->write(data => "VOLT:NPLC 10\n");

 $usbtmc->write(data => ":read?\n");
 print $usbtmc->read(length => 100);
 print $usbtmc->query(data => ":read?\n", length => 100);
 
 my $capabilities = $usbtmc->get_capabilities();
 my $support_term_char = $capabilities->{support_term_char};

DESCRIPTION

This module provides a user-space USBTMC driver.

Internally this module is based on USB::LibUSB.

Does not yet support the additional features of USBTMC-USB488. But those could easily be added if needed.

INSTALLATION

The documentation of USB::LibUSB contains detailed installation instructions.

To access USB devices as a non-root user we need udev rules. E.g. on Debian we add a file /etc/udev/rules.d/97-usbtmc.rules with contents:

 ATTR{idVendor}=="0957", GROUP="usbtmc"

where "0957" (actually 0x0957) is the USB vendor ID of Agilent Technologies.

With this udev rule, all users in the "usbtmc" group can access the device.

METHODS

Errors with USB transfers will result in a croak.

Use default timeout if timeout arg is not given.

new

 my $usbtmc = USB::TMC->new(
     vid => $vid,
     pid => $pid,
     serial => $serial, # optional
     reset_device => 1, # default: do not reset device
     debug_mode => 1,   # print lots of debug messages
     libusb_log_level => LIBUSB_LOG_LEVEL_DEBUG, # Import LIBUSB_LOG_LEVEL_* constant from USB::LibUSB
     term_char => "\n", # Stop a read request if the term_char occurs in the
                        # byte stream. Default: do not use term char
     timeout => 10,     # timeout in seconds. default: 5
 );

write

 $usbtmc->write(data => $data, timeout => $timeout);

Do DEV_DEP_MSG_OUT transfer. So far this only supports USBTMC messages consisting of a single transfer.

read

 my $data = $usbtmc->read(length => $read_length, timeout => $timeout);

Do REQUEST_DEV_DEP_MSG_IN and DEV_DEP_MSG_IN transfers.

clear

 $usbtmc->clear(timeout => $timeout);

Do INITIATE_CLEAR / CHECK_CLEAR_STATUS split transaction. On success, send CLEAR_FEATURE request to clear the Bulk-OUT Halt.

get_capabilities

 my $capabilites = $usbtmc->get_capabilities(timeout => $timeout);

Do GET_CAPABILITIES request.

The $capabilities hash contains the following keys:

bcdUSBTMC
listen_only
talk_only
accept_indicator_pulse
support_term_char

REPORTING BUGS

Please report bugs at https://github.com/lab-measurement/USB-TMC/issues.

CONTACT

Feel free to contact us at the #labmeasurement channel on Freenode IRC.

SEE ALSO

AUTHOR

Simon Reinhardt, <simon.reinhardt@stud.uni-regensburg.de>

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Simon Reinhardt

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.0 or, at your option, any later version of Perl 5 you may have available.