delay sending data rs232
Show older comments
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);
Answers (1)
Vidhi Agarwal
on 4 Dec 2024
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!
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!