UF_ModbusTCP_Manual

UFACTORY ModbusTCP User Instructions

Notice:

  • Communication complies with standard Modbus TCP protocol

  • Data transmission uses Big-endian method, for example transmission order of data 0x1234 is: 0x12, 0x34

  • Different register addresses hold different specific contents, details refer to the appendix

  • Make sure to access the pre-defined register address(refer to appendix),or there will be exception in response

Supported Modbus TCP function codes:

  • Coil register(1 bit)

    • 0x01: Read multiple coil registers,each bit in responded data section represents the value of each one register:

      // sample request and response / exception
      // Request: Read consecutive 16 registers starting from address 0x0000
      00 01 00 00 00 06 01 01 00 00 00 10
      // Response: every bit in the Received data (0xF7 0x00 here as an example) represents the corresponding register value in order
      00 01 00 00 00 05 01 01 02 F7 00
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 81 XX
    • 0x05: Write single coil, according to Modbus protocol, specified data can only be 0xFF00 or 0x0000,for wriring 1 or 0 to the register.

      // sample request and response / exception
      // Request: Write 1 to register address 0x0002 (0xFF00 for writing 1, 0x0000 for writing 0)
      00 01 00 00 00 06 01 05 00 02 FF 00 
      // Response:
      00 01 00 00 00 06 01 05 00 02 FF 00
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 85 XX
    • 0x0F: Write multiple coil registers

      // sample request and response / exception
      // Request: write 3 registers starting from address 0x0002, 0x07 in binary form is for writing all 1s in the three registers.
      00 01 00 00 00 08 01 0F 00 02 00 03 01 07
      // Response:
      00 01 00 00 00 06 01 0F 00 02 00 03
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 8F XX
  • Discrete input register (1 bit)

    • 0x02: Read multiple discrete input registers

      // sample request and response / exception
      // Request: Read 16 consecutive registers from address 0x0000
      00 01 00 00 00 06 01 02 00 00 00 10
      // Response:: every bit in the Received data (0xFF 0x00 here as an example) represents the corresponding register value in order
      00 01 00 00 00 05 01 02 02 FF 00
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 82 XX
  • Holding register (16 bit)

    • 0x03: Read multiple holding registers

      // sample request and response / exception
      // Request: read 2 consecutive holding registers starting from address 0x0003
      00 01 00 00 00 06 01 03 00 03 00 02
      // Response:: Received values of the two registers are (00 05) and (00 06) as an example here
      00 01 00 00 00 07 01 03 04 00 05 00 06
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 83 XX
    • 0x06: Write single holding register

      // sample request and response / exception
      // Request: Write 0x0006 to register address 0x0020
      00 01 00 00 00 06 01 06 00 20 00 06
      // Response:
      00 01 00 00 00 06 01 06 00 20 00 06
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 86 XX
    • 0x10: Write multiple holding registers

      // sample request and response / exception
      // Request: Write consecutive 2 registers from address 0x0003
      // the written values are (04 D2) and (0D 80), with corresponding decimal values of 1234 and 3456
      00 01 00 00 00 0B 01 10 00 03 00 02 04 04 D2 0D 80
      // Response:
      00 01 00 00 00 06 01 10 00 03 00 02
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 90 XX
    • 0x16: Mask write single holding register

      // sample request and response / exception
      // Request: write to register address of 0x0000 with mask.
      // "AND" operation mask is (00 0F),"OR" operation mask is (0F 00)
      // If the value before this operation is "val", then after the mask opeation it becomes: (val & 0x000F) | (0x0F00 & ~0x000F)
      00 04 00 00 00 08 01 16 00 00 00 0F 0F 00
      // Response:
      00 04 00 00 00 08 01 16 00 00 00 0F 0F 00
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 96 XX
    • 0x17: Read and Write multiple holding registers

      // sample request and response / exception
      // Request: Write 2 registers from address 0x0020, and read 2 registers from address 0x0003
      // values to be written are (00 06) and (00 04)
      00 01 00 00 00 0F 01 17 00 03 00 02 00 20 00 02 04 00 06 00 04 
      // Response:  Received values of the two registers are (04 D1) and (0D 7F) as an example here  
      00 01 00 00 00 07 01 17 04 04 D1 0D 7F 
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 97 XX
  • Input register (16 bit)

    • 0x04: Read multiple input registers

      // sample request and response / exception
      // Request: read 2 consecutive holding registers from address 0x0003
      00 01 00 00 00 06 01 04 00 03 00 02
      // Response: Received 2 values are (00 0E) and (00 13) as an example
      00 01 00 00 00 07 01 04 04 00 0E 00 13
      // Exception: XX is the exception code
      00 01 00 00 00 03 01 84 XX

Exception code explanation

  • 0x01: Illegal/Unsuppported function code

  • 0x02: Illegal target address

  • 0x03: Exception of requested data

Appendix

  • Coil Registers (single bit access, READ/WRITE)

  • Discrete Input Registers (single bit access, READ only)

  • Holding Registers (16 bit access, READ/WRITE)

  • Input Registers (16 bit access, READ only)

Last updated