Serial fread is too slow
6 次查看(过去 30 天)
显示 更早的评论
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
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
2019-1-6
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!