Documentation Center

  • Trial Software
  • Product Updates

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.

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

d = daq.getDevices;
d = 

Data acquisition devices:

index Vendor Device ID          Description         
----- ------ --------- -----------------------------
1     ni     Dev1      National Instruments USB-6255
2     ni     Dev2      National Instruments USB-6363

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

s = daq.createSession('ni');
addDigitalChannel(s,'Dev1','Port0/Line0:1','Bidirectional');
addDigitalChannel(s,'Dev1','Port1/Line0:1','Bidirectional')
Data acquisition session using National Instruments hardware:
   Clocked operations using startForeground and startBackground are disabled.
   Only on-demand operations using inputSingleScan and outputSingleScan can be done.
   Number of channels: 4
      index Type Device   Channel       MeasurementType     Range Name
      ----- ---- ------ ----------- ----------------------- ----- ----
      1     dio  Dev1   port0/line0 Bidirectional (Unknown) n/a
      2     dio  Dev1   port0/line1 Bidirectional (Unknown) n/a
      3     dio  Dev1   port1/line0 Bidirectional (Unknown) n/a
      4     dio  Dev1   port1/line1 Bidirectional (Unknown) n/a

Set the direction on all channels to output data.

for i = 1:4
    s.Channels(i).Direction = 'Output'; 
end

Generate digital data.

outputSingleScan (s,[1,0, 1, 0])

Change the direction on all channels to input data

for i = 1:4
    s.Channels(i).Direction = 'Input'; 
end

Acquire digital data.

inputSingleScan(s)
ans =

     1     0     1     0

You can also use the MATLAB® deal function to change direction on all channels together.

[s.channels(:).Direction] = deal ('Input');
Was this topic helpful?