Keithley 2602A: Troubleshooting Python VISA Control

Daniel Price3 min read
Other ManufacturerSerial CommunicationTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

A Python application can control a Keithley 2602A without Test Script Builder by sending instrument commands through VISA. The reported failure occurs before any command is sent: VI_ERROR_RSRC_BUSY means VISA recognizes COM1 but cannot open it. First release the resource, then configure the connection according to the actual interface.

Interpret VI_ERROR_RSRC_BUSY

The traceback reaches the VISA open operation and returns VI_ERROR_RSRC_BUSY: The resource is valid, but VISA cannot currently access it. This confirms that COM1 is a valid VISA resource; it does not confirm that serial settings or instrument commands are correct.

Check whether Test Script Builder or another application already has COM1 open. Close the competing application before starting Python. If the error remains, confirm that COM1 is the interface physically connected to the instrument.

Select the Serial or GPIB Path

Interface Evidence-supported requirement Resource shown
Serial Obtain exclusive access to the port and append a linefeed to every command. COM1
GPIB through KUSB-488 Install the Keithley cable driver, pass the GPIB diagnostic, install a VISA implementation, and address the instrument over GPIB. GPIB::26

The successful GPIB setup used a Keithley KUSB-488 adapter and NI-VISA 4.1. The evidence does not establish whether newer NI-VISA releases behave identically. It also supplies no serial baud rate, parity, data-bit, stop-bit, or flow-control settings, so obtain those values from the instrument configuration rather than guessing.

Establish Python Control

  1. Close Test Script Builder and any other process that may own the selected serial or GPIB resource.
  2. For KUSB-488, install its driver and run the supplied GPIB diagnostic. Continue only after the diagnostic passes.
  3. Install VISA and PyVISA, then open the resource that matches the physical interface. For serial operation, terminate each transmitted command with a linefeed.
  4. Send a source-level command, enable the output, and verify communication by requesting measured values. Turn the output off after the measurement.

This evidence-supported GPIB sequence sets 10 V, enables channel A, measures current and voltage into instrument variables, disables the output, and prints the variables through the remote interface:

import visa
ps = visa.Instrument("GPIB::Address of your instrument")
ps.write("smua.source.levelv=10")
ps.write("smua.source.output=smua.OUTPUT_ON")
ps.write("currenta, voltagea = smua.measure.iv()")
ps.write("smua.source.output=smua.OUTPUT_OFF")
current = ps.ask("print(currenta)")
voltage = ps.ask("print(voltagea)")

Replace the placeholder with the instrument's configured GPIB address. A separate successful test used GPIB::26, but that address must not be assumed for another instrument.

Verify Commands and Returned Data

Verify both write and read directions. A successful open or output command proves only part of the path; confirm that ask("print(currenta)") and ask("print(voltagea)") return data after smua.measure.iv(). Named instrument variables support short bias-and-measure sequences. The evidence indicates that direct buffer access may be more efficient for large sweeps, but it does not provide a validated buffer procedure.

Apply appropriate electrical safety controls before energizing the output. The example contains smua.source.levelv=10 because that exact test appeared in the evidence; it is not a recommended level for an unspecified device under test.

FAQ

Why does PyVISA report VI_ERROR_RSRC_BUSY on COM1?

VISA recognizes COM1, but another application may already have it open. Close Test Script Builder and any other serial application, then retry the Python connection.

Does the Keithley 2602A serial interface require a command terminator?

Yes. The supplied evidence states that serial commands must end with a linefeed; it does not provide the remaining serial-port settings.

How can Python read current and voltage from a Keithley 2602A?

Execute currenta, voltagea = smua.measure.iv(), then query print(currenta) and print(voltagea) through the remote interface. Confirm returned data before expanding the script to coordinated hardware control.

Back to blog