delay sending data rs232

조회 수: 3 (최근 30일)
Oday Shahadh
Oday Shahadh 2021년 8월 17일
답변: Vidhi Agarwal 2024년 12월 4일
hello,
Can any one help on hpe to delay the (vv) values to be delayed in sending every 2 seconds?
clc
clear all
%s = serial('COM1','BaudRate',9600,'ByteOrder','bigEndian','FlowControl','none','Terminator','','TimeOut',10);% baud
s=serial('COM7','BaudRate', 9600, 'Terminator', 'CR','ByteOrder',...
'BigEndian','InputBufferSize',256,'TimeOut',10);
fopen(s);
%get(s);
% fprintf(s,'*idn?');
% out0 = fscanf(s)
% fprintf(s,':syst:err?');
% out1 = fscanf(s)
fprintf(s,'OUTP:STAT 1');
cc=3;
cmd = num2str(cc,':CHAN1:CURR\b %2.2f;CURR?')
fprintf(s,cmd);
%out2 = fscanf(s)
vv=[2,4,6,8]; %%%%%%%%%%%%%%
vmd = num2str(vv,':CHAN1:VOLT\b %2.2f;VOLT?')
fprintf(s,vmd);
%out3 = fscanf(s)
fprintf(s,':CHAN1:MEAS:CURR?');
%out4 = fscanf(s)
fprintf(s,':CHAN1:MEAS:VOLT?');
%out5 = fscanf(s)
%fprintf(s,'OUTP:STAT 0');
fclose (s);
delete (s);

답변 (1개)

Vidhi Agarwal
Vidhi Agarwal 2024년 12월 4일
To introduce a delay between sending each value from the vv array, you can use MATLAB's "pause" function. This function will pause the execution of your script for a specified number of seconds. Follwoing is the sample code that can help you in understanding the implementation for the same.
% Voltage values to be sent
vv = [2, 4, 6, 8];
% Loop through each voltage value, send it, and pause for 2 seconds
for i = 1:length(vv)
vmd = sprintf(':CHAN1:VOLT %2.2f;VOLT?', vv(i));
fprintf(s, vmd);
pause(2); % Pause for 2 seconds
end
To read more about "pause" function in MATLAB refer to the given documentation: https://www.mathworks.com/help/matlab/ref/pause.html
Hope this helps!

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by