You can download this code by clicking the button below.
This code is now available for download.
This function uses the PyVISA library to connect to a device and read information from the device, such as the device model, using the device address. It sets a timeout and handles possible errors while reading data.
Technology Stack : PyVISA
Code Type : Function
Code Difficulty : Intermediate
def read_values_from_device(device_address, timeout=10):
import visa
rm = visa.ResourceManager()
try:
device = rm.open_resource(device_address)
device.timeout = timeout
values = device.query("*IDN?")
return values
except visa.VisaIOError as e:
print(f"An error occurred: {e}")
return None
finally:
rm.close()