Forum Home › Forums › Communicating with Devices › Modbus › Custom Command
- This topic has 5 replies, 2 voices, and was last updated 2 months ago by
Mikhail.
-
AuthorPosts
-
November 3, 2025 at 5:32 am #17245
123
ParticipantHello, regarding the send commands in Modbus, point 1 described below is originally built-in. Can points 2 and 3 be achieved using custom function codes? How can they be implemented?
1.The original data block is Holding Registers (4x), the read function code is 0x03, and the write command function code is 0x06.
2.Modify it so that the data block remains Holding Registers (4x), the read function code is 0x03, and the write command uses a custom function code of 0x07.
3.Change the data block to Input Registers (3x), the read function code to 0x04, and the write command to a custom function code of 0x06.
November 3, 2025 at 10:01 am #17251
MikhailModeratorHello,
2. In the Modbus template, add a new command, set the Data block to Custom, the function code to 7.
3. According to the Modbus specification, Input Registers are read-only. So it’s not possible to write them. You can try creating a separate command with the 0x06 code.
November 5, 2025 at 10:15 am #17265123
ParticipantI tried using a custom function code, as described in the example below. The function I sent was for reading, and the function code used was 0x00. Could you provide a detailed example of how to use custom function codes?
1.
<ElemGroup active=”true” dataBlock=”Custom” address=”0″ name=”定值”>
<Elem type=”ushort” readOnly=”false” isBitMask=”true” tagCode=”test1″ name=”test1″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test2″ name=”test2″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test2″ name=”test2″ />
</ElemGroup>
</ElemGroups>
<Cmds>
<Cmd dataBlock=”Custom” funcCode=”7″ cmdNum=”0″ cmdCode=”Custom” name=”Custom” />
</Cmds>November 6, 2025 at 11:14 am #17267
MikhailModeratorPlease provide screenshots of your settings and log files.
November 10, 2025 at 3:32 am #17269123
ParticipantIf I’m using the template with dataBlock=”HoldingRegisters”, as described below,how can I configure it to use function code 0x03 for reading and function code 0x07 for writing?
<?xml version=”1.0″ encoding=”utf-8″?>
<DeviceTemplate>
<Options>
<ZeroAddr>false</ZeroAddr>
<DecAddr>true</DecAddr>
<DefByteOrder2 />
<DefByteOrder4 />
<DefByteOrder8 />
</Options>
<ElemGroups>
<ElemGroup active=”true” dataBlock=”HoldingRegisters” address=”0″ name=”test”>
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test1″ name=”test1″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test2″ name=”test2″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test3″ name=”test3″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test4″ name=”test4″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test5″ name=”test5″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test6″ name=”test6″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test7″ name=”test7″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test8″ name=”test8″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test9″ name=”test9″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test10″ name=”test10″ />
<Elem type=”ushort” readOnly=”false” isBitMask=”false” tagCode=”test11″ name=”test11″ />
</ElemGroup>
</ElemGroups>
<Cmds>
<Cmd dataBlock=”Custom” funcCode=”7″ cmdNum=”1″ cmdCode=”Custom” name=”Custom” />
</Cmds>
</DeviceTemplate>November 10, 2025 at 9:26 am #17271
MikhailModeratorPlease provide screenshots of your settings and log files.
To upload screenshot use a file hosting or image hosting, for example https://imgbb.com/ -
AuthorPosts
- You must be logged in to reply to this topic.