Skip to content

Instantly share code, notes, and snippets.

@countrymarmot
Last active June 21, 2018 03:05
Show Gist options
  • Save countrymarmot/0d92cb5aec8944dbc681 to your computer and use it in GitHub Desktop.
Save countrymarmot/0d92cb5aec8944dbc681 to your computer and use it in GitHub Desktop.

Test Intruments Driver in Python

Introduction

IVI, VISA, SCPI

SCPI stands for Standard Commands for Programmable Instruments (SCPI), the commands is pure ASCII String, no physical communications link is not defined, it can be used in USB, GPIB, RS-232, Ethernet, VXI, etc.

Example for Ubuntu14.04

Here is an example to make an Agilent U3606A (multimeter and DC power supply, usb interface) to work on Ubuntu 14.04.

First, install the dependency library

we need 3 libs to communicate with the usb interfaced intruments in python, libusb -> pyusb -> usbtmc.

Get Agilent U3606A usb info.

$lsusb
Bus 003 Device 002: ID 0957:4d18 Agilent Technologies, Inc. 

vendor ID is 0957 and product ID is 4d18. Use usbtmc to open the device.

import usbtmc

instr = usbtmc.Intruments(0x0957, 0x4d18)

And we got an error message:

USBError: [Errno 13] Access denied (insufficient permissions)

add rule to udev

we need add rule to udev, by:

sudo vim /etc/udev/rules.d/usbtmc.rules

add following content:

# Agilent U3606A
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0957", ATTR{idProduct}=="4d18", GROUP="usbtmc", MODE="0660"

The group stands for the unix group name, and mode is unix permissions, 0660 (equals to 110 110 000, 3 groups of "r" "w" "x" for owner, group and others, equals to rw-rw----) stands for owner and group have read and write permission while others don't.

add group and username

We need check if the group "usbtmc" exists and if the current user is in the group.

$cat /etc/group
(list groups)

$groups qibo
(or just $groups, list groups the current user in)

qibo : qibo adm dialout fax cdrom floppy tape sudo audio dip video plugdev fuse netdev vboxusers usbtmc 

if your username is not in the group or the group "usbtmc" doesn't exists:

$sudo groupadd usbtmc
(add group)

$sudo usermod -G usbtmc -a qibo
(add qibo to group usbtmc)

We need restart the computer to make it effective.

send SCPI command string

import usbtmc

instr = usbtmc.Instruments(0x0957, 0x4d18)
instr.ask("*IDN?\n")    # notice the "\n" is for Agilent only, some other vendor may not required.
# u'Agilent Technologies,U3606A,MY49520024,01.00-01.00-01.00'

Now it's ready to use the device.

Example for Windows 7

Here is an example to make an Agilent U3606A (multimeter and DC power supply, usb interface) to work on Windows 7. The steps will be very simliar to previous steps for Linux.

First, install the dependency library

we need 3 libs to communicate with the usb interfaced intruments in python, libusb -> pyusb -> usbtmc.

send SCPI command string

Once we installed the drivers and libs, we can directly use it in windows 7:

import usbtmc

instr = usbtmc.Instruments(0x0957, 0x4d18)
instr.ask("*IDN?\n")    # notice the "\n" is for Agilent only, some other vendor may not required.
# u'Agilent Technologies,U3606A,MY49520024,01.00-01.00-01.00'

Reference

http://cp.literature.agilent.com/litweb/pdf/5989-6715EN.pdf

http://cp.literature.agilent.com/litweb/pdf/5989-6718EN.pdf

http://www.ivifoundation.org/docs/scpi-99.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment