You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to detect and send digital I/O using matlab? (not simulink)
    3 views (last 30 days)
  
       Show older comments
    
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)
  Walter Roberson
      
      
 on 5 Dec 2013
        You already asked that three times before. Search the documentation for DIO
16 Comments
  Kelly
 on 6 Dec 2013
				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.
  Walter Roberson
      
      
 on 6 Dec 2013
				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.
  Kelly
 on 8 Dec 2013
				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?
  Kelly
 on 9 Dec 2013
				
      Edited: Kelly
 on 9 Dec 2013
  
			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.
  Walter Roberson
      
      
 on 9 Dec 2013
				
      Edited: Walter Roberson
      
      
 on 9 Dec 2013
  
			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)
  Walter Roberson
      
      
 on 9 Dec 2013
				PCI-6025 System Timing Controller?
PCI-1407 N114 ?
PCI-8212 GPIB N114 Ethernet ?
  Walter Roberson
      
      
 on 10 Dec 2013
				
      Edited: Walter Roberson
      
      
 on 10 Dec 2013
  
			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.
  Kelly
 on 10 Dec 2013
				
      Edited: Kelly
 on 10 Dec 2013
  
			er... I was given this  http://sine.ni.com/nips/cds/view/p/lang/en/nid/10971 It is also selling in ebay for 185 http://www.ebay.com/itm/like/300920221791?lpid=82
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
  Kelly
 on 10 Dec 2013
				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?
  Walter Roberson
      
      
 on 10 Dec 2013
				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.
  Kelly
 on 11 Dec 2013
				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
  Walter Roberson
      
      
 on 11 Dec 2013
				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.
  Kelly
 on 12 Dec 2013
				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
See Also
Categories
				Find more on Hardware Discovery and Setup in Help Center and File Exchange
			
	Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

