필터 지우기
필터 지우기

Programmable power supply not able to send value through COM

조회 수: 3 (최근 30일)
Srinivas Anegundi
Srinivas Anegundi 2022년 5월 18일
답변: Sivapriya Srinivasan 2023년 10월 6일
%Create a serial port object.
obj1 = instrfind('Type', 'serial', 'Port', 'COM10', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial('COM10');
else
fclose(obj1);
obj1 = obj1(1)
end
% Connect to instrument object, obj1.
fopen(obj1);
% Communicating with instrument object, obj1.
a=20;
a=num2str(a);
data1 = query(obj1, "VSET1:a");
I am not bale to send integer values to a , can anybody help please

답변 (1개)

Sivapriya Srinivasan
Sivapriya Srinivasan 2023년 10월 6일
Hello,
I understand to send integer values to your instrument using serial port object in matlab, want to convert integer to string before sending it .In this updated code, the integer value a is converted to a string a_str using the num2str function.
% Create a serial port object
obj1 = instrfind('Type', 'serial', 'Port', 'COM10', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial('COM10');
else
fclose(obj1);
obj1 = obj1(1);
end
% Connect to the instrument object, obj1.
fopen(obj1);
% Communicate with the instrument object, obj1.
a = 20;
a_str = num2str(a); % Convert the integer to a string
command = "VSET1:" + a_str;
data1 = query(obj1, command);
% Close the serial port connection
fclose(obj1);
Then, the command string is constructed by concatenating the value with the command prefix. Finally, the command is sent to the instrument using the query function. By using the query function, you can send a command to the instrument and receive the response from it. The specific command and its expected response should be defined in the instrument's documentation or communication protocol.
Make sure to replace "VSET1:" with the appropriate command for your instrument. This code should allow you to send integer values to your instrument successfully.
Hope this helps!

제품

Community Treasure Hunt

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

Start Hunting!

Translated by