Hi,
i'm writing data of voltage and current to an instrument with scpi commands and it works fine. Now i'm trying to print the meassured data at the power supply controller via a 'query instrument'-block to a display, but receiving the error Response from instrument was non-numeric.
These are my configurations:
Is it possible to handle the response from the instrument with the 'query instrument' block?
Or is it possible to insert MATLAB-Code to my simulink model? Because with matlab code i received the meassured data, but i dont want to do it all by script, but with the simulink model.
THANKS IN ADVANCE!

 채택된 답변

Harald
Harald 2023년 6월 30일

0 개 추천

Hi Tobias,
to answer the final part: you can use the MATLAB Function block to incorporate MATLAB code into Simulink models.
Best wishes,
Harald

댓글 수: 4

Tobias Kammler
Tobias Kammler 2023년 6월 30일
편집: Tobias Kammler 2023년 6월 30일
So, the MATLAB-Code i used to read back and print the voltage is:
fprintf(serialObject,'MEasure:VOltage?');
V = fscanf(serialObject);
disp(V);
If i put this in a function block, the SCPI-command 'MEasure:VOltage?' has to be the input for the matlab function or do i use the function block without input, just the output "U"?
My idea for the code inside the block is
function Voltage = U
fprintf(serialObject,'MEasure:VOltage?');
V = fscanf(serialObject);
U = disp(V);
and this should print the meassured voltage every time step?!
I would rather use
function U = Voltage
fprintf(serialObject,'MEasure:VOltage?');
U= fscanf(serialObject);
serialObject will need to be a parameter. You can set these using the "Edit Data" menu in the top left.
Best wishes,
Harald
Tobias Kammler
Tobias Kammler 2023년 7월 4일
unfortunately this doesnt work. i get the following error:
The 'serial' class does not support code generation.
Function 'MATLAB Function' (#24.59.77), line 5, column 16:
"serial(serialPort)"
i also tried to generate to generate the serial object, like i did before with pure matlab code outside the simulink model
serialPort = 'COM4';
serialObject = serial(serialPort);
do you have an other idea to solve the query fromm the instrument from simulink?
Hi Tobias,
you need to declare all functions that are not supported for code generation but used in a MATLAB Function block as extrinsic, so e.g. also
coder.extrinsic('serial')
Keep in mind that this would open a new connection every time the block is executed. This may not be desirable.
Thus, I prefer the other approach of creating the connection in MATLAB. What problems did you run into when you tried this?
Best wishes,
Harald

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 C2000 Microcontroller Blockset에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2023년 6월 29일

댓글:

2023년 7월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by