|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +import argparse |
| 4 | +import nidcpower |
| 5 | +import sys |
| 6 | + |
| 7 | + |
| 8 | +def 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 | + |
| 79 | +def _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 | + |
| 117 | +def main(): |
| 118 | + _main(sys.argv[1:]) |
| 119 | + |
| 120 | + |
| 121 | +def 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 | + |
| 138 | +def test_main(): |
| 139 | + cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4051; BoardType:PXIe', ] |
| 140 | + _main(cmd_line) |
| 141 | + |
| 142 | + |
| 143 | +if __name__ == '__main__': |
| 144 | + main() |
0 commit comments