Modbus/TCP Master Communication Sample Program


■ Explanation

 

This is a sample program of Modbus/TCP master created in C++, C#, and VB.Net.

Modbus/TCP communication can be executed by specifying the IP address and communication port.

 

■ Screen Image

 

 

■ Step to Use

 

  1. Enter the IP address of the device you want to access and the port number to use, then execute [modbus_new_tcp].
  2. Use [modbus_connect] to connect with the device.
  3. To input or output via Modbus communication, please click the button after setting the parameters of each function code.
    * Please refer to the following for the function code corresponding to each button.

    Function Code

    Button Name (Function Name)

    ReadCoils (FC 1)

    modbus_read_bits

    ReadDiscreteInputs (FC 2)

    modbus_read_input_bits

    ReadHoldingRegisters (FC 3)

    modbus_read_registers

    ReadInputRegisters (FC 4)

    modbus_read_input_registers

    WriteCoil (FC 5)

    modbus_write_bit

    WriteRegister (FC6)

    modbus_write_register

    WriteMultipleCoils (FC15)

    modbus_write_bits

    WriteMultipleRegisters (FC16)

    modbus_write_regsiters


    Data format for sending and receiving is as follows.

    - Send Data (Hex)
       Example) 01 0D AD

    - Receive Data (Hex)
       Example) 01 0D AD

    - Send Data (Bin)
       Example) 0 1 1

    - Receive Data (Bin)
       Example) 0 1 1

    In this sample, the maximum number of reading is 2000 bits / 125 words, and the maximum number of writing is 1968 bits / 123 words.
    * This is the maximum value of the Modbus specifications.

  4. Use [modbus_close] to disconnect from the device.
  5. Use [modbus_free] to free the memory allocated.
  6. Click the close button to exit the program.