How to detect and send digital I/O using matlab? (not simulink)
11 次查看(过去 30 天)
显示 更早的评论
Kelly
2013-12-5
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
回答(2 个)
Walter Roberson
2013-12-5
You already asked that three times before. Search the documentation for DIO
16 个评论
Kelly
2013-12-6
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
2013-12-6
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
2013-12-8
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
2013-12-9
编辑:Kelly
2013-12-9
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
2013-12-9
编辑:Walter Roberson
2013-12-9
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
2013-12-9
PCI-6025 System Timing Controller?
PCI-1407 N114 ?
PCI-8212 GPIB N114 Ethernet ?
Walter Roberson
2013-12-10
编辑:Walter Roberson
2013-12-10
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
2013-12-10
编辑:Kelly
2013-12-10
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
2013-12-10
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
2013-12-10
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
2013-12-11
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
2013-12-11
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
2013-12-12
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hardware Discovery and Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)