Info
此问题已关闭。 请重新打开它进行编辑或回答。
What if Simulink can't achieve specified sample time?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm trying to create a simulink model to communicate with an external device. I have written a custom Level 2 Matlab S-Function to receive data from the device through TCP/IP, and specified a sample time for this S-Function block of 3 ms. I have added timing measurements and have concluded that the Output function of my custom block tasks a mean of 5.3 ms.
I have two questions about this. First, when happens with the timing if Simulink fails to achieve the specified sample time of a block? Does it just go as fast as it can?
Also, I understand that Matlab S-Functions are executed by running a Matlab Interpreter. However, when I take the exact same code that's in the Output function of my custom block and place it into a regular .m script and use the same timing measurements, then as a standalone script the code takes 2.4 ms to run. What is the reason for this significant slowdown? Below is the code for the Output function. (Note, the device is controlled through a C++ program that writes data to the socket, and this was consistent between the two tests.)
function Outputs(block)
global socket
socket.readasync();
if(socket.BytesAvailable > 0)
A = socket.fgetl();
entries = sscanf(A, '%f,');
if(length(entries) ~= 23) %known packet size
disp('Incorrect data packet format; missing data');
else
%parse data
block.OutputPort(1).Data = entries(1);
block.OutputPort(2).Data = entries(2:8)';
block.OutputPort(3).Data = entries(9:15)';
block.OutputPort(4).Data = entries(16:22)';
block.OutputPort(5).Data = entries(23);
end
end
b = toc;
block.OutputPort(6).Data = b-a;
block.OutputPort(7).Data = b;
%endfunction
Any help would be greatly appreciated! Thank you!
0 个评论
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!