Serial fread is too slow

8 views (last 30 days)
Nikolay Konstantinov
Nikolay Konstantinov on 11 Feb 2018
I'm using MATLAB R2017a & Linux.
version -java
'Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode'
The program below, 75% of time spends onto fread(). How can it be speed-up?
s = serial(serial_port,'BaudRate',baud_rate,'DataBits',8,'InputBufferSize',buffer_size);
fopen(s);
size_to_read=s.BytesAvailable;
if (size_to_read>10)
out = fread(s,size_to_read,'uint16')
// some code //
end
Probably direct access for Java will be faster, but I dont know how.
Another solution is use this MEX https://nl.mathworks.com/matlabcentral/fileexchange/62545-mex-c-serial-interface This output is 8bit digits, but I need 16 bit, can it be changed?
  8 Comments
Walter Roberson
Walter Roberson on 12 Feb 2018
There is no problem using nested functions for callbacks or using shared objects with serial ports, and doing so is often a good structuring mechanism. Shared variables are one of the faster forms of variable access.
I notice that you are using // for comments. Those are not supported for MATLAB, which suggests you are possibly using Octave.
Tillmann Spellauge
Tillmann Spellauge on 6 Jan 2019
I have a similar problem.
I am using Matlab R2018b and linux. My program is spending 90+% of its runtime in "com.mathworks.toolbox.instrument.SerialComm". More specifically in the igetfield() function used in line 150 of the fscanf() function. It also makes no difference using fread(), fgets() or fgetl().
Did you eventually find a solution?

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!