Custom Command

Forum Home Forums Communicating with Devices Modbus Custom Command

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #17245
    123
    Participant

    Hello, 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.

    #17251
    Mikhail
    Moderator

    Hello,

    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.

    #17265
    123
    Participant

    I 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>

    #17267
    Mikhail
    Moderator

    Please provide screenshots of your settings and log files.

    #17269
    123
    Participant

    If 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>

    #17271
    Mikhail
    Moderator

    Please provide screenshots of your settings and log files.
    To upload screenshot use a file hosting or image hosting, for example https://imgbb.com/

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.