Installation, IDE, Architecture and First Example (Linear Gauge)

We need to install the software before we start developing SCADA/HMI in the Beckhoff platform. As we have already understood the differences between HMI and SCADA, we shall mention only HMI on this page. Download the following software on your hard disk.

=> .Net 4.7.2 developer pack or equivalent (https://dotnet.microsoft.com/download/dotnet-framework/net472)

=> Visual Studio (2013, 2017 or 2019) community (make sure to include web-related components if visible) or pro version https://visualstudio.microsoft.com/downloads/

=> TwinCAT 3.1 – eXtended Automation Engineering (XAE), version 3.1.4024.7 (https://beckhoff.com/)

=> TE2000 | TC3 HMI  , version 1.10.1336.404 (https://beckhoff.com/)

Beckhoff software has an engineering version and run time version. We shall use the engineering version for developing the application and on the other hand, run time is used for only executing the program. One good example is that when we install Beckhoff TwinCat Software to PLC, we install only the run time version. Even it is not possible to install the engineering version to PLC due to memory constraints. The engineering version offers all the development, debug, etc tools on top of run time.

Download all the software and run those executables as administrator. Good to install visual studio before installing TwinCAT 3.1

Architecture, how HMI works in Windows platform

A Windows sockets (Winsock) is an application programming interface (API) that allows for communication between Windows network software and network services, such as Transmission Control Protocol/Internet Protocol (TCP/IP). Winsock is based on the Berkeley Unix sockets interface. These works on a client-server basis.

Operating systems Windows includes a data link layer named winsock.dll, which helps to make the Windows programs and the TCP/IP services work together. If you are more interested you could take a look at this link to know how these work. Since our job is to develop HMI we don’t need to know these in detail. Beckhoff has done it for us.

First Example (Linear guage)

We assume that the necessary software is installed. We shall build a project and test and publish it to a remote HMI server.

STEP 1: Start Visual Studio and open a new TwinCAT HMI project.

STEP 2: Select Tool Box (if not visible select View | Tool Box)

STEP 3: Drag and drop Linear gauge on the desktop view, make one of those vertical (properties | appearance | orientation)

The linear example final one is shown below. If we press on Start button then it will start reading the pressure sensor and display on the left side linear gauge. The Start button will be changed to Stop. If the PLC is already running then it will the status of the variable and set the text as needed.

PLC Source code behind the HMI

Since we don’t have an actual pressure sensor, we are using a small piece of structured text code for generating pressure sensor value. That pressure value is shown on the linear gauge. When the startTimer variable is TRUE then the timer will start and generates data (pressure value). the pressure value is shown on the Beckhoff HMI.

//Declaration
PROGRAM MAIN
VAR
pressureValue : REAL := 0.0;
myTimer : TON;
startTimer : BOOL := FALSE;
directionPlus : BOOL := FALSE;
END_VAR
//Body of the program
myTimer(IN:= startTimer, PT:= T#50MS);
IF myTimer.Q = TRUE THEN
myTimer(IN:= FALSE);
IF pressureValue >= 100 THEN
pressureValue := 100.0;
directionPlus := FALSE;
END_IF
IF pressureValue <= 0 THEN
pressureValue := 0.0;
directionPlus := TRUE;
END_IF
IF directionPlus = TRUE THEN
pressureValue := pressureValue + 1.0;
ELSE
pressureValue := pressureValue - 1.0;
END_IF
END_IF
HMI and the simulator PLC code relation


Above picture shows pressureValue is linked to Lineargauge and StartTimer is linked to Start button.

How to build the HMI

Few  steps are needed before reading the data from PLC (we assume that Button and Linear gauge are placed on the UI)

We need to bring those PLC variables available to the UI project. These are done for us by the framework, we just use those. More will be discussed in the next tutorial (Symbol Data)

First, we need to configure the  HMI Server

STEP 1: Select from the Menu  TWINCAT HMI | Windows | TwinCAT HMI Server configuration

STEP 2: Click on ADS | Runtimes | PLC1 and make the necessary changes as shown in the following figure. If we want to read from actual PLC, we shall use actual AmsNetId. The PLC should be in the same network (for more see our network tutorial)

 

Now we shall have a connection to our PLC but we need to tell the framework  which variables we want to manipulate  or want to listen. This process is called  symbol mapping

STEP 3: Now go back to  HMI Configuration Select from the Menu  TWINCAT HMI | Windows | TwinCAT HMI  configuration 

STEP 4: Select Server Symbols | All Symbols | then expand the ADS | PLC1 | MAIN | Map Symbol

STEP 5: Select pressureValue and startTimer variables and map them, these will be added to Mapped Symbols

 

 

Now let’s configure the button

STEP 6: Go to button events and pressed on  the edit icon,  drag  and drop  General | Condition to the right pane. Drag and drop WriteToSymbol to the THEN box and to ELSE box

STEP 7:  Select small square and Create data binding

STEP 8: Insert the Text field (selected control | Start | Common | Text)  and the value to STOP, this will indicate if the startTimer is TRUE then the button text will be Stop (more in the localizations tutorial)

Final STEPS:  Do the same for  .onPressed for the button  and for value for the linearGauge case as shown in the next few images. If you press on the Live view or debug with google chrome we see that value changes when we press the start button and stop when we press the stop button


Following figure shows how to configure the text of the button when the button is created by the framework. This is good place to check or set the text of a button or similar control

 

Following figure shows how to configure onPressed event for button. Write To Symbol statements are used 2 times in if branches.

 

Value property of the lineargauge has been configured  to the pressureValue variable in PLC

We shall add a video here soon, please do visit us again