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