Send and Receive via serial port execution time

2 visualizaciones (últimos 30 días)
MrPuzzled Marc
MrPuzzled Marc el 25 de Abr. de 2011
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Abr. de 2011
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.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by