Serial port slows / freezes after a few sends.

1 次查看(过去 30 天)
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.

回答(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