Send and Receive via serial port execution time

조회 수: 2 (최근 30일)
MrPuzzled Marc
MrPuzzled Marc 2011년 4월 25일
Hi, I have a questions. I have created a code for send and receive binary bits via serial port. However, this need very long execution time. Anyone knows how to improve on this?
%Send
send_count=1;
loop_count=0;
while send_count < looptimes+2;
if strcmp(s.PinStatus.ClearToSend, 'on') && send_count <looptimes+1
C=[];
for i=1+5000*(send_count-1):5000*send_count
C=[C F((-15+16*(i)):16*(i))]; %Arrange in 16bits and send over
end
fprintf(s,C)
send_count=1+send_count;
end
end
s.RequestToSend='off';
guidata(hObject,handles);
% --- Executes on button press in Receive.
function Receive_Callback(hObject, eventdata, handles)
% hObject handle to Receive (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Save_file=get(handles.EditSaveAs,'String');
if isempty (Save_file)
msgbox('No File Selected!','Error','error');
else
s.RequestToSend='off';
s.RequestToSend='on';
received_count=1;
loop_count=0;
file=[];
while strcmp(s.PinStatus.ClearToSend,'on')
s.RequestToSend='on';
received=fgetl(s);
file=[file received];
received_count=received_count+1;
set(handles.EditStatusBar, 'String', 'Receiving....');
pause (0.2);
loop_count=0;
s.RequestToSend='off';
size_byte=fix(size(file)/32);
M=size_byte(2);
Video_bin=[];
for j=1:M
b=16*(j);
a=-15+b;
Video_bin= [Video_bin;file(a:b)];
end
Video_dec=bin2dec(Video_bin);
fid1=fopen (Save_file, 'wb');
count=fwrite(fid1, Video_dec, 'uint16');
Can thin

채택된 답변

Walter Roberson
Walter Roberson 2011년 4월 25일
Testing RTS and CTS can take a long time. It is of no practical use to manipulate or test those lines yourself unless you are using a half-duplex transmission scheme. You should instead switch to hardware flow control.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by