Created
December 20, 2024 14:20
-
-
Save steveway/d5d208dfec39844d06340f2f0a9cb188 to your computer and use it in GitHub Desktop.
Example for Siglent SPD4000 devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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