Interface configuration
Before setting up PyVISA you need to setup your interface.
USB
Notes
- For Serial over USB, read the Serial / RS232 section.
- See here for a USB oscilloscope example script.
Windows
After following the NI-VISA + PyVISA install guide it works out of the box.
Linux
You will need to add a Udev rule that grant your user raw access to USB devices. For added security, you can instead grant access to a specific device only (see note below).
-
Create Group: Create a new group called
usbgroup
.sudo groupadd usbgroup
-
Add User to Group: Add the current user to the
usbgroup
group.sudo usermod -aG usbgroup $USER
-
Create Udev Rule: Authorize raw USB access to a group called
usbgroup
.sudo bash -c 'cat > /etc/udev/rules.d/99-usbgroup.rules <<EOF SUBSYSTEM=="usb", GROUP="usbgroup", MODE="0666" EOF'
-
Reload Udev Rules: to apply the changes.
sudo udevadm control --reload-rules sudo udevadm trigger
-
Reboot your system:
sudo reboot
Now go to the Linux PyVISA setup.
Note: adding a Udev Rule for a Specific USB Device
- Identify USB Device
Use lsusb
to find the vendor ID (VID) and product ID (PID) of your USB device.
Bus 003 Device 011: ID VID:PID Your SCPI / VISA compatible measuring instrument
-
Create Udev Rule: Create a udev rule for your specific USB device.
sudo bash -c 'cat > /etc/udev/rules.d/99-mydevice.rules <<EOF SUBSYSTEM=="usb", ATTR{idVendor}=="VID", ATTR{idProduct}=="PID", GROUP="usbgroup", MODE="0666" EOF'
-
Reload Udev Rules: to apply changes.
sudo udevadm control --reload-rules sudo udevadm trigger
-
Reboot if needed.
Ethernet
No special drivers are needed, it works out of the box in all OS. Skip to the Windows PyVISA setup or the Linux PyVISA setup.
Notes
- Your PC's firewall need to allow traffic on the instrument's port.
Standard ports for protocols VXI-11:
TCP 111
, HiSLIP:TCP 4880
. - For raw sockets, specify the instrument's IP and port in its address:
TCPIP::<IP>::<PORT>
.
GPIB (IEEE488)
This interface requires a GPIB controller or a GPIB to USB adapter. These adapters are quite expensive, often over $150 for the cheapest ones. A cheaper Open-Source alternative exists for hobbyists: UsbGpib.
Windows
Install your adapter's drivers and go to the NI-VISA + PyVISA install guide.
Linux
If you are using an NI or Agilent card, the linux-gpib drivers should be installed. It is not a trivial setup and you should refer to Tom Verbeure's guide.
The UsbGpib's GitHub repo documents it's setup.
Serial / RS232
Notes
- An example script for a serial power supply is available here.
- You may need to set the baud rate of the connection using the
baud_rate
parameter in theopen_resource
method. Ex:open_resource("ASRL1::INSTR", baud_rate=115200)
.
Windows
Works out of the box.
Serial VISA adress format expected: ASRL<X>::INSTR
Linux
For Linux (and UNIX) users, add your user to the dialout
group:
sudo usermod -aG dialout $USER
Serial VISA adress format expected: ASRL/dev/ttyUSB<X>::INSTR
or ASRL<X>::INSTR
.
PXI
For PXI chassis, refer to the NI PXI Platform Services website. Drivers are available for Windows and Linux.
Termination Characters
Some devices expect termination characters at the end of the commands and send them at the end of answers.
Refer to the device's manual but the most common characters are \n
, r
, and \r\n
.
For serial, the default is no write termination and \r
for read termination.
Example:
inst.read_termination = "\n" # Line Feed (LF) inst.write_termination = "\r" # Carriage Return + Line Feed