이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to detect and send digital I/O using matlab? (not simulink)
조회 수: 6 (최근 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에서 Digital Input and Output에 대해 자세히 알아보기
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 (한국어)