How do I get an array of serial readings if readout isn't working with my device?

So my code looks as follows:
check = serialportlist; %all ports
checkAv = serialportlist('available');
if numel(checkAv)==1
%use it
COMc = checkAv{:};
else
choseComId = listdlg('Chose COM',checkAv);
COMc = checkAv{choseComId};
end
bc_obj = serialport(COMc, 115200);
flush(bc_obj);
configureTerminator(bc_obj,"CR/LF");
writeline(bc_obj,"mOn 1000");
disp = readline(bc_obj);
And when I run it, I end up getting a timeout warning.
Warning: The specified amount of data was not returned within the Timeout period for 'readline'.
'serialport' unable to read any data. For more information on possible reasons, see serialport Read Warnings.
This doesn't seem to happen whenever I use read on my code, but I need to have more than the alotted characters being read.

1 Comment

I recommend writing an empty lne before the mOn command, in case there happens to be some junk in the buffer.

Sign in to comment.

Answers (1)

Hi David,
The Warning is related to a timeout issue. For more information about this warning refer to the following documentations,
For resolving timeout issues refer to the timeout documentation.
Setting a longer timeout value, according to the length of the input data, resolve the issue.
Kiran Felix Robert

Products

Release

R2020a

Tags

Asked:

on 24 Aug 2020

Commented:

on 28 Aug 2020

Community Treasure Hunt

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

Start Hunting!