Serial port slows / freezes after a few sends.

1 view (last 30 days)
Reuben
Reuben on 12 Oct 2013
Edited: Reuben on 12 Oct 2013
After sending X iterations of data over a serial port via fwrite/fprintf code begins to execute very slowly, one fwrite() call per 3 to 10 seconds. (X being nearly a random number from 3 to 1000+)
I am unsure where the problem is. The serial device is receiving the data.
clear, clc
count = 0;
delete(instrfindall)
socket = serial('COM11','BAUD',57600);
fopen(socket);
pause(3);
for i = 1:10000
count = count + 1;
disp(count)
fwrite(socket,'A','uint8')
%fprintf(socket,'%s','A')
pause (.01)
end
EDIT
Adding "stopasync(socket)" before calling "fprintf()" results in working code. Does anyone know why without "stopasync(socket)" the code fails? I currently suspect an hardware issue as the COM port is a USB port emulating a COM port.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!