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

1 visualización (últimos 30 días)
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

Respuesta aceptada

ANGEL DEL PINO JIMENEZ
ANGEL DEL PINO JIMENEZ el 24 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Instrument Control Toolbox Supported Hardware en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by