Пример #1
0
def test_channel_format_types():
    with nifgen.Session(
            '', [0, 1], False,
            'Simulate=1, DriverSetup=Model:5433 (2CH);BoardType:PXIe'
    ) as simulated_session:
        assert simulated_session.num_channels == 2
    with nifgen.Session(
            '', range(2), False,
            'Simulate=1, DriverSetup=Model:5433 (2CH);BoardType:PXIe'
    ) as simulated_session:
        assert simulated_session.num_channels == 2
    with nifgen.Session(
            '', '0,1', False,
            'Simulate=1, DriverSetup=Model:5433 (2CH);BoardType:PXIe'
    ) as simulated_session:
        assert simulated_session.num_channels == 2
    with nifgen.Session(
            '', None, False,
            'Simulate=1, DriverSetup=Model:5433 (2CH); BoardType:PXIe'
    ) as simulated_session:
        assert simulated_session.num_channels == 2
    with nifgen.Session(
            resource_name='',
            reset_device=False,
            options='Simulate=1, DriverSetup=Model:5433 (2CH); BoardType:PXIe'
    ) as simulated_session:
        assert simulated_session.num_channels == 2
Пример #2
0
    def initialize(self, deviceName, triggerMode):
        try:
            if(deviceName != ''):
                self.session = None
                self.wfm_handles = list()
                self.reportTime = ms()
                with nifgen.Session(deviceName) as session:
                    self.maxRate = session.arb_sample_rate
                    self.source0 = self.Add_AOSource('0', -1, 1, 0.1)
                    self.source1 = self.Add_AOSource('1', -1, 1, 0.1)

                self.session = nifgen.Session(deviceName)
        except:
            pass

        self.initialized.emit()
Пример #3
0
def session_5421():
    with daqmx_sim_db_lock:
        simulated_session = nifgen.Session(
            '', '0', False, 'Simulate=1, DriverSetup=Model:5421;BoardType:PXI')
    yield simulated_session
    with daqmx_sim_db_lock:
        simulated_session.close()
Пример #4
0
def test_get_self_cal_last_date_and_time():
    try:
        with nifgen.Session('', '0', False, 'Simulate=1, DriverSetup=Model:5421;BoardType:PXI') as session:  # Simulated 5433 returns unrecoverable error when calling get_self_cal_last_date_and_time()
            session.get_self_cal_last_date_and_time()
            assert False
    except nifgen.Error as e:
        assert e.code == -1074118632  # This operation is not supported for simulated device
Пример #5
0
def example(resource_name, options, shape, channel):
    with nifgen.Session(resource_name=resource_name, options=options, channel_name=channel) as session:
        # CONFIGURATION
        # 1 - Set the mode to Script
        session.output_mode = nifgen.OutputMode.SCRIPT

        # 2 - Configure Trigger:
        # SOFTWARE TRIGGER: used in the script
        session.script_triggers[0].script_trigger_type = nifgen.ScriptTriggerType.SOFTWARE_EDGE  # TRIG_NONE / DIGITAL_EDGE / DIGITAL_LEVEL / SOFTWARE_EDGE
        session.script_triggers[0].digital_edge_script_trigger_edge = nifgen.ScriptTriggerDigitalEdgeEdge.RISING  # RISING / FAILING

        # 3 - Calculate and write different waveform data to the device's onboard memory
        session.channels[channel].write_waveform('sine', calculate_sinewave())        # (waveform_name, data)
        session.channels[channel].write_waveform('rampup', calculate_rampup())
        session.channels[channel].write_waveform('rampdown', calculate_rampdown())
        session.channels[channel].write_waveform('square', calculate_square())
        session.channels[channel].write_waveform('triangle', calculate_triangle())
        session.channels[channel].write_waveform('noise', calculate_gaussian_noise())

        # 4 - Script to generate
        # supported shapes: SINE / SQUARE / TRIANGLE / RAMPUP / RAMPDOWN / NOISE / MULTI
        script_name = 'script{}'.format(shape.lower())
        num_triggers = 6 if shape.upper() == 'MULTI' else 1  # Only multi needs two triggers, all others need one

        session.channels[channel].write_script(SCRIPT_ALL)
        session.script_to_generate = script_name

        # LAUNCH
        with session.initiate():
            for x in range(num_triggers):
                time.sleep(10)
                session.script_triggers[0].send_software_edge_trigger()
Пример #6
0
def test_error_message():
    try:
        # We pass in an invalid model name to force going to error_message
        with nifgen.Session('', '0', False, 'Simulate=1, DriverSetup=Model:invalid_model (2CH);BoardType:PXIe'):
            assert False
    except nifgen.Error as e:
        assert e.code == -1074134944
        assert e.description.find('Insufficient location information or resource not present in the system.') != -1
Пример #7
0
def test_get_ext_cal_last_date_and_time():
    with nifgen.Session(
            '', False, 'Simulate=1, DriverSetup=Model:5421;BoardType:PXI'
    ) as session:  # 5433 throws out unrecoverable error on calling get_ext_cal_last_date_and_time()
        try:
            session.get_ext_cal_last_date_and_time()
            assert False
        except nifgen.Error as e:
            assert e.code == -1074118632  # This operation is not supported for simulated device
Пример #8
0
def example(resource_name, options, samples, gain, offset, gen_time):
    waveform_data = create_waveform_data(samples)
    with nifgen.Session(resource_name=resource_name,
                        options=options) as session:
        session.output_mode = nifgen.OutputMode.ARB
        waveform = session.create_waveform(waveform_data_array=waveform_data)
        session.configure_arb_waveform(waveform_handle=waveform,
                                       gain=gain,
                                       offset=offset)
        with session.initiate():
            time.sleep(gen_time)
Пример #9
0
def test_channels_rep_cap():
    with nifgen.Session(
            '', '', False,
            'Simulate=1, DriverSetup=Model:5433 (2CH);BoardType:PXIe'
    ) as session:
        session.func_amplitude = 0.5
        assert session.channels[0:1].func_amplitude == 0.5

        session.channels[0].func_amplitude = 1
        assert session.channels[0].func_amplitude == 1
        assert session.channels[1].func_amplitude == 0.5
def example(resource_name, options, waveform, frequency, amplitude, offset,
            phase, gen_time):
    with nifgen.Session(resource_name=resource_name,
                        options=options) as session:
        session.output_mode = nifgen.OutputMode.FUNC
        session.configure_standard_waveform(waveform=nifgen.Waveform[waveform],
                                            amplitude=amplitude,
                                            frequency=frequency,
                                            dc_offset=offset,
                                            start_phase=phase)
        with session.initiate():
            time.sleep(gen_time)
Пример #11
0
def test_create_advanced_arb_sequence_wrong_size():
    with nifgen.Session('', '0', False, 'Simulate=1, DriverSetup=Model:5421;BoardType:PXI') as session:  # TODO(marcoskirsch): Use 5433 once internal NI bug 677115 is fixed.
        waveform_data = [x * (1.0 / 256.0) for x in range(256)]
        waveform_handles_array = [session.create_waveform(waveform_data), session.create_waveform(waveform_data), session.create_waveform(waveform_data)]
        marker_location_array = [0, 16]
        loop_counts_array = [10, 20, 30]
        session.output_mode = nifgen.OutputMode.SEQ
        # Test relies on value of sequence handles starting at a known value and incrementing sequentially. Hardly ideal.
        try:
            session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, marker_location_array=marker_location_array)
            assert False
        except ValueError:
            pass
Пример #12
0
def example(resource_name1, resource_name2, options, waveform, gen_time):
    with nifgen.Session(resource_name=resource_name1,
                        options=options) as session1, nifgen.Session(
                            resource_name=resource_name2,
                            options=options) as session2:
        session_list = [session1, session2]
        for session in session_list:
            session.output_mode = nifgen.OutputMode.FUNC
            session.configure_standard_waveform(
                waveform=nifgen.Waveform[waveform],
                amplitude=1.0,
                frequency=1000,
                dc_offset=0.0,
                start_phase=0.0)
        session1.start_trigger_type = nifgen.StartTriggerType.SOFTWARE_EDGE
        session2.start_trigger_type = nifgen.StartTriggerType.DIGITAL_EDGE
        session2.digital_edge_start_trigger_edge = nifgen.StartTriggerDigitalEdgeEdge.RISING
        session2.digital_edge_start_trigger_source = '/' + resource_name1 + '/0/StartTrigger'
        with session2.initiate():
            with session1.initiate():
                session1.send_software_edge_trigger(nifgen.Trigger.START)
                time.sleep(gen_time)
Пример #13
0
def test_create_advanced_arb_sequence():
    with nifgen.Session('', '0', False, 'Simulate=1, DriverSetup=Model:5421;BoardType:PXI') as session:  # TODO(marcoskirsch): Use 5433 once internal NI bug 677115 is fixed.
        seq_handle_base = 100000  # This is not necessary on 5433 because handles start at 0.
        waveform_data = [x * (1.0 / 256.0) for x in range(256)]
        waveform_handles_array = [session.create_waveform(waveform_data), session.create_waveform(waveform_data), session.create_waveform(waveform_data)]
        marker_location_array = [0, 16, 32]
        sample_counts_array = [256, 128, 64]
        loop_counts_array = [10, 20, 30]
        session.output_mode = nifgen.OutputMode.SEQ
        # Test relies on value of sequence handles starting at a known value and incrementing sequentially. Hardly ideal.
        assert ([], seq_handle_base + 0) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array)
        assert ([], seq_handle_base + 1) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, sample_counts_array=sample_counts_array)
        assert (marker_location_array, seq_handle_base + 2) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, marker_location_array=marker_location_array)
        assert (marker_location_array, seq_handle_base + 3) == session.create_advanced_arb_sequence(waveform_handles_array, loop_counts_array=loop_counts_array, sample_counts_array=sample_counts_array, marker_location_array=marker_location_array)
Пример #14
0
def initialize_sessions(tsm: SMContext, options: dict = {}):
    """Opens sessions for all instrument channels that are associated with the tsm context"""
    instrument_names = tsm.get_all_nifgen_instrument_names()
    for instrument_name in instrument_names:
        session = nifgen.Session(instrument_name,
                                 reset_device=True,
                                 options=options)
        tsm.set_nifgen_session(instrument_name, session)
    dut_pins, system_pins = tsm.get_pin_names()
    all_pins = dut_pins + system_pins
    instrument_type = nitsm.enums.InstrumentTypeIdConstants.NI_FGEN
    fgen_pins = tsm.filter_pins_by_instrument_type(all_pins, instrument_type,
                                                   "")
    pin_query_context, sessions, channels = tsm.pins_to_nifgen_sessions(
        fgen_pins)
    for fgen_session, channel_list in zip(sessions, channels):
        temp = set(channel_list)
        channels = list(temp)
        fgen_session.channels = channels  # configure channels
Пример #15
0
def session():
    with nifgen.Session(
            '', False,
            'Simulate=1, DriverSetup=Model:5433 (2CH);BoardType:PXIe'
    ) as simulated_session:
        yield simulated_session
Пример #16
0
def test_get_hardware_state():
    with nifgen.Session(
            '', False, 'Simulate=1, DriverSetup=Model:5421;BoardType:PXI'
    ) as session:  # Function or method not supported for 5413/23/33
        assert session.get_hardware_state() == nifgen.HardwareState.IDLE
Пример #17
0
parser.add_argument('-a',
                    '--amplitude',
                    default=1.0,
                    type=float,
                    help='Amplitude (Vpk-pk)')
parser.add_argument('-o',
                    '--offset',
                    default=0.0,
                    type=float,
                    help='DC Offset (V)')
parser.add_argument('-p',
                    '--phase',
                    default=0.0,
                    type=float,
                    help='Start Phase (deg)')
args = parser.parse_args()

with nifgen.Session(args.name) as session:
    session.output_mode = nifgen.OutputMode.NIFGEN_VAL_OUTPUT_FUNC  # TODO(marcoskirsch): name to change per #553
    session.configure_standard_waveform(
        waveform=nifgen.Waveform[args.waveform],
        amplitude=args.amplitude,
        frequency=args.frequency,
        dc_offset=args.offset,
        start_phase=args.phase)
    with session.initiate():
        try:
            input("Press Enter to abort generation...")
        except SyntaxError:
            pass
Пример #18
0
import nifgen, numpy as np, scipy.signal, time
# Tested using nifgen v 1.0.0 (highest version number found using pip)

with nifgen.Session('ARB') as session:
    print('Starting')
    session.abort()
    session.clear_arb_memory()

    session.output_mode = nifgen.OutputMode.ARB
    session.arb_sample_rate = 100000

    print('Arb sample rate set to: ' + str(session.arb_sample_rate))

    # Generating a chirp waveform +/- 0.5v from 100-1000 Hz for 50ms
    times = np.arange(0, 0.001, 1 / session.arb_sample_rate)
    #wave = scipy.signal.chirp(times, 1, times[-1], 1)
    #wave = np.multiply(wave, 0.5)
    #wave = np.append(wave, np.flip(wave, 0))
    wave = np.random.rand(12)
    print(wave)

    print('Generated chirp waveform for length: ' + str(wave.shape[0]))

    wfm = session.channels[0].create_waveform(wave)
    print('Creating waveform, should be (length/rate) seconds long: ' +
          str(wave.shape[0] / session.arb_sample_rate))
    session.trigger_mode = nifgen.TriggerMode.SINGLE
    #session.start_trigger_type = nifgen.StartTriggerType.TRIG_NONE
    session.channels[0].configure_arb_waveform(wfm, 1, 0.0)
    print('Configured arb waveform on card, gain = 1 and offset = 0.0')