Send and Receive via serial port execution time
Show older comments
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
1 Comment
Oleg Komarov
on 25 Apr 2011
Remove the duplicate post.
Accepted Answer
More Answers (0)
Categories
Find more on Workspace Variables and MAT Files 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!