Azzera filtri
Azzera filtri

Serial port slows / freezes after a few sends.

5 visualizzazioni (ultimi 30 giorni)
Reuben
Reuben il 12 Ott 2013
Modificato: Reuben il 12 Ott 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.

Risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by