I'm trying to remote control Keysight DC Electronic Load N3300A with Simulink via GPIB interface, and use GPIB-USB-HS+ board from NI to connect the instrument with my PC. I want to set the instrument to be in CC mode and sink 1.25A of current, and then send the measured current data back to my Simulink model. There is no problem that I control it with sending command through Test & Measuring Tool or run in Matlab script, Here are the commands in Matlab scrip:
C1 = gpib('ni',0,3); % Board index=0, Address=3
C1.EOSMode = 'read&write';
C1.EOSCharCode = 'LF';
fprintf(C1,'CHAN 2'); % Using channel 2
fprintf(C1,'FUNC CURR'); % Set CC mode
fprintf(C1,'CURR:RANG MIN'); % Set low current range
fprintf(C1,'CURR 1.25'); % Set current sink to be 1.25A
fprintf(C1,'MEAS:CURR?'); % mearsure the input current
CurData = fscanf(C1)
CurVal = str2double(CurData);
And thus I use the same settings and commands in Query Instrument Block in Simulink, but there is no response from the instrument. I am not sure the parameters I set in the block are in correct format, here are my settings:
Block Sample Time: 1
Buffer Size: 512
Board Vendor: National Instruments
Board index: 0
Primary Address: 3
Secondary Address: 0
Send string: 'CHAN 2 ; INPUT OFF ; FUNC CURR ; CURR:RANG MIN ; CURR 1.25 ; :INPUT ON'
*I had also tried selecting Execute function, but not sure if I have to type fprintf or fprintf('CHAN 2 ; INPUT OFF ; FUNC CURR ; CURR:RANG MIN ; CURR 1.25 ; :INPUT ON').
Query command: 'MEAS:CURR?'
Data format: ASCII
ASCII format string: '%c' (I'd also tried '%1.3f')
Byte order: Little Endian
Checked "Remove any additional bytes from input buffer"
After initial response: Repeat query for new data
In addition, since I can obtain the instrument data via Matlab script and store it in workspace, is there any method to run a m-file in each time step in Simulink? I would like to import the measured data into my Simulink model and apply Simulink Destop Real-Time to do the real-time processing. However, I can't write the commands into Matlab Function Block because it exists an error "The 'gpib' class does not support code generation." and also don't know if callbacks can run the script automatically in every time step.
Any tips about setting Query Instrument Block or importing data from m-file would be greatly appreciated!