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

1 回表示 (過去 30 日間)
ANGEL DEL PINO JIMENEZ
ANGEL DEL PINO JIMENEZ 2023 年 4 月 10 日
回答済み: ANGEL DEL PINO JIMENEZ 2023 年 4 月 24 日
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 Center および File ExchangeInstrument Control Toolbox Supported Hardware についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by