How to fix the read() error in the following code to control B1500 (parameter analyzer) using PyVISA?

62 Views Asked by At
import visa
import time

# Replace 'GPIB0::17::INSTR' with the actual VISA address of your Agilent B1500
visa_address = 'GPIB0::17::INSTR'

# Create a VISA resource manager and open a connection to the instrument
rm = visa.ResourceManager()
b1500 = rm.open_resource(visa_address)

try:
    # Configure SMU1:HR to 3V and SMU4:HR to 0V
    b1500.write(':SOURce1:VOLTage:LEVel 3.0')  # Set SMU1:HR to 3V
    b1500.write(':SOURce4:VOLTage:LEVel 0.0')  # Set SMU4:HR to 0V

    # Apply the voltages for 3 seconds
    time.sleep(3)

    # Measure the current on SMU1:HR
    b1500.write(':MEASure1:CURRent?')
    response_smu1 = b1500.read()
    current_smu1 = float(response_smu1.strip())  # Remove leading/trailing whitespace

    # Measure the current on SMU4:HR
    b1500.write(':MEASure4:CURRent?')
    response_smu4 = b1500.read()
    current_smu4 = float(response_smu4.strip())  # Remove leading/trailing whitespace

    # Print the measured currents
    print(f"Current on SMU1:HR: {current_smu1} A")
    print(f"Current on SMU4:HR: {current_smu4} A")

finally:
    # Close the connection
    b1500.close()

I am trying to measure current flowing through a device and the device is connected in between SMU1:HR and SMU4:HR channels of B1500 (parameter analyzer). For this purpose, I have used PyVISA and measured current of SMU1:HR and SMU4:HR channels.

But, I am getting the following error in case of reading the measured value -

Traceback (most recent call last):
  File "C:\Users\b1500\PycharmProjects\TestProjectNabila\resistor_test.py", line 23, in <module>
    current_smu1 = (b1500.read('\n'))
  File "C:\Users\b1500\PycharmProjects\TestProjectNabila\venv\lib\site-packages\pyvisa\resources\messagebased.py", line 489, in read
    message = self._read_raw().decode(enco)
  File "C:\Users\b1500\PycharmProjects\TestProjectNabila\venv\lib\site-packages\pyvisa\resources\messagebased.py", line 442, in _read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "C:\Users\b1500\PycharmProjects\TestProjectNabila\venv\lib\site-packages\pyvisa\ctwrapper\functions.py", line 2337, in read
    ret = library.viRead(session, buffer, count, byref(return_count))
  File "C:\Users\b1500\PycharmProjects\TestProjectNabila\venv\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 226, in _return_handler
    return self.handle_return_value(session, ret_value)  # type: ignore
  File "C:\Users\b1500\PycharmProjects\TestProjectNabila\venv\lib\site-packages\pyvisa\highlevel.py", line 251, in handle_return_value
    raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

Can you please suggest how to solve this error? I have tried to use read_raw() and read(expect_termination = False), but these throw error saying unexpected keyword.

0

There are 0 best solutions below