Connection between HMI client and PLCnext Technology Controller
To check the connection between HMI client and PLCnext Technology controller via your control program, PLCnext Engineer provides HMI-specific system variables. These system variables allow you to retrieve, among other information, the station ID of the client and the time of the last request made by the client to the controller. By using this information, you can, for example, identify single clients from within your control program and stop the HMI application if the connection between client and controller is lost.
Example application: the user presses a button in the HMI application that writes a value to a variable which initiates a mechanical movement of a machine. Before initiating the mechanical movement, the control program checks whether the connection to the HMI client is alive (the LAST_REQ value of the HMI_STATUS variable shows the time when it was last heard from the client; see the decryption below). If the connection between the client and controller is lost, the mechanical movement can be stopped by the control program.
The HMI system variables are located in the Data List of the controller. To open the Data List, select the PLCnext Technology controller node in the PLANT and click the Data List editor in the editors area.
There are two HMI system variables for handling client connections:
- HMI_STATUS
- HMI_CONTROL
HMI_STATUS system variable
The read-only HMI_STATUS system variable provides status information about the HMI clients connected to the controller. The variable uses the HMI_STATUS_TYPE structure (ARRAY of STRUCT) to provide the information.
The HMI_STATUS_TYPE structure contains the members described in the following table. You can display the members of the structure in the 'Init Value Configuration' editor. To open the editor, select the context menu item 'Show Init Value Configuration' of the system variable in the Data List editor or click the icon on the variables table/'Data List' toolbar.
'Init Value Configuration' editor with HMI_STATUS system variable
System variable/elements | Data type | Description |
---|---|---|
HMI_STATUS | HMI_STATUS_TYPE (ARRAY of STRUCT) | Provides information on the web server that can be programmed in PLCnext Engineer. |
CLIENT_COUNT | UINT | Number of existing client connections to the web server at runtime. |
CLIENTS [1]...[256] | ARRAY of STRUCT per client connection | Information on existing client connections (1...256). |
SESSION_ID | STRING | Session ID of the client connection. |
STATION_ID | STRING | Station ID of the client connection. |
LAST_REQ | LINT | Time when it was last heard from the client, i.e., how long the client was up. |
IP_ADDRESS [0]...[3] | BYTE | IP address of the connected client in hexadecimal format:[C0].[A8].[01].[64] ⇒ 192.168.1.100 |
Using the HMI_STATUS system variable
In order to use the HMI_STATUS variable, each client instance has to be assigned a unique StationID (integer value). The station ID value of the client is assigned to a specific client instance by appending the value with the StationID parameter to the URL entered in the address bar of the web browser (see the following example).
Note
Parameters can be passed to an URL by appending the parameter after the question mark (?) in the URL. The value for the parameter is specified after the equals character (=). Multiple parameters can be passed to the URL by separating them with the ampersand character (&) as shown in the following example (here the station ID and the default language of the HMI client when the visualization is started are passed to the URL). Example: https://192.168.1.10/ehmi/hmiapp.html?StationID=222&language=en See the topic "Running the HMI Application" for details on how to call the HMI visualization via the web browser and to pass parameters to the URL. |
Example:
The following example URL connects a client with the StationID 222 to the web server. This client and the related information can be found in the HMI_STATUS_TYPE structure as shown in the figure below (the figure shows the HMI_STATUS variable in the WATCHES window). In the example, the client is shown in the array field [2]. (There is no order inside the HMI_STATUS_TYPE structure when different clients are connected.)
https://192.168.1.10/ehmi/hmiapp.html?StationID=222
To disconnect the client from the web server, you can use the HMI_CONTROL system variable (see below). The client to disconnect is shown in the same array field as the client in the HMI_STATUS_TYPE structure (in our example, this is array field [2]).
Further Info
For details how to call the HMI visualization via the web browser and how to pass start parameters the URL, see the topic "Running the HMI Application". |
HMI_CONTROL system variable
The write-only HMI_CONTROL system variable can be used to disconnect the HMI clients from the web server via the control program (for example, for maintaining purposes). The variable uses the HMI_CONTROL_TYPE structure (ARRAY of STRUCT) containing one DISABLE element per client. Setting the DISABLE element for a specific client to TRUE in the control program disconnects the client from the server.
The client to disconnect is shown in the same array field as the client in the HMI_STATUS_TYPE structure (see the example above).
'Init Value Configuration' editor with HMI_CONTROL system variable