Пример #1
0
def pins_to_session_sessions_info(tsm: SMContext, pins: PinsArg):
    """
    Returns a properly filled object of the type MultipleSessions with a session per each
    site defined in the pin map
    Args:
        tsm: Pin context defined by pin map
        pins: The name of the pin(s) or pin group(s) to translate to a task.
    Return:
        Multiple_Sessions: An object that tracks the task associated with this pin query. Use this
        object to publish measurements and extract data from a set of measurements.
    """
    if type(pins) == str:
        pins = [pins]
    pin_list = tsm.filter_pins_by_instrument_type(
        pins, nitsm.enums.InstrumentTypeIdConstants.NI_DAQMX, nitsm.enums.Capability.ALL
    )
    print(pin_list)
    (pin_query_contex, task, channel_list) = tsm.pins_to_nidaqmx_task(pin_list)
    sites = tsm.site_numbers
    multiple_session_info = MultipleSessions(pin_query_contex, [])
    for site in sites:
        pin_data = ",".join(pin_list)
        session = _Session(task, channel_list, pin_data, site)
        multiple_session_info.sessions.append(session)
    return multiple_session_info
Пример #2
0
def initialize(tsm: SMContext):  # CHECK
    """
    Initialize the TSM context with all the Abstract switch sessions. Based on the instrument type
    it will create session to individual drivers. so it is essential to define the route in pinmap.
    Args:
        tsm: TSM context where the sessions will be initialized
    """
    switch_names = tsm.get_all_switch_names(instrument_type_id)
    if len(switch_names) == 1:
        dut_pins, sys_pins = tsm.get_pin_names()
        en_pins = []
        for pin in dut_pins + sys_pins:
            if pin.lower().find("en_") == 0:
                en_pins.append(pin)
        en_sessions = []
        for instrument in [
                "niDAQmx", "niDigitalPattern", "782xFPGA", "_niSwitch"
        ]:
            filtered_pins = tsm.filter_pins_by_instrument_type(
                en_pins, instrument, nitsm.enums.Capability.ALL)
            for pin in filtered_pins:
                session = Session(pin, instrument, "", 0, "")
                en_sessions.append(session)
        multi_session = AbstractSession(en_sessions)
        multi_session.set_sessions(tsm, switch_names[0])
    else:
        raise nifpga.ErrorStatus(
            5000,
            ("Unsupported Pin Map for the Abstract Switch."
             "Ensure you only have one abstract switch in the pinmap"),
            "initialize()",
            ["tsm_context"],
            (tsm, ),
        )
Пример #3
0
def clear_task(tsm: SMContext):
    """
    Clears all the tasks in the SMContext. Before clearing, this method will abort all tasks, if
    necessary, and will release any resources the tasks reserved. You cannot use a task after you
    clear it unless you set it again.
    """
    task_ao = tsm.get_all_nidaqmx_tasks("AnalogOutput")
    tasks_ai = tsm.get_all_nidaqmx_tasks("AnalogInput")
    tasks_ai_dsa = tsm.get_all_nidaqmx_tasks("AnalogInputDSA")
    tasks_ao_dsa = tsm.get_all_nidaqmx_tasks("AnalogOutputDSA")
    tasks_do = tsm.get_all_nidaqmx_tasks("DigitalOutput")

    for task in task_ao:
        task.stop()
        task.close()
    for task in tasks_ai:
        task.stop()
        task.close()
    for task in tasks_ai_dsa:
        task.stop()
        task.close()
    for task in tasks_ao_dsa:
        task.stop()
        task.close()
    for task in tasks_do:
        task.stop()
        task.close()
Пример #4
0
def initialize_sessions(tsm_context: SMContext, ldb_type: str = ""):
    """
    Initialize the sessions from TSM context pinmap.
    """
    global debug
    instrument_names, channel_group_ids, channel_lists = tsm_context.get_custom_instrument_names(
        InstrumentTypeId)
    # when the output from a function is unused use _ instead of variables like below
    # instrument_names, channel_group_ids, _ = tsm_context.get_custom_instrument_names(
    # InstrumentTypeId)
    for instrument, group_id in zip(instrument_names, channel_group_ids):
        # target_list = ["PXIe-7822R", "PXIe-7821R", "PXIe-7820R"]
        ref_out = ""
        for target in BoardType:
            try:
                ref_out = open_reference(instrument, target, ldb_type)
            except Exception:  # TODO Check on baku since the condition seems to be up side down
                continue
            else:
                break
        tsm_context.set_custom_session(InstrumentTypeId, instrument, group_id,
                                       ref_out)
    dut_pins, system_pins = tsm_context.get_pin_names(InstrumentTypeId)
    debug = list(
        tsm_context.pins_to_custom_sessions(InstrumentTypeId,
                                            dut_pins + system_pins))
Пример #5
0
def set_sessions(tsm: SMContext, switch_name: str, session: niswitch.Session,
                 channel_grp_id: str):
    """
    Adds the session to the list of switch sessions in tsm context

    Args:
        tsm (SMContext): Semiconductor module Reference from the TestStand.
        switch_name (str): name of the switch
        session (niswitch.Session): session created fo the switch
        channel_grp_id (str): unique id of the channel group
    """
    tsm.set_custom_session(instrument_type_id, switch_name, channel_grp_id,
                           session)
Пример #6
0
def initialize_session(tsm: SMContext):
    """
    creates the sessions for all the niDMM resource string available in the tsm context for
    instruments.

    Args:
        tsm (SMContext): TestStand semiconductor module context
    """

    instrument_list = tsm.get_all_nidmm_instrument_names()
    for instrument in instrument_list:
        session = nidmm.Session(resource_name=instrument, reset_device=True)
        tsm.set_nidmm_session(instrument_name=instrument, session=session)
Пример #7
0
def pins_to_sessions(tsm: SMContext, pins: typing.List[str],
                     sites: typing.List[int]):
    """
    Returns the pin-query context object for the given pins at given sites.

    Args:
        tsm (TSMContext): Semiconductor module Reference from the TestStand.
        pins (typing.List[str]): Pins names defined in the current the pinmap.
        sites (typing.List[int]): if you need to control only on specific sites,
        then provide site numbers. Defaults to [].

    Returns:
        TSMScope object :  for the selected pins. All instrument specific operations
        are available as properties and methods of this object.
    """
    pin_query_context, sessions, channels = tsm.pins_to_nifgen_sessions(pins)
    sites_out, pin_list_per_session = ni_dt_common.pin_query_context_to_channel_list(
        pin_query_context, [], sites)
    sscs: typing.List[_NIFGenSSC] = []
    for session, channel, pin_list in zip(sessions, channels,
                                          pin_list_per_session):
        sscs.append(
            _NIFGenSSC(session=session, channels=channel, pin_list=pin_list))
    fgen_tsm = _NIFGenTSM(sscs)
    return TSMFGen(pin_query_context, fgen_tsm, sites_out)
Пример #8
0
def pins_to_sessions(tsm: SMContext, pins: typing.List[str], sites: typing.List[int] = []):
    """
    Returns the pin-query context object for the given pins at given sites.

    Args:
        tsm (TSMContext): Semiconductor module Reference from the TestStand.
        pins (typing.List[str]): Pins names defined in the current the pinmap.
        sites (typing.List[int], optional): if you need to control only on specific sites,
        then provide site numbers. Defaults to [].

    Returns:
        TSMScope object :  for the selected pins. All instrument specific operations
        are available as properties and methods of this object.
    """
    if len(sites) == 0:
        sites = list(tsm.site_numbers)  # This is tested and works
    pin_query_context, sessions, channels = tsm.pins_to_niscope_sessions(pins)
    sites, pin_lists = _pin_query_context_to_channel_list(pin_query_context, [], sites)
    # sites, pin_lists = ni_dt_common.pin_query_context_to_channel_list(
    # pin_query_context, [], sites)
    sscs = [
        _NIScopeSSC(session, channel, pin_list)
        for session, channel, pin_list in zip(sessions, channels, pin_lists)
    ]
    scope_tsm = _NIScopeTSM(sscs)
    return TSMScope(pin_query_context, scope_tsm, sites)
Пример #9
0
def pins_to_sessions(
    tsm_context: SMContext,
    pins: typing.Union[str, typing.Sequence[str]],
    site_numbers: typing.Union[int, typing.Sequence[int]] = [],
):
    """
    Returns an object that contains a list of sessions generated for the provided pins.
    """
    if type(pins) == str:
        pins = [pins]
    if type(site_numbers) == int:
        site_numbers = [site_numbers]
    (
        pin_query_context,
        session_data,
        channel_group_ids,
        channels_lists,
    ) = tsm_context.pins_to_custom_sessions(InstrumentTypeId, pins)
    session_data: typing.Tuple[nifpga.Session]
    channel_list, sites = ni_dt_common.pin_query_context_to_channel_list(
        pin_query_context, [], site_numbers)
    new_sessions = []
    for session, channel_id, channel, site in zip(session_data,
                                                  channel_group_ids,
                                                  channels_lists, sites):
        new_sessions.append(_SSCFPGA(session, channel_id, channel, site))
    return TSMFPGA(pin_query_context, new_sessions, channel_list)
Пример #10
0
def pins_to_task_and_connect(tsm: SMContext, task_name: PinsArg,
                             pins: PinsArg):
    """
    Returns a pin query contex and a list of properties defined in the pin map.
    The list of properties returned can be used to fill a new object type MultipleSessions
    Args:
        tsm: Pin context defined by pin map
        task_name: The name of the pin(s) or pin group(s) to translate to a set of tasks.
        pins: The name of the pin(s) or pin group(s) to translate to a set of abstract sessions.
    Return:
        session: An object that tracks the tasks associated with this pin query. Use this object to
        publish
        measurements and extract data from a set of measurements.
    """
    pin_list = tsm.filter_pins_by_instrument_type(pins, "abstinst",
                                                  nitsm.enums.Capability.ALL)
    multiple_session_info = nidevtools.daqmx.pins_to_session_sessions_info(
        tsm, task_name)
    sessions = []
    for pin in pin_list:
        sessions += pins_to_sessions_sessions_info(tsm, pin).enable_pins
    multi_session = AbstractSession(sessions)
    if len(sessions) != 0:
        multi_session.connect_sessions_info(tsm)
    return multiple_session_info
Пример #11
0
def initialize_sessions(tsm: SMContext, options: dict = {}):
    """
    Open sessions for all NI-SCOPE instrument channels that are defined in pinmap associated with
    the tsm context

    Args:
        tsm (SMContext): TestStand semiconductor module context
        options: Dictionary containing options for driver initialisation.
    """
    instrument_names = tsm.get_all_niscope_instrument_names()
    for instrument_name in instrument_names:
        session = niscope.Session(instrument_name, reset_device=True, options=options)
        try:
            session.commit()
        except Exception:
            session.reset_device()
        session.configure_chan_characteristics(1e6, -1)
        session.commit()
        tsm.set_niscope_session(instrument_name, session)
Пример #12
0
def close_sessions(tsm_context: SMContext):
    """
    Clears the FPGA session.  Before clearing, this method aborts the session, if necessary, and
    releases any resources the session has reserved. You cannot use a session after you clear it
    unless you recreate the session. If you create the FPGA session object within a loop, use this
    method within the loop after you are finished with the session to avoid allocating unnecessary
    memory.
    """
    session_data, _, _ = tsm_context.get_all_custom_sessions(InstrumentTypeId)
    for session in session_data:
        session.close()
Пример #13
0
def close_session(tsm: SMContext):
    """
    Closes the sessions associated with the tsm context

    Args:
        tsm (SMContext): TestStand semiconductor module context
    """
    sessions_list = tsm.get_all_nidmm_sessions()
    for session in sessions_list:
        session.reset()
        session.close()
Пример #14
0
def get_all_sessions(tsm: SMContext):  # CHECK
    """
    Gets a list of Abstract Switch references corresponding to the set Abstract sessions on TSM
    Context
    """
    session_data = tsm.get_all_switch_sessions(instrument_type_id)
    if len(session_data) == 0:
        # Raise Error?
        session = AbstractSession([])
    else:
        session = session_data[0]
    return session
Пример #15
0
def close_sessions(tsm: SMContext):
    """
    Resets and Closes all the NI-SCOPE instruments sessions from the pinmap file associated
    with the Semiconductor Module Context.

    Args:
        tsm (SMContext): TestStand semiconductor module context
    """
    sessions = tsm.get_all_niscope_sessions()
    for session in sessions:
        session.reset()
        session.close()
Пример #16
0
def get_all_instruments_names(tsm: SMContext):
    """
    Returns all the switch based instruments in the tsm context

    Args:
        tsm (SMContext): Semiconductor module Reference from the TestStand.

    Returns:
        tuple : instrument_names, channel_group_ids
    """
    instrument_names, channel_group_ids, _ = tsm.get_custom_instrument_names(
        instrument_type_id)
    return instrument_names, channel_group_ids
Пример #17
0
def pins_to_sessions_sessions(tsm: SMContext, pins: PinsArg):
    """
    Returns a pin query context and a list of properties defined in the pin map.
    The list of properties returned can be used to fill a new object type MultipleSessions
    Args:
        tsm: Pin context defined by pin map
        pins: The name of the pin(s) or pin group(s) to translate to a set of tasks.
    Return:
        session: An object that tracks the tasks associated with this pin query. Use this object to
        publish measurements and extract data from a set of measurements.
    """
    session = tsm.pins_to_nidaqmx_tasks(pins)  # pin_query_context, task, channel_lists
    return session
Пример #18
0
def pins_to_sessions(tsm: SMContext, pins: PinsArg):
    """
    Returns the NI-DMM instrument sessions required to access the pin(s).

    Args:
        tsm (SMContext): _description_
        pins (PinsArg): The names of the pin(s) or pin group(s) to translate to instrument sessions.

    Returns:
        TSMDMM: TSM Session Object for DMM pins
    """
    pin_query_context, sessions = tsm.pins_to_nidmm_sessions(pins)
    return TSMDMM(pin_query_context, sessions)
Пример #19
0
def get_all_sessions(tsm: SMContext, task_type: str = ""):
    """
    Returns all sessions in the Semiconductor Module Context that belong to multiple instruments of
    the type DAQmx.
    Args:
        tsm: Pin context defined by pin map
        task_type: Specifies the type of NI-DAQmx task to return. Use an empty string to obtain the
            names of all
        tasks regardless of task type
    Return:
        List of tasks of the specific type
    """
    tasks = tsm.get_all_nidaqmx_tasks(task_type)
    return tasks
Пример #20
0
def get_all_pins(tsm: SMContext, reload_cache=False):
    """
    Returns all pins and its types (DUT or system) available in the Semiconductor Module context.
    Maintains a cache of these pin details and reloads them when requested or required.
    """
    global _pin_names, _pin_types
    # rebuild cache if empty
    if len(_pin_names) == 0 or reload_cache:
        dut_pins, system_pins = tsm.get_pin_names()
        dut_pin_types = [PinType.DUT_PIN] * len(dut_pins)
        system_pin_types = [PinType.SYSTEM_PIN] * len(system_pins)
        _pin_names = dut_pins + system_pins
        _pin_types = dut_pin_types + system_pin_types
    return _pin_names, _pin_types
Пример #21
0
def get_all_sessions(tsm: SMContext):
    """
    Gets a list of Switch references corresponding to the set sessions on TSM
    Context

    Args:
        tsm (SMContext): Semiconductor module Reference from the TestStand.

    Returns:
        list of sessions: all the switch sessions in the current context
    """
    session_data, _, _ = tsm.get_all_custom_sessions(instrument_type_id)
    list_of_sessions = []
    for session in session_data:
        list_of_sessions.append(session)
    return list_of_sessions
Пример #22
0
def get_all_instrument_names(tsm: SMContext, task_type: str = ""):
    """
    Returns the channel group ID and associated instrument names and channel lists of all
    instruments of type Instrument Type ID defined in the Semiconductor Module context. You can use
    instrument names, channel group IDs, and channel lists to open driver sessions. The Instrument
    Names and Channel Lists parameters always return the same number of elements. Instrument names
    repeat in the Instrument Names parameter if the instrument has multiple channel groups.
    Args:
        tsm: Pin context defined by pin map
        task_type: Specifies the type of NI-DAQmx task to return. Use an empty string to obtain the
            names of all tasks regardless of task type.
    Return:
        A tuple of the NI-DAQmx task names.
    """
    instruments = tsm.get_all_nidaqmx_task_names(task_type)
    return instruments  # Instrument Names, Channel Lists per Instrument
def initialize_sessions(tsm: SMContext):
    ctypes.windll.user32.MessageBoxW(
        None,
        "Process: niPythonHost.exe & ID: " + str(os.getpid()),
        "Attach debugger",
        0,
    )
    print(tsm.pin_map_file_path)
    pins = SMContext.get_pin_names(
        tsm, instrument_type_id=nitsm.enums.InstrumentTypeIdConstants.NI_DIGITAL_PATTERN
    )
    print(pins)
    dt_dpi.initialize_sessions(tsm, options=OPTIONS)
    dpi_tsm_i_o = dt_dpi.pins_to_sessions(tsm, ["DPI_PG_Inputs", "DPI_PG_Outputs"])
    dpi_tsm_i_o.ssc.apply_levels_and_timing("I2C_Levels", "I2C_Timing")
    dpi_tsm_i_o.ssc.select_function(dt_dpi.enums.SelectedFunction.DIGITAL)
Пример #24
0
def _check_for_pin_group(tsm: SMContext, pins_or_pins_group):
    """
    private function for finding the pin_group in the list of pins

    Args:
        tsm (SMContext): semiconductor module context from teststand
        pins_or_pins_group (_type_): list of pins or pin_group names

    Returns:
        pin_types, pins: for each of the input pin find its pin type and pins
    """
    pins = pins_or_pins_group
    pins_types, pin_group_found = identify_pin_types(tsm, pins_or_pins_group)
    if pin_group_found:
        pins = tsm.get_pins_in_pin_groups(pins_or_pins_group)
        pins_types, _ = identify_pin_types(tsm, pins)
    return pins_types, pins
Пример #25
0
def pin_to_sessions_session_info(tsm: SMContext, pin: str = ""):
    """
    Returns a Switch Session object containing a list of switch sessions detailed on the pinmap

    Args:
        tsm (SMContext): Pin context defined by pin map
        pin (str, optional): The name of the pin to translate to a session. Defaults to "".

    Returns:
        session: An object that tracks the session associated with pin provided.
    """
    try:
        _, session_data, channel_group_id, _ = tsm.pins_to_custom_session(
            instrument_type_id, pin)
        relay_name = channel_group_id
        # TODO CHECK for better equivalent
        data = MultipleSessions([Session(session_data, pin, relay_name)])
        return data
    except Exception:
        return None
Пример #26
0
def expand_pin_groups_and_identify_pin_types(tsm: SMContext, pins_in):
    """
    for the given pins expand all the pin groups and identifies the pin types

    Args:
        tsm (SMContext): semiconductor module context from teststand
        pins_in (_type_): list of pins for which information needs to be expanded if it is pin group

    Returns:
        pins_info, pins_expanded: tuple of pins_info and pins_expanded.
    """
    pins_temp, pin_types_temp = get_all_pins(tsm)
    pins_info = []
    pins_expanded = []
    i = 0
    for d_pin in pins_in:
        if d_pin in pins_temp:
            index_d = pins_temp.index(d_pin)
            d_pin_type = pin_types_temp[index_d]
            count = 1
            pin_expanded = ExpandedPinInformation(d_pin, d_pin_type, i)
            pins_expanded.append(pin_expanded)
        else:
            d_pin_type = PinType.PIN_GROUP
            temp_exp_pins = tsm.get_pins_in_pin_groups(
                d_pin)  # This works fine
            count = len(temp_exp_pins)
            for a_pin in temp_exp_pins:
                index_a = pins_temp.index(a_pin)
                a_pin_type = pin_types_temp[index_a]
                pin_expanded = ExpandedPinInformation(
                    a_pin, a_pin_type,
                    i)  # Found bug here due to class & fixed it.
                pins_expanded.append(pin_expanded)
        pin_info = PinInformation(d_pin, d_pin_type, count)
        pins_info.append(pin_info)
        i += 1
    pins_expanded = remove_duplicates_from_tsm_pin_information_array(
        pins_info, pins_expanded)
    return pins_info, pins_expanded
Пример #27
0
def pins_to_sessions_sessions_info(tsm: SMContext, pin: str):
    """
    Returns an AbstractSession object containing a list al Abstract switch sessions detailed on the
    pinmap
    Args:
        tsm: Pin context defined by pin map
        pin: The name of the pin to translate to a session.
    Return:
        session: An object that tracks the session associated with pin provided.
    """
    session_list = []
    contexts, sessions, switch_routes = tsm.pin_to_switch_sessions(
        pin, instrument_type_id)
    i = 0
    for context, session, route in zip(contexts, sessions, switch_routes):
        data = route.split(",")
        list1 = []
        list2 = []
        for route_data in data:
            data2 = route_data.split("=")
            out1 = data2[0].strip()
            out2 = "".join(data2[1:]).strip()
            list1.append(out1)
            list2.append(out2)
        for element1, element2 in zip(list1, list2):
            condition = False
            for single_session in session.enable_pins:
                # Change id 050322 "Moving the lines that set the route_value for each element
                # and the site inside the if statement avoids overwriting correct route_value
                # with following for loops"
                if single_session.enable_pin.strip().lower() == element1.lower(
                ):
                    single_session.route_value = element2
                    single_session.site = i
                    session_list.append(single_session)
                    break
        del tsm
    return AbstractSession(session_list)
Пример #28
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
Пример #29
0
def set_task(tsm: SMContext):
    """
    Associates each NI-DAQmx tasks with the NI-DAQmx task name defined in the pin map and
    set all the sessions accordingly
    """
    input_voltage_range = 10.0
    task_names, channel_lists = tsm.get_all_nidaqmx_task_names(
        "AnalogOutput"
    )  # Replace String if PinMap change
    for task_name, physical_channel in zip(task_names, channel_lists):
        task = nidaqmx.Task(task_name)
        try:
            task.ao_channels.add_ao_voltage_chan(
                physical_channel=physical_channel,
            )
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        except Exception:
            task = reset_devices(task)
            task.ao_channels.add_ao_voltage_chan(physical_channel)
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        finally:
            tsm.set_nidaqmx_task(task_name, task)
    # input_voltage_range = 10.0
    task_names, channel_lists = tsm.get_all_nidaqmx_task_names(
        "AnalogInput"
    )  # Replace String if PinMap change
    for task_name, physical_channel in zip(task_names, channel_lists):
        task = nidaqmx.Task(task_name)
        try:
            task.ai_channels.add_ai_voltage_chan(
                physical_channel,
                "",
                nidaqmx.constants.TerminalConfiguration.DIFFERENTIAL,
                -input_voltage_range,
                input_voltage_range,
            )
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        except Exception:
            task = reset_devices(task)
            task.ai_channels.add_ai_voltage_chan(physical_channel)
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        finally:
            tsm.set_nidaqmx_task(task_name, task)

    task_names, channel_lists = tsm.get_all_nidaqmx_task_names(
        "AnalogInputDSA"
    )  # Replace String if PM change
    for task_name, physical_channel in zip(task_names, channel_lists):
        task = nidaqmx.Task(task_name)
        try:
            ch = task.ai_channels.add_ai_voltage_chan(physical_channel)
            print(ch.ai_coupling, ch.ai_term_cfg, ch.channel_names)
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        except Exception:
            task = reset_devices(task)
            task.ai_channels.add_ai_voltage_chan(physical_channel)
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        finally:
            tsm.set_nidaqmx_task(task_name, task)

    task_names, channel_lists = tsm.get_all_nidaqmx_task_names(
        "AnalogOutputDSA"
    )  # Replace String if PM change
    for task_name, physical_channel in zip(task_names, channel_lists):
        task = nidaqmx.Task(task_name)
        try:
            ch = task.ao_channels.add_ao_voltage_chan(physical_channel)
            # TODO Config doesn't write properly for DSA channel
            ch.ao_term_cfg = nidaqmx.constants.TerminalConfiguration.DIFFERENTIAL
            print(ch.ao_term_cfg, ch.ao_min, ch.channel_names)
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        except Exception:
            task = reset_devices(task)
            task.ao_channels.add_ao_voltage_chan(physical_channel)
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.SAMPLE_CLOCK
        finally:
            tsm.set_nidaqmx_task(task_name, task)

    task_names, channel_lists = tsm.get_all_nidaqmx_task_names(
        "DigitalOutput"
    )  # Replace String if PM change
    for task_name, physical_channel in zip(task_names, channel_lists):
        task = nidaqmx.Task(task_name)
        try:
            task.do_channels.add_do_chan(
                physical_channel, "", nidaqmx.constants.LineGrouping.CHAN_PER_LINE
            )
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.ON_DEMAND
        except Exception:
            task = reset_devices(task)
            task.do_channels.add_do_chan(
                physical_channel, "", nidaqmx.constants.LineGrouping.CHAN_PER_LINE
            )
            task.timing.samp_timing_type = nidaqmx.constants.SampleTimingType.ON_DEMAND
        finally:
            tsm.set_nidaqmx_task(task_name, task)
Пример #30
0
def close_sessions(tsm: SMContext):
    """Closes the sessions associated with the tsm context"""
    sessions = tsm.get_all_nifgen_sessions()
    for session in sessions:
        session.reset()
        session.close()