Industrial communication toolbox (R2022a): function code for Modbus multiple holding registers write

13 views (last 30 days)
I wish to write an uint16 integer value to Fanuc CNC controller using the ModBus write function of the industrial communcation toolbox.
The FANUC controller only accepts 'multiple holding register write' (modbus function code 16).
If I run
m = modbus('tcpip', '192.168.1.10');
write(m,'holdingregs', 2, 100, 'uint16'); % other 'precision' formats, uint64, not work neither.
a communication error will occur.
Using other modbus program to issue the 'multiple register write' command work just fine.
How to force the matlab modbus write function to generate a function-code-16 write ?

Accepted Answer

Sivapriya Srinivasan
Sivapriya Srinivasan on 6 Oct 2023
Edited: Sivapriya Srinivasan on 9 Oct 2023
Hello,
I understand that you want to force the MATLAB Modbus write function to generate a function-code-16 write, you can use the following steps:
  1. First, make sure you have the Industrial Communication Toolbox installed in MATLAB.
  2. Create a Modbus object by specifying the communication type and the IP address of the FANUC controller. In this case, you are using TCP/IP, so the code would be:
m = modbus('tcpip', '192.168.1.10');
Set the 'FunctionCode' property of the Modbus object to 16, which corresponds to the "multiple holding register write" function code:
m.FunctionCode = 16;
Use the write function to send the data to the FANUC controller. Specify the register address, the value to be written, and the data type ('uint16' in this case):
write(m, 'holdingregs', 2, 100, 'uint16');
By setting the 'FunctionCode' property to 16 before calling the write function, you can force the MATLAB Modbus toolbox to generate a function-code-16 write command.
Make sure to check the documentation of the Industrial Communication Toolbox and the specific requirements of the FANUC controller to ensure proper configuration and communication.

More Answers (0)

Categories

Find more on MATLAB Mobile in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!