How to set Query Instrument Block parameters in proper format?
9 views (last 30 days)
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!
Jan Houska on 18 Apr 2021
you cannot use gpib object with SImulink Desktop Real-Time in External mode because it does not support code generation. However, you can still use the object with SImulink Desktop Real-Time in Normal mode. To do that, please put the Real-Time Sync block into your model and run the model from the SIMULATION toolstrip tab (as opposed to the DESKTOP REAL-TIME tab).
Good Luck, Jan
Andrei Ursache on 29 Apr 2021
If you're using the gpib code within a MATLAB Function block, since it does not support code generation you need to declare gpib (and the gpib related functions you're using, i.e. fopen, etc.) with coder.extrinsic ( https://www.mathworks.com/help/simulink/function-definition.html ). Within a MATLAB Function block for setting/getting gbib property values you would also need to use the set and get functions rather than dot notation.
Another option would be to call your MATLAB function via an Interpreted MATLAB Function block ( https://www.mathworks.com/help/simulink/slref/interpretedmatlabfunction.html ).
For troubleshooting the behavior you are seeing with the Query Instrument block, consider contacting MathWorks support.