Too many output arguments ERROR

I am making a function to run venting on a pump system. I am getting an error using the matlab timer object. I have the script below and the error let me know if you can help. Thanks!
function vent_man(sec)
v = visa('agilent', 'ASRL1::INSTR');
fopen(v);
hexdata_open = ['02'; '80'; '31'; '32'; '32'; '31'; '31'; '03'; '42'; '33'];
decdata_open = hex2dec(hexdata_open);
hexdata_close = ['02'; '80'; '31'; '32'; '32'; '31'; '30'; '03'; '42'; '33'];
decdata_close = hex2dec(hexdata_close);
t = timer;
t.StartFnc = fwrite(v, decdata_open, 'uint8');
t.StopFnc = fwrite(v, decdata_close, 'uint8');
t.Period = sec;
start(t);
fclose(v);
delete(v);
end
P.S. I have already tried changing the first line to function v = vent_man(sec) which did not work
Error using icinterface/fwrite
Too many output arguments.
Error in vent_man (line 9)
t.StartFnc = fwrite(v, decdata_open, 'uint8');

답변 (1개)

Cam Salzberger
Cam Salzberger 2020년 7월 24일
편집: Cam Salzberger 2020년 7월 24일

0 개 추천

Keir,
The fwrite method for that object doesn't seem to return an output argument. Always try to make sure that you are both using the correct function and using the function correctly.
In this case, it looks like you want to make a function handle for the timer functions, not call the function immediately. So you probably want something more like:
t.StartFnc = @(~,~)fwrite(v, decdata_open, 'uint8');
and similar for the other
-Cam

댓글 수: 3

I am attempting at the start of the timer to write the decdata_open to the pump and then when the timer stops to write the decdata_close to the pump. When I run your solution I get another error:
Error using timer/subsasgn (line 137)
The name 'StartFnc' is not an accessible property for an instance of class 'timer objects'.
Error in vent_man (line 9)
t.StartFnc = @(~,~)fwrite(v, decdata_open, 'uint8');
Cam Salzberger
Cam Salzberger 2020년 7월 24일
Ah, I copied from your code without looking. The parameter name is 'StartFcn' not 'StartFnc'.
Always read the error messages - they're usually pretty useful.
Keir Hunter
Keir Hunter 2020년 7월 24일
Thanks!

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 7월 24일

댓글:

2020년 7월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by