Examples
You can download all nidcpower examples for latest version here
nidcpower_advanced_sequence.py
1#!/usr/bin/python
2
3import argparse
4import hightime
5import nidcpower
6import sys
7
8
9def example(resource_name, options, voltage_max, current_max, points_per_output_function, source_delay):
10 with nidcpower.Session(resource_name=resource_name, options=options) as session:
11 # Configure the session.
12 session.source_mode = nidcpower.SourceMode.SEQUENCE
13 session.voltage_level_autorange = True
14 session.current_limit_autorange = True
15 session.source_delay = hightime.timedelta(seconds=source_delay)
16 properties_used = ['output_function', 'voltage_level', 'current_level']
17 session.create_advanced_sequence(sequence_name='my_sequence', property_names=properties_used, set_as_active_sequence=True)
18
19 voltage_per_step = voltage_max / points_per_output_function
20 for i in range(points_per_output_function):
21 session.create_advanced_sequence_step(set_as_active_step=False)
22 session.output_function = nidcpower.OutputFunction.DC_VOLTAGE
23 session.voltage_level = voltage_per_step * i
24
25 current_per_step = current_max / points_per_output_function
26 for i in range(points_per_output_function):
27 session.create_advanced_sequence_step(set_as_active_step=False)
28 session.output_function = nidcpower.OutputFunction.DC_CURRENT
29 session.current_level = current_per_step * i
30
31 # Calculate the timeout.
32 aperture_time = session.aperture_time
33 total_points = points_per_output_function * 2
34 timeout = hightime.timedelta(seconds=((source_delay + aperture_time) * total_points + 1.0))
35
36 with session.initiate():
37 channel_indices = f'0-{session.channel_count - 1}'
38 channels = session.get_channel_names(channel_indices)
39 measurement_group = [session.channels[name].fetch_multiple(total_points, timeout=timeout) for name in channels]
40
41 session.delete_advanced_sequence(sequence_name='my_sequence')
42 line_format = '{:<15} {:<4} {:<10} {:<10} {:<6}'
43 print(line_format.format('Channel', 'Num', 'Voltage', 'Current', 'In Compliance'))
44 for i, measurements in enumerate(measurement_group):
45 num = 0
46 channel_name = channels[i].strip()
47 for measurement in measurements:
48 print(line_format.format(channel_name, num, measurement.voltage, measurement.current, str(measurement.in_compliance)))
49 num += 1
50
51
52def _main(argsv):
53 parser = argparse.ArgumentParser(description='Output ramping voltage to voltage max, then ramping current to current max.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
54 parser.add_argument('-n', '--resource-name', default='PXI1Slot2/0, PXI1Slot3/0-1', help='Resource names of NI SMUs.')
55 parser.add_argument('-s', '--number-steps', default=256, type=int, help='Number of steps per output function')
56 parser.add_argument('-v', '--voltage-max', default=1.0, type=float, help='Maximum voltage (V)')
57 parser.add_argument('-i', '--current-max', default=0.001, type=float, help='Maximum Current (I)')
58 parser.add_argument('-d', '--delay', default=0.05, type=float, help='Source delay (s)')
59 parser.add_argument('-op', '--option-string', default='', type=str, help='Option String')
60 args = parser.parse_args(argsv)
61 example(args.resource_name, args.option_string, args.voltage_max, args.current_max, args.number_steps, args.delay)
62
63
64def main():
65 _main(sys.argv[1:])
66
67
68def test_main():
69 cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4162; BoardType:PXIe', ]
70 _main(cmd_line)
71
72
73def test_example():
74 options = {'simulate': True, 'driver_setup': {'Model': '4162', 'BoardType': 'PXIe', }, }
75 example('PXI1Slot2/0, PXI1Slot3/1', options, 1.0, 0.001, 256, 0.05)
76
77
78if __name__ == '__main__':
79 main()
80
81
nidcpower_constant_resistance_and_constant_power.py
1#!/usr/bin/python
2
3import argparse
4import nidcpower
5import sys
6
7
8def example(
9 resource_name,
10 options,
11 output_function,
12 constant_resistance_level,
13 constant_resistance_level_range,
14 constant_resistance_current_limit,
15 constant_power_level,
16 constant_power_level_range,
17 constant_power_current_limit,
18 source_delay,
19):
20 assert output_function in (
21 nidcpower.OutputFunction.CONSTANT_RESISTANCE, nidcpower.OutputFunction.CONSTANT_POWER
22 ), 'This example only supports CONSTANT_RESISTANCE and CONSTANT_POWER output functions.'
23
24 with nidcpower.Session(resource_name=resource_name, options=options) as session:
25 # Configure the session.
26 session.source_mode = nidcpower.SourceMode.SINGLE_POINT
27 session.output_function = output_function
28 if output_function == nidcpower.OutputFunction.CONSTANT_RESISTANCE:
29 session.constant_resistance_level = constant_resistance_level
30 session.constant_resistance_level_range = constant_resistance_level_range
31 session.constant_resistance_current_limit = constant_resistance_current_limit
32 else:
33 session.constant_power_level = constant_power_level
34 session.constant_power_level_range = constant_power_level_range
35 session.constant_power_current_limit = constant_power_current_limit
36 # Configure the source_delay to allow for sufficient startup delay for the input to sink to
37 # the desired level. When starting from a 0 A or Off state, the electronic load requires
38 # additional startup delay before the input begins to sink the desired level. The default
39 # source_delay in this example takes this startup delay into account. In cases where
40 # the electronic load is already sinking, less settling time may be needed.
41 session.source_delay = source_delay
42
43 with session.initiate():
44 session.wait_for_event(event_id=nidcpower.Event.SOURCE_COMPLETE)
45 measurement = session.measure_multiple()[0]
46 in_compliance = session.query_in_compliance()
47 print(f'Channel : {measurement.channel}')
48 print(f'Voltage Measurement : {measurement.voltage:f} V')
49 print(f'Current Measurement : {measurement.current:f} A')
50 print(f'Compliance / Limit Reached: {in_compliance}')
51 print(f'Resistance Measurement : {measurement.voltage / measurement.current:f} Ω')
52 print(f'Power Measurement : {measurement.voltage * measurement.current:f} W')
53
54 session.reset()
55
56
57def _main(argsv):
58 parser = argparse.ArgumentParser(
59 description=(
60 'Demonstrates how to use the Constant Resistance Output Function to force a resistance'
61 ' level on the electronic load and how to use the Constant Power Output Function to'
62 ' force a power level on the electronic load.'
63 ),
64 formatter_class=argparse.ArgumentDefaultsHelpFormatter
65 )
66 parser.add_argument('-n', '--resource-name', default='PXI1Slot2/0', help='Resource names of NI electronic loads')
67 parser.add_argument('-o', '--output-function', default='CONSTANT_RESISTANCE', type=str, choices=('CONSTANT_RESISTANCE', 'CONSTANT_POWER'), help='Output function')
68 parser.add_argument('-rl', '--constant-resistance-level', default=15.0, type=float, help='Constant resistance level (Ω)')
69 parser.add_argument('-rr', '--constant-resistance-level-range', default=1.0e3, type=float, help='Constant resistance level range (Ω)')
70 parser.add_argument('-rc', '--constant-resistance-current-limit', default=800.0e-3, type=float, help='Constant resistance current limit (A)')
71 parser.add_argument('-pl', '--constant-power-level', default=7.0, type=float, help='Constant power level (W)')
72 parser.add_argument('-pr', '--constant-power-level-range', default=300.0, type=float, help='Constant power level range (W)')
73 parser.add_argument('-pc', '--constant-power-current-limit', default=800.0e-3, type=float, help='Constant power current limit (A)')
74 parser.add_argument('-s', '--source-delay', default=1.0, type=float, help='Source delay (s)')
75 parser.add_argument('-op', '--option-string', default='', type=str, help='Option String')
76 args = parser.parse_args(argsv)
77 example(
78 resource_name=args.resource_name,
79 options=args.option_string,
80 output_function=getattr(nidcpower.OutputFunction, args.output_function),
81 constant_resistance_level=args.constant_resistance_level,
82 constant_resistance_level_range=args.constant_resistance_level_range,
83 constant_resistance_current_limit=args.constant_resistance_current_limit,
84 constant_power_level=args.constant_power_level,
85 constant_power_level_range=args.constant_power_level_range,
86 constant_power_current_limit=args.constant_power_current_limit,
87 source_delay=args.source_delay,
88 )
89
90
91def main():
92 _main(sys.argv[1:])
93
94
95def test_example():
96 example(
97 resource_name='PXI1Slot2/0',
98 options={'simulate': True, 'driver_setup': {'Model': '4051', 'BoardType': 'PXIe', }, },
99 output_function=nidcpower.OutputFunction.CONSTANT_RESISTANCE,
100 constant_resistance_level=15.0,
101 constant_resistance_level_range=1.0e3,
102 constant_resistance_current_limit=800.0e-3,
103 constant_power_level=7.0,
104 constant_power_level_range=300.0,
105 constant_power_current_limit=800.0e-3,
106 source_delay=1.0,
107 )
108
109
110def test_main():
111 cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4051; BoardType:PXIe', ]
112 _main(cmd_line)
113
114
115if __name__ == '__main__':
116 main()
nidcpower_lcr_source_ac_voltage.py
1#!/usr/bin/python
2
3import argparse
4import nidcpower
5import sys
6
7
8def example(
9 resource_name,
10 options,
11 lcr_frequency,
12 lcr_impedance_range,
13 cable_length,
14 lcr_voltage_rms,
15 lcr_dc_bias_source,
16 lcr_dc_bias_voltage_level,
17 lcr_measurement_time,
18 lcr_custom_measurement_time,
19 lcr_source_delay_mode,
20 source_delay,
21):
22 with nidcpower.Session(resource_name=resource_name, options=options) as session:
23 # Configure the session.
24 session.instrument_mode = nidcpower.InstrumentMode.LCR
25 session.lcr_stimulus_function = nidcpower.LCRStimulusFunction.VOLTAGE
26 session.lcr_frequency = lcr_frequency
27 session.lcr_impedance_range = lcr_impedance_range
28 session.cable_length = cable_length
29 session.lcr_voltage_amplitude = lcr_voltage_rms
30 session.lcr_dc_bias_source = lcr_dc_bias_source
31 session.lcr_dc_bias_voltage_level = lcr_dc_bias_voltage_level
32 session.lcr_measurement_time = lcr_measurement_time
33 session.lcr_custom_measurement_time = lcr_custom_measurement_time
34 session.lcr_source_delay_mode = lcr_source_delay_mode
35 session.source_delay = source_delay
36
37 with session.initiate():
38 # Low frequencies require longer settling times than the default timeout for
39 # wait_for_event(), hence 5.0s is set here as a reasonable timeout value
40 session.wait_for_event(event_id=nidcpower.Event.SOURCE_COMPLETE, timeout=5.0)
41 measurements = session.measure_multiple_lcr()
42 for measurement in measurements:
43 print(measurement)
44
45 session.reset()
46
47
48def _main(argsv):
49 parser = argparse.ArgumentParser(
50 description='Output the specified AC voltage and DC bias voltage, then takes LCR measurements',
51 formatter_class=argparse.ArgumentDefaultsHelpFormatter
52 )
53 parser.add_argument('-n', '--resource-name', default='PXI1Slot2/0', help='Resource names of NI SMUs')
54 parser.add_argument('-f', '--lcr-frequency', default=10.0e3, type=float, help='LCR frequency (Hz)')
55 parser.add_argument('-i', '--lcr-impedance-range', default=100.0, type=float, help='LCR impedance range (Ω)')
56 parser.add_argument('-c', '--cable-length', default='NI_STANDARD_2M', type=str, choices=tuple(nidcpower.CableLength.__members__.keys()), help='Cable length')
57 parser.add_argument('-v', '--lcr-voltage-rms', default=700.0e-3, type=float, help='LCR voltage RMS (V RMS)')
58 parser.add_argument('-d', '--lcr-dc-bias-source', default='OFF', type=str, choices=tuple(nidcpower.LCRDCBiasSource.__members__.keys()), help='LCR DC bias source')
59 parser.add_argument('-dv', '--lcr-dc-bias-voltage_level', default=0.0, type=float, help='LCR DC bias voltage (V)')
60 parser.add_argument('-t', '--lcr-measurement-time', default='MEDIUM', type=str, choices=tuple(nidcpower.LCRMeasurementTime.__members__.keys()), help='LCR measurement time')
61 parser.add_argument('-ct', '--lcr-custom-measurement-time', default=10.0e-3, type=float, help='LCR custom measurement time (s)')
62 parser.add_argument('-sm', '--lcr-source-delay-mode', default='AUTOMATIC', type=str, choices=tuple(nidcpower.LCRSourceDelayMode.__members__.keys()), help='LCR source delay mode')
63 parser.add_argument('-s', '--source-delay', default=16.66e-3, type=float, help='Source delay (s)')
64 parser.add_argument('-op', '--option-string', default='', type=str, help='Option String')
65 args = parser.parse_args(argsv)
66 example(
67 resource_name=args.resource_name,
68 options=args.option_string,
69 lcr_frequency=args.lcr_frequency,
70 lcr_impedance_range=args.lcr_impedance_range,
71 cable_length=getattr(nidcpower.CableLength, args.cable_length),
72 lcr_voltage_rms=args.lcr_voltage_rms,
73 lcr_dc_bias_source=getattr(nidcpower.LCRDCBiasSource, args.lcr_dc_bias_source),
74 lcr_dc_bias_voltage_level=args.lcr_dc_bias_voltage_level,
75 lcr_measurement_time=getattr(nidcpower.LCRMeasurementTime, args.lcr_measurement_time),
76 lcr_custom_measurement_time=args.lcr_custom_measurement_time,
77 lcr_source_delay_mode=getattr(nidcpower.LCRSourceDelayMode, args.lcr_source_delay_mode),
78 source_delay=args.source_delay,
79 )
80
81
82def main():
83 _main(sys.argv[1:])
84
85
86def test_example():
87 example(
88 resource_name='PXI1Slot2/0',
89 options={'simulate': True, 'driver_setup': {'Model': '4190', 'BoardType': 'PXIe', }, },
90 lcr_frequency=10.0e3,
91 lcr_impedance_range=100.0,
92 cable_length=nidcpower.CableLength.NI_STANDARD_2M,
93 lcr_voltage_rms=700.0e-3,
94 lcr_dc_bias_source=nidcpower.LCRDCBiasSource.OFF,
95 lcr_dc_bias_voltage_level=0.0,
96 lcr_measurement_time=nidcpower.LCRMeasurementTime.MEDIUM,
97 lcr_custom_measurement_time=10.0e-3,
98 lcr_source_delay_mode=nidcpower.LCRSourceDelayMode.AUTOMATIC,
99 source_delay=16.66e-3,
100 )
101
102
103def test_main():
104 cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4190; BoardType:PXIe', ]
105 _main(cmd_line)
106
107
108if __name__ == '__main__':
109 main()
nidcpower_measure_record.py
1#!/usr/bin/python
2
3import argparse
4import nidcpower
5import sys
6
7
8def example(resource_name, options, voltage, length):
9 with nidcpower.Session(resource_name=resource_name, options=options) as session:
10 # Configure the session.
11 session.measure_record_length = length
12 session.measure_record_length_is_finite = True
13 session.measure_when = nidcpower.MeasureWhen.AUTOMATICALLY_AFTER_SOURCE_COMPLETE
14 session.output_function = nidcpower.OutputFunction.DC_VOLTAGE
15 session.voltage_level = voltage
16
17 session.commit()
18 print(f'Effective measurement rate: {session.measure_record_delta_time / 1} S/s')
19
20 print('Channel Num Voltage Current In Compliance')
21 row_format = '{0:15} {1:3d} {2:8.6f} {3:8.6f} {4}'
22 with session.initiate():
23 channel_indices = f'0-{session.channel_count - 1}'
24 channels = session.get_channel_names(channel_indices)
25 for i, channel_name in enumerate(channels):
26 samples_acquired = 0
27 while samples_acquired < length:
28 measurements = session.channels[channel_name].fetch_multiple(count=session.fetch_backlog)
29 samples_acquired += len(measurements)
30 for i in range(len(measurements)):
31 print(row_format.format(channel_name, i, measurements[i].voltage, measurements[i].current, measurements[i].in_compliance))
32
33
34def _main(argsv):
35 parser = argparse.ArgumentParser(description='Outputs the specified voltage, then takes the specified number of voltage and current readings.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
36 parser.add_argument('-n', '--resource-name', default='PXI1Slot2/0, PXI1Slot3/0-1', help='Resource names of NI SMUs.')
37 parser.add_argument('-l', '--length', default='20', type=int, help='Measure record length per channel')
38 parser.add_argument('-v', '--voltage', default=5.0, type=float, help='Voltage level (V)')
39 parser.add_argument('-op', '--option-string', default='', type=str, help='Option String')
40 args = parser.parse_args(argsv)
41 example(args.resource_name, args.option_string, args.voltage, args.length)
42
43
44def main():
45 _main(sys.argv[1:])
46
47
48def test_example():
49 options = {'simulate': True, 'driver_setup': {'Model': '4162', 'BoardType': 'PXIe', }, }
50 example('PXI1Slot2/0, PXI1Slot3/1', options, 5.0, 20)
51
52
53def test_main():
54 cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4162; BoardType:PXIe', ]
55 _main(cmd_line)
56
57
58if __name__ == '__main__':
59 main()
nidcpower_sink_dc_current_into_electronic_load.py
1#!/usr/bin/python
2
3import argparse
4import nidcpower
5import sys
6
7
8def example(
9 resource_name,
10 options,
11 current_level,
12 current_level_range,
13 voltage_limit_range,
14 source_delay,
15 output_shorted,
16 conduction_voltage_mode,
17 conduction_voltage_on_threshold,
18 conduction_voltage_off_threshold,
19 current_level_rising_slew_rate,
20 current_level_falling_slew_rate,
21):
22 with nidcpower.Session(resource_name=resource_name, options=options) as session:
23 # Configure the session.
24 session.source_mode = nidcpower.SourceMode.SINGLE_POINT
25
26 session.output_function = nidcpower.OutputFunction.DC_CURRENT
27 session.current_level = current_level
28 session.current_level_range = current_level_range
29 session.voltage_limit_range = voltage_limit_range
30 # Note that the voltage_limit property is not applicable for electronic loads and is not
31 # configured in this example. If you change the output_function, configure the appropriate
32 # level, limit and range properties corresponding to your selected output_function.
33
34 session.source_delay = source_delay
35
36 # Configure the output_shorted property to specify whether to simulate a short circuit in
37 # the electronic load.
38 session.output_shorted = output_shorted
39
40 # If you set the output_function property to nidcpower.OutputFunction.DC_CURRENT or
41 # nidcpower.OutputFunction.CONSTANT_POWER, set the conduction_voltage_mode to
42 # nidcpower.ConductionVoltageMode.AUTOMATIC or nidcpower.ConductionVoltageMode.ENABLED to
43 # enable Conduction Voltage.
44 # If you set the output_function property to nidcpower.OutputFunction.DC_VOLTAGE or
45 # nidcpower.OutputFunction.CONSTANT_RESISTANCE, set the conduction_voltage_mode to
46 # nidcpower.ConductionVoltageMode.AUTOMATIC or nidcpower.ConductionVoltageMode.DISABLED to
47 # disable Conduction Voltage.
48 # If Conduction Voltage is enabled, set the conduction_voltage_on_threshold to configure the
49 # electronic load to start sinking current when the input voltage exceeds the configured
50 # threshold, and set the conduction_voltage_off_threshold to configure the electronic load
51 # to stop sinking current when the input voltage falls below the threshold.
52 # If Conduction Voltage is disabled, the electronic load attempts to sink the desired level
53 # regardless of the input voltage.
54 session.conduction_voltage_mode = conduction_voltage_mode
55 session.conduction_voltage_on_threshold = conduction_voltage_on_threshold
56 session.conduction_voltage_off_threshold = conduction_voltage_off_threshold
57
58 # If you set the output_function property to nidcpower.OutputFunction.DC_CURRENT, configure
59 # the current_level_rising_slew_rate and current_level_falling_slew_rate, in amps per
60 # microsecond, to control the rising and falling current slew rates of the electronic load
61 # while sinking current.
62 # When the output_function property is set to a value other than
63 # nidcpower.OutputFunction.DC_CURRENT, these properties have no effect.
64 session.current_level_rising_slew_rate = current_level_rising_slew_rate
65 session.current_level_falling_slew_rate = current_level_falling_slew_rate
66
67 with session.initiate():
68 session.wait_for_event(event_id=nidcpower.Event.SOURCE_COMPLETE)
69 measurement = session.measure_multiple()[0]
70 in_compliance = session.query_in_compliance()
71 print(f'Channel : {measurement.channel}')
72 print(f'Voltage Measurement : {measurement.voltage:f} V')
73 print(f'Current Measurement : {measurement.current:f} A')
74 print(f'Compliance / Limit Reached: {in_compliance}')
75
76 session.reset()
77
78
79def _main(argsv):
80 parser = argparse.ArgumentParser(
81 description=(
82 'Demonstrates how to use the DC Current Output Function to force a current into the'
83 ' electronic load and how to configure the electronic load with the Output Shorted,'
84 ' Conduction Voltage and Current Level Slew Rate features.'
85 ),
86 formatter_class=argparse.ArgumentDefaultsHelpFormatter
87 )
88 parser.add_argument('-n', '--resource-name', default='PXI1Slot2/0', help='Resource names of NI electronic loads')
89 parser.add_argument('-cl', '--current-level', default=1.0, type=float, help='Current level (A)')
90 parser.add_argument('-cr', '--current-level-range', default=40.0, type=float, help='Current level range (A)')
91 parser.add_argument('-vr', '--voltage-limit-range', default=60.0, type=float, help='Voltage limit range (V)')
92 parser.add_argument('-s', '--source-delay', default=0.5, type=float, help='Source delay (s)')
93 parser.add_argument('-os', '--output-shorted', default=False, action='store_true', help='Output shorted')
94 parser.add_argument('-cv', '--conduction-voltage-mode', default='AUTOMATIC', type=str, choices=tuple(nidcpower.ConductionVoltageMode.__members__.keys()), help='Conduction voltage mode')
95 parser.add_argument('-nt', '--conduction-voltage-on-threshold', default=1.0, type=float, help='Conduction voltage on threshold (V)')
96 parser.add_argument('-ot', '--conduction-voltage-off-threshold', default=0.0, type=float, help='Conduction voltage off threshold (V)')
97 parser.add_argument('-rs', '--current-level-rising-slew-rate', default=24.0, type=float, help='Current level rising slew rate (A/µs)')
98 parser.add_argument('-fs', '--current-level-falling-slew-rate', default=24.0, type=float, help='Current level falling slew rate (A/µs)')
99 parser.add_argument('-op', '--option-string', default='', type=str, help='Option String')
100 args = parser.parse_args(argsv)
101 example(
102 resource_name=args.resource_name,
103 options=args.option_string,
104 current_level=args.current_level,
105 current_level_range=args.current_level_range,
106 voltage_limit_range=args.voltage_limit_range,
107 source_delay=args.source_delay,
108 output_shorted=args.output_shorted,
109 conduction_voltage_mode=getattr(nidcpower.ConductionVoltageMode, args.conduction_voltage_mode),
110 conduction_voltage_on_threshold=args.conduction_voltage_on_threshold,
111 conduction_voltage_off_threshold=args.conduction_voltage_off_threshold,
112 current_level_rising_slew_rate=args.current_level_rising_slew_rate,
113 current_level_falling_slew_rate=args.current_level_falling_slew_rate,
114 )
115
116
117def main():
118 _main(sys.argv[1:])
119
120
121def test_example():
122 example(
123 resource_name='PXI1Slot2/0',
124 options={'simulate': True, 'driver_setup': {'Model': '4051', 'BoardType': 'PXIe', }, },
125 current_level=1.0,
126 current_level_range=40.0,
127 voltage_limit_range=60.0,
128 source_delay=0.5,
129 output_shorted=False,
130 conduction_voltage_mode=nidcpower.ConductionVoltageMode.AUTOMATIC,
131 conduction_voltage_on_threshold=1.0,
132 conduction_voltage_off_threshold=0.0,
133 current_level_rising_slew_rate=24.0,
134 current_level_falling_slew_rate=24.0,
135 )
136
137
138def test_main():
139 cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4051; BoardType:PXIe', ]
140 _main(cmd_line)
141
142
143if __name__ == '__main__':
144 main()
nidcpower_source_delay_measure.py
1#!/usr/bin/python
2
3import argparse
4import hightime
5import nidcpower
6import sys
7
8
9def print_fetched_measurements(measurements):
10 print(f' Voltage : {measurements[0].voltage:f} V')
11 print(f' Current: {measurements[0].current:f} A')
12 print(f' In compliance: {measurements[0].in_compliance}')
13
14
15def example(resource_name, options, voltage1, voltage2, delay):
16 timeout = hightime.timedelta(seconds=(delay + 1.0))
17
18 with nidcpower.Session(resource_name=resource_name, options=options) as session:
19 # Configure the session.
20 session.source_mode = nidcpower.SourceMode.SINGLE_POINT
21 session.output_function = nidcpower.OutputFunction.DC_VOLTAGE
22 session.current_limit = .06
23 session.voltage_level_range = 5.0
24 session.current_limit_range = .06
25 session.source_delay = hightime.timedelta(seconds=delay)
26 session.measure_when = nidcpower.MeasureWhen.AUTOMATICALLY_AFTER_SOURCE_COMPLETE
27 session.voltage_level = voltage1
28
29 with session.initiate():
30 channel_indices = f'0-{session.channel_count - 1}'
31 channels = session.get_channel_names(channel_indices)
32 for channel_name in channels:
33 print(f'Channel: {channel_name}')
34 print('---------------------------------')
35 print('Voltage 1:')
36 print_fetched_measurements(session.channels[channel_name].fetch_multiple(count=1, timeout=timeout))
37 session.voltage_level = voltage2 # on-the-fly set
38 print('Voltage 2:')
39 print_fetched_measurements(session.channels[channel_name].fetch_multiple(count=1, timeout=timeout))
40 session.output_enabled = False
41 print('')
42
43
44def _main(argsv):
45 parser = argparse.ArgumentParser(description='Outputs voltage 1, waits for source delay, and then takes a measurement. Then orepeat with voltage 2.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
46 parser.add_argument('-n', '--resource-name', default='PXI1Slot2/0, PXI1Slot3/0-1', help='Resource names of an NI SMUs.')
47 parser.add_argument('-v1', '--voltage1', default=1.0, type=float, help='Voltage level 1 (V)')
48 parser.add_argument('-v2', '--voltage2', default=2.0, type=float, help='Voltage level 2 (V)')
49 parser.add_argument('-d', '--delay', default=0.05, type=float, help='Source delay (s)')
50 parser.add_argument('-op', '--option-string', default='', type=str, help='Option String')
51 args = parser.parse_args(argsv)
52 example(args.resource_name, args.option_string, args.voltage1, args.voltage2, args.delay)
53
54
55def main():
56 _main(sys.argv[1:])
57
58
59def test_main():
60 cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4162; BoardType:PXIe', ]
61 _main(cmd_line)
62
63
64def test_example():
65 options = {'simulate': True, 'driver_setup': {'Model': '4162', 'BoardType': 'PXIe', }, }
66 example('PXI1Slot2/0, PXI1Slot3/1', options, 1.0, 2.0, 0.05)
67
68
69if __name__ == '__main__':
70 main()
71
72