필터 지우기
필터 지우기

Running .m and simulink (.slx) file together

조회 수: 7 (최근 30일)
Rutvik Shete
Rutvik Shete 2020년 8월 11일
댓글: Rutvik Shete 2020년 8월 11일
I ran in to trouble while working with NI DAQ (USB 6251). I wanted to integrate everything is simulink and they dont provide block for counter (Can't use DIs). So I used function block with coder.extrensic() function and it works but my counter resets everytime. Following is my code,
function data = functionRead1()
data = zeros(1,1); %Preinitialization
coder.extrinsic('daq','addinput','read','table2array'); %define functions as external
d = daq("ni"); % Add DAQ
ch1 = addinput(d, 'Dev1', 'ctr0', 'Position'); % Add Inputs
data = table2array(read(d)); %reads 1 scan cycle and returns accumulated value
end
So the problem is everytime counter resets and I get wront data read in code. Cant use while loop or if...else logic as it goes in loop or throws error.
I have .m file as well for code which works fine. It there any way I can run .m and .slx together on same machine? Or any other solution is fine.
Thanx in advance.

채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 11일
Use persistent. Check if the persistent variable is empty and if it is then configure it. Then either way, read from the daq.
Note: consider using OutputFormat 'Matrix' instead of the default table.
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 8월 11일
persistent d
Rutvik Shete
Rutvik Shete 2020년 8월 11일
Thanx a lot. Works really well. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simultaneous and Synchronized Operations에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by