Modbus TCP: Read successful, write unsuccessful

조회 수: 10 (최근 30일)
Kamal Baghirli
Kamal Baghirli 2023년 6월 21일
답변: Amir Tairi 2024년 1월 30일
Hi all.
I have connected a PC to a Bachmann M1 Controller using Modbus tcp/ip connection in MATLAB. Now I want to read/write variables from/to a Simulink model which is deployed and running on the controller. So I have created variables in Simulink using SVI-SW blocks (provided by Bachmann M-target), and mapped those variables to holding registers and given them indexes of 0 and 100.
When I try to read those variables from MATLAB command line, it returns correct value. But when I try to write, it returns invalid address error.
Reading:
>> b = read(m, 'holdingregs', 1, 1, 'double')
b =
0
Writing:
>> write(m, 'holdingregs', 1, 89, 'double')
The Modbus server returned an invalid address error. Address + number of values to write is out of range.
The variable at address 1 is an input to the Simulink via SVI block, and can be read and written to. And the address 1 should not be out of range as I have defined variable in that address and it can be read successfully.
Does anyone have an idea of what might be wrong?
Thanks :)

답변 (2개)

Sanjana
Sanjana 2023년 8월 24일
Hi Kamal,
I understand that you are facing an issue with the “write” operation performed over a “Modbus TCP/IP” connection.
This is an externally reported bug, and since you are using “R2021b” MATLAB Version, please install “Update 5” for the “R2021b” MATLAB Version, as mentioned in the bug fixes.
Please refer to the following link, for further information.
Hope this helps.
Regards,
Sanjana.
  댓글 수: 1
José Rudiney De Sousa Miranda Júnior
편집: José Rudiney De Sousa Miranda Júnior 2023년 11월 12일
I have the same problem, but i connect a Mitsubishi Q03UDE to PC, I can read but I cant write. and I use "R2023b"

댓글을 달려면 로그인하십시오.


Amir Tairi
Amir Tairi 2024년 1월 30일
Hello,
I recently encountered a similar issue and found a solution that worked for me. I simply incremented the coil or register address by 1. For instance, if the documentation indicates that the write address is 402, you should actually use 403. This adjustment resolved the problem in my case.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by