How to detect and send digital I/O using matlab? (not simulink)

How to use matlab to detect and generate digital input output form a NiDAQ using matlab?
I do not want to use simulink. Is that even possible? I have a sensor and a LED light. When I put my figure near the sensor the LED turn on, when I let go the LED will go off. IS that even possible in Matlab? I believe matlab don't run things continuously.
e.g while (true) If detect digital signal iniput from port 0 line 0 (Sensor) pause(.1) send digital signal output to port 0 line 1 (LED) pause(.1) send the inverse siganl to port 0 line 1 (turn off LED) end
end

Answers (2)

You already asked that three times before. Search the documentation for DIO

16 Comments

http://www.mathworks.com/help/daq/examples/introduction-to-digital-input-and-output.html that's the tutorial, it teaches me how to send values to specific ports. However, it didn't teach me how to send digital input and output and how to detect digital input and output.
Once you have configured the object as sending digital I/O then you just use the regular commands to send data to the port; there is no specific "send digital I/O" command.
I'm still a little confused, I tried everything in the website and I still fail to turn on the light in port 0 line 1 or have a way to detect signals from port 0 line 2. Do you mind writing that line out here?
Session based interface or Legacy interface?
I was given DAQ6202-AQC. I believe is legacy, I am not sure. Better yet, can anyone explain the difference between legacy and session base interface? (i know x64 can't use legacy, but that's about it). Anyways, I just go with what most make sense to me. Here's my code.
% code
dio = digitalio('nidaq','Dev1');
addline(dio,0:3,'In');
line1 = dio.Line(1);
set(line1,'Direction','Out'); <-- at this point I am expecting the LED light of port 0 line 0 to turn on, but it didn't. Oh I also tried dio.Line(0) as well.
Regarding how to detect digital input for an if loop, i'm completely clueless, would appreciate if someone could lend me a hand on that.
That is legacy code you have there.
The DAQ6202-AQC appears to be an IC rather than a board. It is for NI's "M-Series" hardware. In order to determine whether you need session or legacy, I will need the board name including the interface (e.g., PCI, PCI-express, and so on.) Also, I will need to know which MATLAB version you are using.
Instead of setting the direction out using set(), you can create it as out in the first place, using
addline(dio,0:3,{'out', 'in', 'in', 'in');
Once you have that, you can send a value to the port using putvalue(). It took me a bit of reading to figure out to use putvalue() instead of putsample() or putdata(): putvalue() is for digital lines and the other two are analog.
putvalue(dio.Line(1), 1)
% code
N114
DAQ6202-AQC
DAQ-STC2-BGC
The interface is PCI, not PCIE. My matlab is 2013a 32bit
PCI-6025 System Timing Controller?
PCI-1407 N114 ?
PCI-8212 GPIB N114 Ethernet ?
1417 ? I am not finding that one. I am finding IMAQ PCI-1407 which is a monochrome image acquisition board. It has three BNC connectors on it, one of which can be driven high/low or as a TTL level line.
I have daqmx 9.2.2 installed. I can turn on the lights when that program. Therefore it prove the daqmx is correctly connected to the computer.
When I try the following i get this.
% code
DIO = digitalio('nidaq','Dev1')
Error using digitalio (line 117) Failure to find requested data acquisition device: nidaqmx.
Also In the daqmx, the device is indicated as NI PCI/PXI-6221 (68-pin).
Lastly, I tried the session base code. It works
% code
s = daq.createSession('ni');
s =
Data acquisition session using National Instruments hardware: Will run for 1 second (1000 scans) at 1000 scans/second. No channels have been added.
Properties, Methods, Events
However, the problem is the fact that I am more familiar with legacy base's codes. I am really clueless on how to send digital output and detect digital input with session base program. Also could anyone care to explain what session base means?
% code
ni: National Instruments PCI-6221 (Device ID: 'Dev2')
Analog input subsystem supports:
4 ranges supported
Rates from 0.1 to 250000.0 scans/sec
16 channels ('ai0' - 'ai15')
'Voltage' measurement type
Analog output subsystem supports:
-10 to +10 Volts range
Rates from 0.1 to 833333.3 scans/sec
2 channels ('ao0','ao1')
'Voltage' measurement type
Digital subsystem supports:
Rates from 0.1 to 1000000.0 scans/sec
24 channels ('port0/line0' - 'port2/line7')
'InputOnly','OutputOnly','Bidirectional' measurement types
Counter input subsystem supports:
Rates from 0.1 to 80000000.0 scans/sec
2 channels ('ctr0','ctr1')
'EdgeCount','PulseWidth','Frequency','Position' measurement types
Counter output subsystem supports:
Rates from 0.1 to 80000000.0 scans/sec
2 channels ('ctr0','ctr1')
'PulseGeneration' measurement type
Also, is it the fact that I am using BNC 2090 (an extention instead of soldering the the lines to the daq) the reason why my code'ss not working?
I am going to need to do more reading, and I do not know if I am going to be able to solve this. I will be out this evening.
Sorry, I threw too much questions. So anyways just answer this. 1) How to send digital output using session base? 2) How to detect digital input using session base? I code I want to complete is this.
If (digital output at port 0 line 1 == True) % sensor detection
send digital output to port 0 line 2; turn on led
send an inverse output to port 0 line 2; turn off led
end
Legacy interface instead of Session-based interface should be fine. You will need at least R2011b for the session-based interface for that device, and I see noted some bugs for support of the device before R2011b (but I did not cross-check which interface that was for.)
Beyond that I will need to research more.
DIO = digitalio('nidaq','Dev1')
Error using digitalio (line 117) Failure to find requested data acquisition device: nidaqmx.
The legacy interface isn't working probably, but it doesn't matter to me anyways. I just want it to work. So to the question. how to do the following with session base interface?
% code
If (digital output at port 0 line 1 == True) % sensor detection
send digital output to port 0 line 2; turn on led
send an inverse output to port 0 line 2; turn off led
end

Sign in to comment.

^ what do you mean by the documentation of DIO

Categories

Asked:

on 5 Dec 2013

Commented:

on 12 Dec 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!