Created
March 4, 2025 13:05
-
-
Save steveway/a474f67aa0c52f67687dc4b61c5a291f to your computer and use it in GitHub Desktop.
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 | |
| def main(): | |
| # Connect to the device | |
| rm = visa.ResourceManager() | |
| instrument = rm.open_resource("TCPIP0::192.168.10.94::inst0::INSTR") # replace with IP address of your device | |
| instrument.timeout = 200000 | |
| device_id = instrument.query("*IDN?") | |
| print(device_id) | |
| # Set the device to AC | |
| instrument.write("CONF:VOLT:AC") | |
| # Set the device to 200mV | |
| instrument.write("VOLT:AC:RANG 0.2") | |
| # Set the number of measurements to 1 | |
| instrument.write("SAMP:COUNT 1") | |
| # Read the voltage, this returns a list of voltages, the first element is the voltage, if you increase the sample count it will contain multiple values | |
| voltage = instrument.query_ascii_values("READ?") | |
| print(f"Voltage: {voltage}") | |
| # Compare the voltage to the expected value | |
| expected_value = 0.015 | |
| # We want the voltage to be within 5% of the expected value | |
| if abs(voltage[0] - expected_value) < expected_value * 0.05: # We use [0] because we only have one value, and we want to compare it to the expected value | |
| print("Test passed") | |
| else: | |
| print("Test failed") | |
| # Show how many percent the voltage deviates from the expected value with 2 decimal places | |
| print(f"Percentage deviation: {abs(voltage[0] - expected_value) / expected_value * 100:.2f}%") | |
| # Close the connection | |
| instrument.close() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment