qmi.core.usbtmc

Python USBTMC driver

Copyright (c) 2012-2017 Alex Forencich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


This module was modified for use in QMI.

Original code downloaded from https://github.com/python-ivi/python-usbtmc/commit d9bfb20b2ef002da787adb6b093e1679705c00e2 Original author: Alex Forencich Original license: MIT License

This module was added to the QMI repository because the original repository is no longer maintained and has unresolved issues.

Modifications by Joris van Rantwijk:

(see also https://github.com/jorisvr/python-usbtmc/):

  • Read Bulk-IN data during abort_bulk_in sequence.

  • Clear Bulk-OUT endpoint after abort_bulk_out.

  • Ignore EOM flag when device sends partial data.

  • Always call set_configuration() to synchronize data toggle.

  • Clear Bulk-IN endpoint during initialization to synchronize data toggle.

Modifications by HK Ervasti:
  • .strip() dev.serial_number string to avoid SNs with whitespace character(s).

  • Logging import and a _logger instance with some ‘debug’ logging lines.

Functions

find_device([idVendor, idProduct, iSerial])

Find USBTMC instrument

list_devices()

List all connected USBTMC devices

list_resources()

List resource strings for all connected USBTMC devices

parse_visa_resource_string(resource_string)

Parse VISA resource string.

Classes

Instrument(*args, **kwargs)

USBTMC instrument interface client

Exceptions

UsbtmcException([err, note])

USBTMC exception type.

qmi.core.usbtmc.parse_visa_resource_string(resource_string)

Parse VISA resource string.

exception qmi.core.usbtmc.UsbtmcException(err=None, note=None)

USBTMC exception type.

add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

qmi.core.usbtmc.list_devices()

List all connected USBTMC devices

qmi.core.usbtmc.list_resources()

List resource strings for all connected USBTMC devices

qmi.core.usbtmc.find_device(idVendor=None, idProduct=None, iSerial=None)

Find USBTMC instrument

class qmi.core.usbtmc.Instrument(*args, **kwargs)

USBTMC instrument interface client

close()

Close device.

is_usb488()

Check if device supports USB488.

get_capabilities()

Enumerate the capabilities of the device.

pulse()

Send a pulse indicator request, this should blink a light for 500-1000ms and then turn off again.

Only for devices that support this.

write_raw(data)

Write binary data to instrument

Parameters:

data – data to send.

read_raw(num=-1)

Read binary data from instrument

Parameters:

num – number of bytes to read, or -1 for everything that is available.

ask_raw(data, num=-1)

Write (ask) then read binary data.

Parameters:
  • data – data to send (ask).

  • num – number of response bytes to read, or -1 for everything (default: -1).

write(message, encoding='utf-8')

Write string message(s) to instrument.

Parameters:
  • message – single message as string, or list/tuple of messages.

  • encoding – encoding to use (default: utf-8).

read(num=-1, encoding='utf-8')

Read string message from instrument.

Parameters:
  • num – number of bytes to read, or -1 for everything (default: -1).

  • encoding – encoding to use to decode the raw data (default: utf-8).

ask(message, num=-1, encoding='utf-8')

Write (ask) then read string messages.

Parameters:
  • message – message to send (ask).

  • num – number of response bytes to read, or -1 for everything (default: -1).

  • encoding – encoding to use to encode/decode the raw data (default: utf-8).

read_stb()

Read status byte.

trigger()

Send trigger command.

clear()

Send clear command.

remote()

Send remote command.

local()

Send local command.

lock()

Send lock command (Avantest only).

unlock()

Send unlock command (Avantest only).

advantest_read_myid()

Read MyID value from Advantest and ADCMT devices.