Experimental linux-usbtmc kernel driver

Discussion created by dpenkler@gmail.com on Jul 1, 2017

An experimental version of the linux usbtmc kernel driver has been released at https://github.com/dpenkler/linux-usbtmc for folks to test and suggest new features before having them submitted to the upstream kernel.


The current version of the driver has some additional capabilities that have not yet been submitted upstream. These include module parameters to configure the buffer size and usb timeout and also an ioctl to send a device trigger. 


The build and resulting driver have been tested successfully on  "3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2" and a stock kernel.org 4.11.3, so should build OK on the intervening kernel versions.

Parts of the README from the project are included below to provide some extra details.

linux-usbtmc driver

This is an experimental linux driver for usb test measurement & control instruments that adds support for missing functions in USBTMC-USB488 spec and the ability to handle SRQ notifications with fasync or poll/select. Most of the functions have been incorporated in the linux kernel starting with version 4.6. This package is provided for folks wanting to test or use driver features not yet supported by the standard usbtmc driver in their kernel.

Presently only the trigger ioctl and the module params are not available in the standard kernel.org releases >= 4.6.



ioctl to support the USBTMC-USB488 READ_STATUS_BYTE operation.

When performing a read on an instrument that is executing a function that runs longer than the USB timeout the instrument may hang and require a device reset to recover. The READ_STATUS_BYTE operation always returns even when the instrument is busy, permitting the application to poll for the appropriate condition without blocking as would be the case with an "*STB?" query.

Note: The READ_STATUS_BYTE ioctl clears the SRQ condition but it has no effect on the status byte of the device.

Support for receiving USBTMC-USB488 SRQ notifications with fasync

By configuring an instrument's service request enable register various conditions can be reported via an SRQ notification. When the FASYNC flag is set on the file descriptor corresponding to the usb connected instrument a SIGIO signal is sent to the owning process when the instrument asserts a service request.

Support for receiving USBTMC-USB488 SRQ notifications via poll/select

In many situations operations on multiple instruments need to be synchronized. poll/select provide a convenient way of waiting on a number of different instruments and other peripherals simultaneously. When the instrument sends an SRQ notification the fd becomes readable. If the MAV (message available) event is enabled the normal semantic of poll/select on a readable file descriptor is achieved. However many other conditions can be set to cause SRQ. To reset the poll/select condition a READ_STATUS_BYTE ioctl must be performed. 

New ioctls to enable and disable local controls on an instrument

These ioctls provide support for the USBTMC-USB488 control requests for REN_CONTROL, GO_TO_LOCAL and LOCAL_LOCKOUT

ioctl to cause a device to trigger

This is equivalent to the IEEE 488 GET (Group Execute Trigger) action. While a the "*TRG" command can be sent to perform the same operation, in some situations an instrument will be busy and unable to process the command immediately in which case the USBTMC488_IOCTL_TRIGGER can be used.

Utility ioctl to retrieve USBTMC-USB488 capabilities

This is a convenience function to obtain an instrument's capabilities from its file descriptor without having to access sysfs from the user program. The driver encoded usb488 capability masks are defined in the tmc.h include file.

Two new module parameters

io_buffer_size specifies the size of the buffer in bytes that is used for usb bulk transfers. The default size is 2048. The minimum size is 512. Values given for this parameter are automatically rounded down to the nearest multiple of 4.

usb_timeout specifies the timeout in milliseconds that is used for usb transfers. The default value is 5000 and the minimum value is 500.


Issues and enhancement requests

Use the Issue feature in github to post requests for enhancements or bugfixes.