Modbus Configurator/zh-hans

From SoftMC-Wiki
< Modbus Configurator
Revision as of 09:28, 6 July 2017 by Chi (talk | contribs) (Created page with "{{Languages}} =Modbus Configurator= The Modbus Communication Scripts Generator ('''Modbus Configurator''') is a tool that allows you to map your softMC application variables t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
语言: [[::Modbus Configurator|English]]  • [[::Modbus Configurator/zh-hans|中文(简体)‎]]

Modbus Configurator

The Modbus Communication Scripts Generator (Modbus Configurator) is a tool that allows you to map your softMC application variables to Modbus tags.

Note: Tag access is defined from the HMI perspective. In other words:

  • Read Access variables are written by the softMC to the Modbus address space.
  • Write Access variables are read by the softMC from the Modbus address space.

You can define whether a variable has Read Access (meaning it is read by the HMI/PLC), or Write Access (meaning it is written by the HMI/PLC). Currently, it is not possible to define a variable as having both Read Access and Write Access. However, all Write Access variables can be written once by the softMC upon system startup by a special routine that is generated in HMIMBMAP.LIB (see section below).

The MCMBConfigurator creates three files:

  • HMIMBMAP.LIB and HMIMBMAP.PRG files are MC-Basic scripts that are used to start a softMC task. These are default file names, which you can change, but must retain the 8.3 format. This task cyclically and indefinitely reads/writes Modbus tags according to access type.
  • A .CSV format file that can be used by an HMI development environment, such as JMobile Studio or Indusoft, to automatically import Modbus tags. You define the HMI development environment by selecting various Python scripts that will generate the .csv file.

Mapping Variables

Note: Variables destined to be mapped to Modbus tags must be defined as global variables by the Common Shared declaration.

1. In order to map the variables, the program must be loaded in the softMC.

2. Start the Modbus Configuration: from the ControlStudio toolbar, select Tools, and then Modbus Configurator…

The Modbus Configurator windows opens.

3. Click Connection, and select Setting.

The setting dialog box opens, with fields showing the following (default) settings:

softMC Modbus HMI (3).png

  • Modbus offset: Used to start the mapping from an address other than zero.
  • Script file name: A Python script that generates the product files. Different scripts create different .csv files.
  • Output LIB, Output Prog, HMI CSV file name: Used to define target file names.
Note: The softMC file names must be UPPERCASE and in 8.3 format.
  • MC IP address: Used to set the IP address of your softMC.

Make any necessary changes in the Settings dialog box. Then click Connection, and then Connect.

Once the Modbus Configurator is connected to softMC it gets updated with the complete list of all the global variables. Double-clicking on variables automatically maps them to Modbus tags in consecutive order. The automatic Modbus address and data type are displayed in the table.

If a mapped variable is defined as CONST, its access type is automatically set to Read. In such instances the access type cannot be changed. Read Access variables are read only by the HMI; therefore the softMC only writes them to the Modbus address space.

A variable that is not defined as CONST automatically appears as Write Access. Double-click on the access type to toggle the variable between Read Access and Write Access, and thus determine whether the variable will be read or written by softMC.

softMC Modbus HMI (4).png

Generating and Using Scripts

After you are done mapping variables and defining the access types, a snapshot of the current configuration must be saved in order to generate the Modbus-handling scripts.

1. Click Files, and then Save As.

The mapping is saved in an .mbas file.
If you makes changes after saving the .mbas file, the MBAS file indicator in the status bar will light up.

2. To generate the product files, click Generate.

The Log windows will display Success messages.
The product files were created in the target folder you chose when saving the .mbas file.
The files HMIMBMAP.LIB and HMIMBMAP.PRG will automatically open in ControlStudio.

softMC Modbus HMI (5).png


Using the Modbus-Handling Scripts

1. Using the ControlStudio File Manager, copy HMIMBMAP.LIB and HMIMBMAP.PRG to the softMC.

Note: Before these files can be loaded and used, your application must be loaded, and all mapped variables must exist in the softMC memory.

softMC Modbus HMI (6).png

1. Using the ControlStudio Terminal, load the library HMIMBMAP.LIB:

Load HMIMBMAP.LIB
Since HMIMBMAP.PRG imports this library it must not be loaded globally. This code can be executed wherever is convenient.

2. Verify that the library was loaded successfully:

?tasklist

3. Start the Modbus communication task by loading the program:

Load HMIMBMAP.PRG

HMIMBMAP.PRG is defined as Program Continue, therefore it starts automatically after it is loaded and it does not require an explicit StartTask command.

Of course, HMIMBMAP.PRG can be loaded and executed only after HMIMBMAP.LIB is loaded. Therefore, you should add the following code to AUTOEXEC.PRG or wherever is convenient:

Load HMIMBMAP.LIB
Load HMIMBMAP.PRG

HMIMBMAP.PRG Explained

The code:

import HMIMBMAP.LIB
Program Continue
	dim retVal as long = 0
	retVal = Init_Modbus
	while 1
		retVal = Read_Modbus_Registers
		retVal = Write_Modbus_Registers
		sleep 1
	end while
End Program

The functions Init_Modbus, Read_Modbus_Registers and Write_Modbus_Registers are implemented in HMIMBMAP.LIB, which is automatically generated by a Python script.

The function Init_Modbus starts the Modbus server and then writes to the Modbus address space all the Write Access Variables (i.e., all the variables read by the softMC from the Modbus address space). This feature allows you to setup the system to start with an initialized Modbus address space before the HMI/PLC connects to it. The HMI/PLC can read the address space and initialize itself accordingly.

The functions Read_Modbus_Registers and Write_Modbus_Registers are invoked cyclically and indefinitely. Read_Modbus_Registers reads all the tags that are written by the HMI/PLC and updates the Write Access variables with new values, while Write_Modbus_Registers does the opposite.