How can I send variable value with To Instrument Simulink block?

조회 수: 1 (최근 30일)
Hello, I am using an external PSU and I would like to set the voltage and current using simulink but I am not able to do it with simulink.
I am using the Instrument Toolbox and the Support Package for Keysight IO Libraries and VISA Interface. For matlab it is straight forward, this is the code
PSU = visadevlist();
vi = visa('agilent',PSU{1,1});
fopen(vi);
fprintf(vi, ':INST CH2');
fprintf(vi, ':VOLT 27.3');
fclose(vi);
but with simulink I am not able to send the value of a variable to the PSU. I am using the To Instrument block, and this is my simple simulink diagram,
and those are my properties
Any idea how to do this? I am also open to other alternatives

채택된 답변

ANGEL DEL PINO JIMENEZ
ANGEL DEL PINO JIMENEZ 2023년 4월 24일
In case someone from the future finds it useful, I have solved it. The main problem was dealing with Error with simulink: 'The 'visa' class does not support code generation.'
I have done it very easily by using the MATLAB System block and using the Interpreted execution option of it.
And the code, in the stepImpl function:
function stepImpl(obj, voltage)
% Set up VISA connection
vi = visa('agilent', "INSTR_ID");
fopen(vi);
fprintf(vi, ':INST CH2');
% Set the output voltage
% fprintf(vi, sprintf(':APPL CH2,%f,%f', voltage, 1.5));
fprintf(vi, sprintf(':VOLT %f', voltage));
% Close VISA connection
fclose(vi);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Instrument Control Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by