Serial fread is too slow

6 次查看(过去 30 天)
Nikolay Konstantinov
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 个评论
Walter Roberson
Walter Roberson 2018-2-12
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
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?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by