Code hangs while writing on a SerialPort
Ältere Kommentare anzeigen
I had a code running for 24/24 7/7 for almost a month. Now the same code is no loger working properly with no apparent change (I was also using a compiled version).
Matlab (2020a last updated) GUI is communicationg (serial port by a USB converter) with and Arduino witha custom protocol: sending (from GUI) 32 byte each second (triggered by a timer object in the gui) and receving 80 byte, twice each second (reading with a callback triggered by the terminator)
This is the serial configuration:
app.serConn = serialport(app.SelectedSerialPort,115200);
app.serConn.Timeout=1;
configureTerminator(app.serConn,"CR/LF");
configureCallback(app.serConn,"terminator",@(src,event,DataStorage)serConn_instrcallback(app,event));
flush(app.serConn);
This is the write commmand:
try
writeline(app.serConn,Serial_Send_Data);
catch e
disp(e.message);
disp('Error Writing Serial SerConn')
end
it was working properly now (after some working cycles, please note remote connection to PC make things worse) the system hangs
Pressing ^C the error show that is locked in the Serialport.m function
here at the wait for
try
data = varargin{1};
write(obj.StringClient, data);
% Wait for the write to be complete
waitfor(obj, "WriteComplete", true); %% HANGS HERE
catch ex
throwAsCaller(ex);
end
I have no choiche to catch the error just the ^C showing the problem
Commenting the waitfor command system works properly
Where am I wrong? How can avoid hanging or manage the problem?
Akzeptierte Antwort
Weitere Antworten (1)
Mario Silvagni
am 8 Sep. 2020
0 Stimmen
Kategorien
Mehr zu Serial and USB Communication finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!