Modbus/RTU Master Communication Sample Program


■ Explanation

 

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

Modbus/RTU communication can be executed by specifying the COM port, setting the baudrate and parity etc.

 

■ Screen Image

 

 

■ Step to Use

 

  1. Enter the COM port, baudrate, parity bit, data bit, and stop bit to be used, then execute [modbus_new_rtu].
  2. Please specify the slave ID in [modbus_set_slave].
    * Set various serial settings and slave ID according to the settings of the device to communicate with.
  3. Use [modbus_connect] to connect with the device.
  4. 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.

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