daq_read_digital_port.py
"""Example: Read a digital port (all lines as one N-bit integer)."""
from instro.daq import InstroDAQ
from instro.daq.types import DAQVendor, DigitalPortWidth, Direction, Logic
from instro.lib.publishers import NominalCorePublisher
# Configuration: Choose your vendor. Port-mode I/O is supported on NI, Keysight, and MCC.
VENDOR = DAQVendor.NI
# Vendor-specific configuration. Each vendor driver lives in its own package and
# owns its transport at construction time.
match VENDOR:
case DAQVendor.NI:
from instro.daq.drivers.ni import NIDAQDriver
PORT = "Dev1/port0"
driver = NIDAQDriver(device_id="Dev1")
case DAQVendor.KEYSIGHT_34980:
from instro.daq.drivers import Keysight34980A
PORT = "5101"
driver = Keysight34980A("USB0::0x0957::0x0507::MY44001757::INSTR")
case DAQVendor.MCC:
from instro.daq.drivers.mcc import MCCDriver
PORT = "FIRSTPORTB"
driver = MCCDriver(
device_id="344371:0"
) # MCC DAQ device ID, optionally suffixed with ":<board_number>" (default 0)
# Nominal Core dataset to send data to as the instrument is operated.
DATASET_RID = "<dataset_rid>" # Replace with your dataset RID.
### Main code
daq = InstroDAQ(name="myDAQ", driver=driver)
daq.add_publisher(NominalCorePublisher(dataset_rid=DATASET_RID))
daq.open()
try:
daq.configure_digital_port(
direction=Direction.INPUT,
physical_channel=PORT,
alias="di_port",
logic=Logic.HIGH,
port_width=DigitalPortWidth.WIDTH_8,
)
measurement = daq.read_digital_port(channel="di_port")
print(f"Port value: {int(measurement.latest)}")
finally:
print("Closing DAQ")
daq.close()