TwinCAT HMI Scope

The TwinCAT Scope:

The TwinCAT Scope extension enables connection to a TwinCAT Scope Server. For this purpose, an existing Scope project (.tcscopex file) can be integrated into the TwinCAT HMI. The visualization of the client takes place in Scope Control. The configuration of the charts (e.g. linking with the PLC variables, configuration of the axes, etc.) is done in the Scope project itself.

We need the following

 

Actual PLC project (the project which is under testing)

A scope project part of the PLC project solution in Visual Studio.

An HMI scope project, which is part of the HMI project 

Actual PLC project

We have a sample fictitious project where we have pressure sensor data and temperature sensor data of a pump. The pump works and generates vacuum (under pressure) and pressure above the atmospheric pressure in cyclic order (just to have some data for our scope project). We monitor another similar variable temperature. We shall monitor these two variables by the scope. We shall develop the sample for PLC, TwinCAT Scope, and HMI scope. The TwinCAT scope project is normally part of the TwinCAT project. If we want to see the data we need the scope project, Visual Studio and so on. The HMI scope project makes these data visible in the HMI so our operator does not need to use the Visual Studio Scope project. This way, we can see the data or the graph in our browser. We shall show all these steps in this tutorial.

STEP 01:

First, we create a simple TwinCAT project in Visual Studio and make sure it compiles and work. The code is as follows.

The pump function block has two variables for monitoring.

//Header

FUNCTION_BLOCK PUMP
VAR_INPUT
index : INT := 0;
END_VAR
VAR_OUTPUT
END_VAR
VAR
name : STRING := 'PT_';
pressure : REAL := 0.0;//we shall monitor pressure
temperature : REAL := 0.0; //we shall monitor temperature as well
InitDone : BOOL := FALSE;
sinValue : REAL := 0.0;
startTimer : BOOL := FALSE; //if true myTimer starts
myTimer : TON;
END_VAR

//Body

IF NOT InitDone THEN
name:= CONCAT(name,  INT_TO_STRING(index+1));
InitDone := TRUE;
END_IF
myTimer(IN:= startTimer, PT:=T#50MS);
IF myTimer.Q = TRUE THEN
myTimer(IN:= FALSE);
pressure := SIN(sinValue);
temperature := COS(sinValue+1);
sinValue:= sinValue+ 0.05;
IF sinValue >  6.2832 THEN
sinValue:= 0.0;
END_IF
END_IF
PROGRAM MAIN
VAR
myPump: PUMP;
END_VAR
//Calling myPump
myPump(index:= 60);

We can download the sample from the download section and test it. We can run the project in the local simulated PLC provided by Beckhoff (AMS NetID: 127.0.0.1.1.1) or we can use the PLC which is connected to our development PC (find the AMS Net ID of the PLC).

Actual Scope project (part of TwinCAT PLC project)

 

STEP 02:

Add a new project to the solution as shown in the following image This is an actual project in which one will draw the curve based on the values of our variables.

 

Figure 01: Adding new project (YT Measurement) to the existing PLC program in Visual Studio solution

STEP 03:

Select the YTScope project to the PLC project solution in Visual Studio as shown in the following image. The time (T) will be in the X-Axis, os it is called as YT scope project.

Figure 02: Select YT project and continue the wizards

After following the wizards, we get an empty YT Scope Project as shown in the following figure. Now we need to configure the YT Project

Figure 03:  YT  Scope project added in the solutions

STEP 04:

While the YT Scope Project is selected, press F4 and set the Server address (you can select local host if you are running it locally or select the AMS Net ID of the actual PLC, in our case we have 127.0.0.1.1.1 as we are running locally)

Figure 04:  Setting server  AMS Net ID

STEP 05:

While the DataPool is selected, press the right Mouse click and select the Target Browser. By this, we are telling from where we should get the data.

Figure 05:  Configuring Target Browser

STEP 06:

Please select the right PLC and its port.

Browse to the variables that we are planning to plot in the YT graphs.

Figure 06:  Configurattion of the Scope Server (Local or the remote server Net ID)

STEP 07:

Now we select the variables from the DataPool and drop these into the Axis Group as shown in the following figure.

Figure 07:  Configuring the variables from DataPool to YT Chart

STEP 08:

Now we need to run the plc application and start recording by pressing Start Recording (F5) and get the recording as a YT chart in the Visual Studio project. We can change different properties of the graph by selecting the YT Chart and its sub-component properties. Select YT Chart/Axis Group and then F4. We can select pressure, temperature, and its properties such as color, axis max value, min value, etc.

Figure 08:  Final view of the plots inside Visual Studio project

So far we have completed the project as part of the PLC solution, now we shall create another project as an HMI project where we can show the graph in the Browser window. The reason is that not many people in the field or the user group will not have the Visual Studio installed. So we want to export this for displaying in browsers such as Chrome, Edge, etc.

Actual HMI Project for displaying graphs to HMI in Browser

STEP 09:

Create another HMI project, we can create the same solution as the PLC solution project. But we shall create the project in a separate solution.

STEP 10:

Select References and mouse right click then Manage Nuget Package and install ScopeControl as shown in the following figure.

We select HMI ScopeControl, and TwinCAT HMI Official Nuget Package which matches to our SDK. If we install other versions then it may not work properly.

Figure 09:  Adding Scope Control references to our HMI project

STEP 11:

Now we should have references of HMI.ScopeControl and HMI.Scope to the reference list as shown in the following image.

Now we can drag and drop Scope Control to the Desktop view

Resize the control as our need.

Figure 10:  Scope Control references to our HMI project are added

STEP 12:

Now drag and drop the Scope Control from the toolbox to the Desktop view as shown in the following image

Figure 11:  Scope Control is available in tool box and ready for use

STEP 12:

Select the  control in the Desktop view and press F4 and see the Scope Config

Press on the Scope Config ellipse (…), Import Scope Config, give a scope name, press on Browse Files for YT Scope Project (from the PLC Scope project we developed in previous steps), and press on Open

Press on OK button

Now expand MyScope (I gave MyScope to my Scope name) and select YTChart (if you have changed the name select that one)

Now the OK button will be enabled and press on OK button

Now we should be able to see the Desktop live view or we can publish to the HMI Server so we can see the plots inside the browsers.

Figure 12:  Scope Control configuration and linking to the YT project

STEP 13:

Now we should be able to see the Desktop live view or we can publish to HMI Server so we can see the graphs inside browsers. This is shown in the following image.

Figure 13:  Scope Control in the Browser

We can start, stop, and examine the data at a given time. Most important we don’t need the Visual Studio for observing the data.

Download

You can download the sample from this link.

If you have any questions, related to this sample or any other questions, we are ready to help you, you can always post question to this Google group https://groups.google.com/g/hemelix

YouTube Video

Coming soon…

TIPs

Coming soon…

See also

References

 

 

Download the sample from the link given above.

See next our Linear Gauge example at https://www.hemelix.com/scada-hmi/twincat-hmi/hmi-localization/

Ask questions related to Hemelix sample code and design at Google group https://groups.google.com/g/hemelix