11# -------------------------------------------------------------------------------
22# Name: Keithley 6517B Poling
3- # Purpose:
4- #
3+ # Purpose: Apply a poling voltage to a sample.
54# Author: Prathamesh K Deshmukh
6- #
75# Created: 03-03-2024
8-
9- # updates: V1.3
6+ # Updated: 22-11-2025 (Refactored for robustness)
107# -------------------------------------------------------------------------------
118
129import time
1310from pymeasure .instruments .keithley import Keithley6517B
1411
1512
16- try :
17- keithley = Keithley6517B ("GPIB0::27::INSTR" )
18- time .sleep (0.5 )
19- # keithley.apply_voltage() # Sets up to source current
20- # keithley.source_voltage_range = 20 # Sets the source voltage
21- # range to 200 V
22- # keithley.source_voltage = 20 # Sets the source voltage to 20 V
23- time .sleep (0.5 )
24- # keithley.enable_source() # Enables the source output
25- time .sleep (0.5 )
26- keithley .source_voltage = 100
27- # keithley.measure_resistance() # Sets up to measure resistance
28- # keithley.ramp_to_voltage(10) # Ramps the voltage to 50 V
29- # print(keithley.resistance) # Prints the resistance in Ohms
30- time .sleep (20 )
31- print (f'Current is { (keithley .current )} ' )
32-
33- # and disables outpu
34- except Exception as e :
35- print (f"error with Keithley6517B : { e } " )
36-
37- except KeyboardInterrupt :
38- # keithley.source_voltage = 0 # Ramps the voltage to 50 V
39- keithley .shutdown () # Ramps the voltage to 0 V
40- print ("\n Poling stopped..." )
41-
42- time .sleep (0.5 )
43- keithley .clear ()
44- time .sleep (0.5 )
45- keithley .reset ()
46-
47- keithley .shutdown () # Ramps the current to 0 mA and disables output
48-
49-
50- except Exception as e :
51- print (f"error with keithley : { e } " )
52- keithley .shutdown ()
13+ def main ():
14+ """
15+ Connects to a Keithley 6517B, applies a fixed voltage for a duration,
16+ and then safely shuts down.
17+ """
18+ keithley = None
19+ try :
20+ # Initialize and configure the instrument
21+ keithley = Keithley6517B ("GPIB0::27::INSTR" )
22+ time .sleep (0.5 )
23+
24+ # Apply a poling voltage
25+ keithley .source_voltage = 100
26+ keithley .enable_source ()
27+ print ("Source enabled. Applying 100V for poling." )
28+ time .sleep (1 )
29+
30+ # Wait for the poling duration, periodically checking current
31+ print ("Waiting for poling to complete (20s)... Press Ctrl+C to stop early." )
32+ for i in range (20 ):
33+ time .sleep (1 )
34+ # You can uncomment the next line to monitor current during poling
35+ # print(f" -> Time: {i+1}s, Current: {keithley.current:.3e} A", end='\r')
36+
37+ print (f"\n Poling complete. Final current: { keithley .current :.3e} A" )
38+
39+ except KeyboardInterrupt :
40+ print ("\n Poling stopped by user (Ctrl+C)." )
41+ except Exception as e :
42+ print (f"An error occurred with the Keithley 6517B: { e } " )
43+ finally :
44+ # Guaranteed shutdown logic
45+ if keithley :
46+ print ("Ramping down voltage and shutting down source..." )
47+ keithley .shutdown ()
48+ print ("Source is off." )
49+ # Optional: Reset the instrument to default state
50+ keithley .reset ()
51+
52+
53+ if __name__ == "__main__" :
54+ main ()
0 commit comments