Modbus TCP slave

You can use a Modbus master application to connect to KINGSTAR PLC Runtime (Modbus TCP slave) and access the variables you created. There are many Modbus master applications. In this guide, we use ModScan64 as an example.

NOTE:  ModScan64 is a trademark of WinTECH Software Design. The official website is https://www.win-tech.com/.

  1. In KINGSTAR Control Panel, turn on KINGSTAR PLC.
  2. Configure your firewall rules to open the TCP port 502. This is the port used by the Modbus master. If you are using Windows Firewall, go to Control Panel >System and Security > Windows Defender Firewall > Advanced settings to configure its rules. If you are using other firewall, consult your IT department.
  3. In KINGSTAR LogicLab, in the Resources panel to the left, click Modbus Slave.
  4. In the Resources panel in the middle, click the blue plus to add a variable.
  5. In the Select Block dialog box, click 4 Read-write (numeric) data, and click OK.
  6. A variable is added. Double-click its Variable cell and change the name to pos (or other meaningful name).
  7. NOTE:  To edit the value in other cell, double-click it.

  8. Add more variables to the table.
  9. Compile and download your PLC program to the KINGSTAR PLC Runtime. For more information, see Compile and run your PLC program.
  10. In the Project panel, expand Modbus_Slave_Variables, drag the Modbus variables into the Watch panel.
  11. NOTE:  To display the Watch panel, on the View menu, click Tool windows > Watch.

  12. Start ModScan64. In the ModScan641 window, enter the following information:
  13. Address: 1 (Modbus displays 0001). This is the address of the variable we created in LogicLab. It depends on where you want to get the data. For example, if you want to access from the variable whose address is 1, enter 1.

    Length: 3. This determines how many variables in a row you want to access. 1 means that Modscan reads or writes one variable. For example, we entered 1 for Address and 1 for Length. That means we only want to get data from the variable whose address is 0001. If we enter 3 for Length, we'll get data from the variables whose addresses are 0001, 0002, 0003.

    Device Id: 1. This is the ID for Modbus TCP. It can be 1-256.

    MODBUS Point Type: 03: HOLDING REGISTER. This type is to read and write 16-bit data.

  14. On the Connection menu, click Connect.
  15. In the Connection Details dialog box, in the Connect Using list, make sure Remote modbusTCP Server is selected. In the IP Address box, enter the IP address of the computer that has KINGSTAR PLC Runtime installed. In the Service Port box, enter "502." When you finish editing, click OK.
  16. The connection should be established immediately. The variables are displayed. Since we added three variables, you should see the address 40001, 40002, 40003. The first number "4" corresponds to the data block prefix of the Modbus server in LogicLab.
  17. To change the variable's value, in the gray pane, double-click the displayed variable. In the Write Register dialog box, in the Value box, enter a value. For example, we changed the value in the address 40001 to 200. Click Update to update the value.
  18. In the Watch panel, POS's value (address 40001) is changed to 200.