Timeout does not work for modbus (TCP/IP transport)
이전 댓글 표시
m = modbus('tcpip', '192.168.15.25', 502, 'Timeout', 1)
m = modbus('tcpip', '192.168.15.25', 502)
Running the first command, I was expecting to get timeout error after 1 second, but I get timeout error after 20 seconds, same as running the second command.
m = modbus('serialrtu','COM3','Timeout',1)
Timeout works with 'serialrtu', but does not work with 'tcpip'.
Matlab 2018b
My IP address: 192.168.15.3
Subnet mask: 255.255.255.0
Could anyone help please? Thanks.
댓글 수: 1
Enrico Segre
2022년 10월 26일
+1, and for me the timeout on creation is fixed to 120sec, which is even more annoying
답변 (2개)
Enrico Segre
2022년 10월 26일
편집: Enrico Segre
2022년 10월 26일
I pinpointed the problem in my installation (2021a) down to method createAndConnect() of /usr/local/MATLAB/R2021a/toolbox/instrument/instrument/+instrument/+interface/+modbus/+tcpip/Modbus.m. This method creates an object of class matlabshared.network.internal.TCPClient. As such, that does have a public property ConnectTimeout,which is neither passed as an argument, nor set in this constructor. I found that as a default, it has value Inf.
To reduce the timeout to for instance 2 seconds I can add a
obj.TcpIpObj.ConnectTimeout=2;
in createAndConnect(), after line 142 of Modbus.m in my version. This of course requires write access to the matlab installation, and obviously is an inflexible and unportable solution.
Enrico Segre
2025년 11월 16일
0 개 추천
Coming back to report, in case someone with the same problem stumbles here: there seems to be a workaround, sanctioned recently by the support staff: https://www.mathworks.com/matlabcentral/answers/2178749-how-to-configure-the-timeout-property-using-the-modbus-function-in-matlab-r2024a
The solution is quoted for r2024a, but it seems to work in my r2020b as well.
카테고리
도움말 센터 및 File Exchange에서 ActiveX에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!