Skip to content

Instantly share code, notes, and snippets.

@steveway
Created December 20, 2024 14:20
Show Gist options
  • Select an option

  • Save steveway/d5d208dfec39844d06340f2f0a9cb188 to your computer and use it in GitHub Desktop.

Select an option

Save steveway/d5d208dfec39844d06340f2f0a9cb188 to your computer and use it in GitHub Desktop.
Example for Siglent SPD4000 devices
#! /usr/bin/env python3
import pyvisa as visa
from serial.serialutil import SerialException
def main():
# Get list of connected devices
rm = visa.ResourceManager()
device_list = {}
for device_name in rm.list_resources():
print(device_name)
device_id = ""
try:
device_id = rm.open_resource(device_name).query("*IDN?")
except (visa.VisaIOError, FileNotFoundError, SerialException):
pass
if "spd" in device_name.lower(): # Add only devices which names contain "spd"
if device_name not in device_list:
device_list[device_name] = rm.open_resource(device_name)
for name in device_list.keys():
device = device_list[name]
print(name.split("::")[3])
device.write(":SOURce:VOLTage:SET CH1,3")
current_voltage = device.query(':SOURce:VOLTage:SET? CH1')
print(f"Current voltage: {current_voltage}")
# Enable output
device.write("OUTPut CH1,1")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment