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

1 view (last 30 days)
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

Accepted Answer

ANGEL DEL PINO JIMENEZ
ANGEL DEL PINO JIMENEZ on 24 Apr 2023
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

More Answers (0)

Categories

Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!