Skip to content

NIDAQ¤

NIDAQ (Interface) ¤

NIDAQ(equipment: Equipment)

Use NI-DAQmx as the backend to communicate with the equipment.

The backend value must be equal to NIDAQ to use this class for the communication backend.

The returned object from calling the connect method is equivalent to importing the NI-DAQmx package, e.g.,

from msl.equipment import Backend, Connection

connection = Connection(address="Dev1", backend=Backend.NIDAQ)
nidaqmx = connection.connect()

with nidaqmx.Task() as task:
    task.ai_channels.add_ai_voltage_chan(f"{nidaqmx.address}/ai0")
    voltage = task.read()

is equivalent to

import nidaqmx

with nidaqmx.Task() as task:
    task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
    voltage = task.read()

You can also combine the packages, use msl-equipment for managing information about the equipment and directly use nidaqmx for the connection. If you use this combination, the editor you use to develop your code may have better support for features like code completion and type checking.

import nidaqmx
from msl.equipment import Config

# config.xml contains <equipment eid="MSLE.0.142" name="daq" manufacturer="NI"/>
# and specifies where the equipment registers are and the connections file.
cfg = Config("config.xml")
equipment = cfg.equipment["daq"]
address = equipment.connection.address

with nidaqmx.Task() as task:
    task.ai_channels.add_ai_voltage_chan(f"{address}/ai0")
    voltage = task.read()

    # You could now use the `equipment` instance to apply a correction to the `voltage`

See the examples on the NI-DAQmx repository to learn how to use the nidaqmx package.

Parameters:

Name Type Description Default
equipment Equipment

An Equipment instance.

required
Source code in src/msl/equipment/interfaces/nidaq.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __init__(self, equipment: Equipment) -> None:
    """Use [NI-DAQmx] as the backend to communicate with the equipment.

    The [backend][msl.equipment.schema.Connection.backend] value must be equal
    to `NIDAQ` to use this class for the communication backend.

    The returned object from calling the [connect][msl.equipment.schema.Equipment.connect]
    method is equivalent to importing the [NI-DAQmx] package, e.g.,

    ```python
    from msl.equipment import Backend, Connection

    connection = Connection(address="Dev1", backend=Backend.NIDAQ)
    nidaqmx = connection.connect()

    with nidaqmx.Task() as task:
        task.ai_channels.add_ai_voltage_chan(f"{nidaqmx.address}/ai0")
        voltage = task.read()
    ```

    is equivalent to

    ```python
    import nidaqmx

    with nidaqmx.Task() as task:
        task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
        voltage = task.read()
    ```

    You can also combine the packages, use `msl-equipment` for managing information
    about the equipment and directly use `nidaqmx` for the connection. If you use this
    combination, the editor you use to develop your code may have better support for
    features like code completion and type checking.

    ```python
    import nidaqmx
    from msl.equipment import Config

    # config.xml contains <equipment eid="MSLE.0.142" name="daq" manufacturer="NI"/>
    # and specifies where the equipment registers are and the connections file.
    cfg = Config("config.xml")
    equipment = cfg.equipment["daq"]
    address = equipment.connection.address

    with nidaqmx.Task() as task:
        task.ai_channels.add_ai_voltage_chan(f"{address}/ai0")
        voltage = task.read()

        # You could now use the `equipment` instance to apply a correction to the `voltage`
    ```

    See the [examples](https://github.com/ni/nidaqmx-python/tree/master/examples)
    on the [NI-DAQmx repository](https://github.com/ni/nidaqmx-python) to learn
    how to use the `nidaqmx` package.

    [NI-DAQmx]: https://nidaqmx-python.readthedocs.io/en/stable/index.html

    Args:
        equipment: An [Equipment][] instance.
    """
    super().__init__(equipment)

    if nidaqmx is None:  # pragma: no branch
        msg = "nidaqmx is not installed, run: pip install nidaqmx"
        raise RuntimeError(msg)

address property ¤

address: str

Returns the address of the Connection.

equipment property ¤

equipment: Equipment

The Equipment associated with the interface.

disconnect ¤

disconnect() -> None

Disconnect from the equipment.

This method can be overridden in the subclass if the subclass must implement tasks that need to be performed in order to safely disconnect from the equipment.

For example,

  • to clean up system resources from memory (e.g., if using a manufacturer's SDK)
  • to configure the equipment to be in a state that is safe for people working in the lab when the equipment is not in use

Tip

This method gets called automatically when the Interface instance gets garbage collected, which happens when the reference count is 0.

Source code in src/msl/equipment/schema.py
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
def disconnect(self) -> None:
    """Disconnect from the equipment.

    This method can be overridden in the subclass if the subclass must implement
    tasks that need to be performed in order to safely disconnect from the equipment.

    For example,

    * to clean up system resources from memory (e.g., if using a manufacturer's SDK)
    * to configure the equipment to be in a state that is safe for people
      working in the lab when the equipment is not in use

    !!! tip
        This method gets called automatically when the [Interface][msl.equipment.schema.Interface]
        instance gets garbage collected, which happens when the reference count is 0.
    """
    logger.debug("Disconnected from %r", self)