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 | |
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 | |