USB::TMC - Perl interface to USB Test & Measurement (USBTMC) backend.
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};
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.
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.
Errors with USB transfers will result in a croak.
Use default timeout if timeout arg is not given.
timeout
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 );
$usbtmc->write(data => $data, timeout => $timeout);
Do DEV_DEP_MSG_OUT transfer. So far this only supports USBTMC messages consisting of a single transfer.
my $data = $usbtmc->read(length => $read_length, timeout => $timeout);
Do REQUEST_DEV_DEP_MSG_IN and DEV_DEP_MSG_IN transfers.
$usbtmc->clear(timeout => $timeout);
Do INITIATE_CLEAR / CHECK_CLEAR_STATUS split transaction. On success, send CLEAR_FEATURE request to clear the Bulk-OUT Halt.
my $capabilites = $usbtmc->get_capabilities(timeout => $timeout);
Do GET_CAPABILITIES request.
The $capabilities hash contains the following keys:
$capabilities
Please report bugs at https://github.com/lab-measurement/USB-TMC/issues.
Feel free to contact us at the #labmeasurement channel on Freenode IRC.
Blog post on Lab::VXI11 and USB::TMC
Simon Reinhardt, <simon.reinhardt@stud.uni-regensburg.de>
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.
To install USB::TMC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm USB::TMC
CPAN shell
perl -MCPAN -e shell install USB::TMC
For more information on module installation, please visit the detailed CPAN module installation guide.