Main Content

Generate and Acquire Data on Bidirectional Channels

This example shows how to use a bidirectional channel and read and write data using the same two lines on an NI 6255.

Discover NI devices connected to your system and find the ID for the NI 6255.

d = daqlist("ni")
dev =

  3×4 table

    DeviceID                Description                  Model             DeviceInfo       
    ________    ___________________________________    __________    _______________________

     "Dev1"     "National Instruments(TM) USB-6255"    "USB-6255"    [1×1 daq.ni.DeviceInfo]
     "Dev2"     "National Instruments(TM) USB-6363"    "USB-6363"    [1×1 daq.ni.DeviceInfo]

Create a DataAcquisition and add two lines from port 0 and 2 lines from port 1 on Dev1.

d = daq("ni");
addbidirectional(d,"Dev1","Port0/Line0:1","Digital");
addbidirectional(d,"Dev1","Port1/Line0:1","Digital");
d.Channels
ans = 

    Index    Type     Device       Channel          Measurement Type        Range           Name       
    _____    _____    ______    _____________    _______________________    _____    __________________

      1      "dio"    "Dev1"    "port0/line0"    "Bidirectional (Input)"    "n/a"    "Dev1_port0/line0"
      2      "dio"    "Dev1"    "port0/line1"    "Bidirectional (Input)"    "n/a"    "Dev1_port0/line1"
      3      "dio"    "Dev1"    "port1/line0"    "Bidirectional (Input)"    "n/a"    "Dev1_port1/line0"
      4      "dio"    "Dev1"    "port1/line1"    "Bidirectional (Input)"    "n/a"    "Dev1_port1/line1"

Set the direction on all channels to output data.

set(d.Channels,"Direction","Output");

Generate the digital output data.

write(d,[1 0 1 0])

Change the direction on all channels to input data

set(d.Channels,"Direction","Input");

Acquire the digital data.

read(d,"OutputFormat","Matrix")
ans =

     1     0     1     0