Serial fread is too slow

3 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
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)

Community Treasure Hunt

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

Start Hunting!