Getting started with REX and Monarco HATUser guide

Version 2.50.5
2017-09-06
Plzeň (Pilsen), Czech Republic

Chapter 1Introduction

The REX Control System is a family of software products for automation projects. You can use it in all ﬁelds of automation, robotics, measurements and feedback control.

The runtime core of the REX Control System turns your Raspberry Pi into a programmable device which will run your algorithms.

1.1 Features of the REX Control System

• Graphical programming without hand-coding
• Programming control units on a standard PC or laptop
• User interface for desktop, tablet and smartphone (HMI)
• Wide family of supported devices and input-output units (including Monarco HAT)
• Industry-proven control algorithms
• Easy integration into business IT infrastructure (ERP/BMS)
• REST API for seamless integration into Industry 4.0 and (I)IoT solutions

1.3 Programming in the REX Control System

The REX Control System oﬀers a graphical development environment for programming the algorithms. You can use standard desktop or laptop PC. You create the algorithms from the so-called function blocks. The library includes countless items (timers, comparators, ﬁlters, PID controllers and many more).

1.4 Main components of the REX Control System

1.4.1 RexDraw – the development environment

The RexDraw graphical environment is a developer’s tool which runs on a standard PC with Windows. You create the algorithms using the function block library (The IEC 61131-3 standard deﬁnes Function Block Diagram (FBD) as one of the PLC programming techniques.) of the REX Control System [1]. The library contains simple comparators and timers as well as advanced blocks for signal processing and feedback control (PID controllers etc.). You compile your project on your PC and run it on your Raspberry Pi.

Once running, you can watch your algorithm in real-time. Just select the signals and function blocks of your interest. You can also obtain detailed hierarchical information about the running algorithm and diagnose the runtime core and execution of your algorithm. You can connect via local network or over the Internet.

1.4.2 RexHMI Designer – the user interface

The RexHMI Designer is another developer’s tool intended for designing graphical user interface (or HMI, Human Machine Interface, if you prefer) for your algorithms. The user interface is included in the project and it is copied to your Raspberry Pi along with the algorithm.

1.4.3 RexComp – the compiler

The RexComp compiler converts your algorithms into binary code of the REX Control System. The compiler is almost invisible for the user, it is invoked from the RexDraw development environment. The compiler detects and reports possible errors in your algorithms.

1.4.4 RexCore – the runtime core

The RexCore runtime core runs on the target device (Raspberry Pi). It handles timing and execution of your algorithms and provides various services. The individual tasks are prioritized and executed using preemptive multitasking.

RexCore further contains an integrated webserver providing user interface (HMI) and REST API.

1.4.5 RexView – the diagnostic tool

With RexView you can diagnose the runtime core and execution of your algorithm. It is an alternative standalone tool for commissioning and diagnostics of control algorithms. All the diagnostic functions are included in RexDraw, therefore RexView can be considered obsolete. You can connect via local network or over the Internet.

Chapter 2Installation of the development tools

This chapter describes the steps to install and uninstall the development tools of the REX Control System on Windows 7/8/10 operating systems.

2.1 Windows 7/8/10

The installation package of the REX Control System development tools contains the RexDraw and RexHMI Designer development environments, the RexComp compiler and the RexView diagnostic tool. It also includes the RexCore runtime module for developing and testing purposes.

2.1.1 Installation procedure

2. Select the language and follow the installation wizard.
3. Select the target installation folder, the default is
C:\Program Files (x86)\REX Controls\REX X.XX.XX.XXXX.
4. Afterwards you can select the components to install. The requirements are quite low (approx 400 MB disk space) therefore the Full install option is recommended.
5. The following steps are standard and do not require further explanation.

There is no need to restart the system after installation.

2.1.2 Uninstall procedure

The common procedure can be used to uninstall the REX Control System – go to Control panel and choose Install/Uninstall programs.

Chapter 3Installing the runtime modules of the REX Control System on Raspberry Pi

It is necessary to have a correctly conﬁgured Internet connection on your Raspberry Pi running the so-called Raspbian distribution of GNU/Linux (RexCore should also work on any other distribution based on Debian (e.g. Ubuntu).) prior to using this guide. Visit http://www.raspberrypi.org for more information.

3.1 Installation of components on Raspberry Pi

1. On your Raspberry Pi, install GIT
sudo apt install git
2. Go to your home directory
cd
git clone https://github.com/rexcontrols/rex-install-rpi.git --branch v2.50
4. Change the working directory
cd rex-install-rpi
5. Depending on your hardware, run ONLY ONE of the following installation scripts
• For bare Raspberry Pi:
sudo bash install-rex.sh
• For Raspberry Pi with the Monarco HAT:
sudo bash install-rex-monarcohat.sh
• For Raspberry Pi with UniPi extension board:
sudo bash install-rex-unipi.sh
• For Raspberry Pi with PiFace Digital extension board:
sudo bash install-rex-pifacedigital.sh
6. Perform reboot if you are asked for it and you are done.

Right after the installation the RexCore runtime module is started automatically in the background as a daemon and it is possible to establish connection between the host PC and the Raspberry Pi using the RexDraw program. RexCore also automatically runs upon system (re)start.

3.2 Installed ﬁles and folders

Please refer to the RexCore user guide [2] for detailed information about the ﬁles and folders of the REX Control System runtime modules.

3.3 Uninstall procedure

Use the sudo apt-get remove rexcore command to remove RexCore from the operating system.

Chapter 4Conﬁguration, compilation and execution

The process of creating a control algorithm will be demonstrated on a very simple example with four Boolean variables representing manual switches. In Chapter 5, two of them will be replaced by physical inputs of the Monarco HAT. A software timer will be used for measuring the time when the variables are true (i.e. the switches are in the ON position). A Boolean signal will indicate that the interval of predeﬁned length has elapsed.

4.1 Creating a new project

The project conﬁguration is created using the RexDraw program. Each project consists of at least two .mdl ﬁles. The ﬁrst ﬁle is the main ﬁle of the project, which is used for conﬁguration of tasks, drivers, priorities and timing. The other ﬁle(s) contain the individual control algorithms (tasks).

First we’ll create the example 0101-01 from scratch (All examples which are part of the installation are marked by an ExampleID. The most up-to-date examples are available at https://github.com/rexcontrols/REXexamples/archive/v2.50.zip).

Standard approach:

1. Run the RexDraw program. Start with a plain project and select a folder to save the project ﬁles in (e.g. D:\GettingStarted).
2. The folder will contain two important ﬁles:
• myproject_exec.mdl
3. The myproject_exec.mdl is the project main ﬁle. It contains one EXEC block from the EXEC library. The other block is the TASK block from the same library and it is renamed to myproject_task to reference the second ﬁle of the project (myproject_task.mdl), which will contain the algorithm (the so-called task).

4. The task is connected to the Level0 output of the EXEC block and therefore its timing is deﬁned by tick and ntick0 parameters of the EXEC block.
5. The EXEC block (and any other block) can be conﬁgured by double-clicking on it. A block parameters and properties dialog appears. The parameters of all blocks of the REX Control System are described in the Help (press the F1 key) and in the Block reference manual [1].

6. Note that tick=0.05 and ntick0=2, therefore the task will run each 100 milliseconds ($0.05\cdot 2=0.1s$). There is no need to change any parameter at the moment. Close the dialog.
7. You can delete all the descriptive texts in project ﬁles. These have no eﬀect on the functionality and can be considered programmer’s comments.
8. Open Block Library, choose View/Block Library in the menu or use the icon from the toolbar.
9. The blocks are ordered in alphabetical order. Further the blocks are also organized in sublibraries and the location is always denoted as sublibrary/block, e.g. LOGIC/AND for the logical AND block in the LOGIC sublibrary.

10. Locate the following function blocks in the Block Library and drag them to the task ﬁle:
• MATH/CNB – constant of type Boolean. Once dropped, double-click its name and change it to CNB_SWITCH1. Double-click the block and set parameter $\mathtt{\text{YCN}}=\mathtt{\text{off}}$.
• LOGIC/OR_ – logical OR. Rename it to OR_A.
• LOGIC/AND_ – logical AND.
• LOGIC/TIMER_ – a timer block. Set parameter , $\mathtt{\text{pt}}=5.0$.
• INOUT/Display – a display to show values in real-time.
• ARC/TRND – real-time recording. Set parameters $\mathtt{\text{l}}=2000$, , leave the default values otherwise.
• MATH/CNB – constant of type Boolean, change name to CNB_RUN, set parameter $\mathtt{\text{YCN}}=\mathtt{\text{on}}$.

11. Duplicate the CNB_SWITCH1 block with right mouse button dragging. Or simply Copy&Paste the block.
12. Duplicate the block 2 more times.
13. Duplicate also the OR_A block. Rename the duplicate to OR_B.

14. Connect the blocks as shown below. To connect the blocks, drag the output arrow of one block to the input arrow of the other block using the left mouse button. The connection will be established when the line goes bold and green. After releasing the mouse button you can recognize a successfully connected line by its style. A full line terminated by a full arrow at the input of the connected block indicates a valid connection. New branch of an existing line can be created by dragging an existing line with the right mouse button.

At this moment the executive conﬁguration myproject_exec.mdl and the corresponding myproject_task.mdl ﬁle with the algorithm are ready. The algorithm will be evaluated in the direction of the arrows, starting from the source CNB blocks, passing through the OR_, AND_ and TIMER_ blocks and ﬁnishing at the Display and TRND blocks.

4.2 Compiling and running a project

The developed algorithm must be compiled to binary form prior to deploying. Pick Project/Compile from the menu or use the icon from the toolbar. The compiler output is displayed in the Compiler window. If no error is found, the myproject_exec.rex ﬁle is created.

At this moment it is possible to deploy the control algorithm to the target platform. Use Project/Compile and Download in the menu or click the Compile and Download icon  for this purpose. A dialog for deﬁning the target device appears upon successful compilation.

If there is no licence on your Raspberry Pi, you need to get one ﬁrst. You can get a DEMO licence for free. See Appendix B for details and come back afterwards.

As soon as the download is complete it is possible to switch the RexDraw application to the so-called Watch mode and watch the control algorithm in real-time – click Watch.

In the Watch mode, the background of all ﬁles goes gray and you cannot move or delete any blocks or connections. Right-click the TIMER_ block and select Watch selection in the menu to watch the inputs and outputs of the timer.

You can do the same with the OR_ and AND_ blocks (or any other selection).

Now it is possible to double-click the CNB_SWITCH1 block and change the Boolean variable to $\mathtt{\text{YCN}}=\mathtt{\text{on}}$ (tick the checkbox and click OK). Once you do the same with the CNB_SWITCH3 block, the outputs of both OR blocks are on and the Y output of the AND_ block goes on and the TIMER_ starts to count down. Observe the rt output. (Do not get confused by the default 1 second refresh rate of the Watch mode. The algorithm on the target device runs each 100 milliseconds as mentioned earlier.) Once the timer reaches zero, its output Q is set to on and it remains on as long as the U input is on.

You can double-click the TRND block to see the signals in a real-time graph. The red line is the output of the OR_A block, the magenta line is the output of the OR_B block, the green line is the remaining time of the timer and the blue line is the Boolean output of the timer.

Try turning the CNB blocks off and change the pt parameter of the TIMER_ block. Afterwards turn the CNB blocks on again and observe the signals in the TRND block again. As you can see, you can modify any parameter in real-time, which allows you to ﬁne tune your algorithm.

It is also possible to open a Diagnostics view of the algorithm. Pick Target/Diagnostics from the menu or click the  icon and you will see the algorithm in a tree view which allows you to monitor the control algorithm in full detail. You can verify that the sampling rate of your algorithm is indeed 100 milliseconds. You can also adjust parameters of individual function blocks, which has the same eﬀect as modifying them directly in the Block properties dialog.

Note: There is also a standalone diagnostics program called RexView. Click the RexView icon  and conﬁrm the IP address of the target platform.

Now you can switch RexDraw back to the Development mode. You can do so by deactivating the Watch mode (use the icon). You are oﬀered synchronization of the changed parameters with the source ﬁles of the project, choose No at this moment.

All changes made while in the Watch mode are not permanently stored in the target device (unless you decide so, see [3]). Upon restarting the RexCore runtime module the algorithm will start with the parameters deﬁned in the project source ﬁles, which were valid when compiling and downloading the algorithm to the target device. To apply the changes permanently, you have to transfer the changes to the source ﬁles and Compile and download the project one more time which deﬁnes new startup values.

4.3 Adding a user interface (HMI)

The next step in developing a control algorithm is its user interface, or HMI, Human-Machine-Interface. It allows anyone (even those who are not familiar with the REX Control System) to interact with the algorithm. The HMI of the REX Control System relies on modern web-based technology and the HMI is therefore accessible via web browser on desktop PC, tablet or smartphone.

In this tutorial, a simple HMI will be created using the so-called WebBuDi technology. It provides very simple indicators and input elements to interact with the control algorithm via a web page (Web Buttons and Displays).

The steps to create the HMI are described below. This is how the HMI will look like in the end:

1. In the folder with the project ﬁles, create a hmisrc subfolder. Inside this folder, create a ﬁle named index.hmi.js and edit it with your favorite text editor. The content should be the following:
REX.HMI.init = function(){

//Indicators and virtual switches - group A
var switchesA = {
column: 1,
title: 'Switches - group A',
rows: [
{type: 'DW', alias: 'switch1', desc: 'Switch 1',
{type: 'DW', alias: 'switch2', desc: 'Switch 2',
{type: 'DR', alias: 'S1orS2', desc: 'S1 OR S2',
]
};

//Indicators and virtual switches - group A
var switchesB = {
column: 1,
title: 'Switches - group B',
rows: [
{type: 'DW', alias: 'switch3', desc: 'Switch 3',
{type: 'DW', alias: 'switch4', desc: 'Switch 4',
{type: 'DR', alias: 'S3orS4', desc: 'S3 OR S4',
]
};

//Timer input
var timerInput = {
column: 2,
title: 'Timer input',
rows: [
{type: 'DR', alias: 'inputA', desc: 'Group A',
{type: 'DR', alias: 'inputB', desc: 'Group B',
{type: 'DR', alias: 'AandB', desc: 'A AND B',
]
};

//Timer settings and status
var timer = {
column: 2,
title: 'Timer',
rows: [
{type: 'AW', alias: 'interval', desc: 'Timer interval',
{type: 'AR', alias: 'rt', desc: 'Remaining time',
{type: 'DR', alias: 'timerQ', desc: 'Timer output',
]
};

REX.HMI.Graph.setMaxBufferSize(200);

// Change title of the page
REX.HMI.setTitle('My timer - HMI example');
}

2. This ﬁle will be processed when compiling the project. However, it is necessary to add the EXEC/HMI block into the project main ﬁle ﬁrst.

3. Double-click the HMI block to edit its parameters. Set $\mathtt{\text{GenerateWebWatch}}=\mathtt{\text{off}}$ and conﬁrm. WebWatch is another type of HMI, which you do not need at the moment. See [4] for details, it is a very interesting tool for developers and technicians.

4. The HMI is now an integral part of your project. Compile the project again and you will see that the compile log contains more information. The index.html ﬁle is generated from the source index.hmi.js ﬁle. All the HMI ﬁles are generated into the hmi subfolder (HTML, JS and CSS ﬁles) and included in the resulting binary myproject_exec.rex ﬁle.

5. After you download the project to the target device, you can access the HMI via web browser. Go to menu Target/Web Interface which will open the webpage. Remember the default login credentials: admin with no password.

6. You can toggle the switches and observe the results. The virtual switches are linked to the individual CNB function blocks therefore the eﬀect is the same as toggling the values directly in RexDraw.
7. You can also change the timer setting and shorten or lengthen the interval.
8. See [4] for detailed information about WebBuDi elements and possible customization (colors, backgrounds etc.).
9. The default URL address is http://192.168.1.100:8008/hmi/index.html.
10. The default port of the webserver (8008) can be changed in RexCore settings. See [2] for details.

Please note that there is also a program called RexHMI Designer, which allows you to create graphical user interfaces. Appendix A of this guide shows the steps to create a basic graphical interface. A more complex HMI is shown below solely for inspiration purposes.

4.4 Ready for interaction with the outer world

Well done! You have created the example 0101-01 from scratch (All examples which are part of the installation are marked by an ExampleID. The most up-to-date examples are available at https://github.com/rexcontrols/REXexamples/archive/v2.50.zip). You have learned the basic workﬂow for developing and running your algorithms using the REX Control System, which is the same for all platforms. Now it’s time to add the so-called input-output drivers so that the algorithm can interact with sensors, actuators and external data.

Chapter 5I/O conﬁguration for the Monarco HAT

The previous chapter illustrated the process of creating a control algorithm in the REX Control System and deploying it to the target device. But so far, the algorithm does not interact with the outer world, it is not connected to any physical signal (or external data).

We will use the input and output signals of the Monarco HAT for interaction with the real world.

As mentioned in Chapter 4, two physical switches will be connected as inputs and a software timer will control one output signal. In other words, this chapter is devoted to advancing from the generic example 0101-01 to example 0121-01 for the Monarco HAT.

5.1 Physical connections

Connect the switches as shown below. The motor is optional, the onboard LED will indicate the status of the output.

5.2 Adding inputs and outputs to the project

Now when we have everything wired up, it’s time to include the physical signals into the algorithm. You need to expand your project main ﬁle with 2 additional function blocks to access the inputs and outputs from the control algorithm in your project. Insert the EXEC/MODULE and EXEC/IODRV blocks from the Block library and attach them to the EXEC block as shown below.

In the task ﬁle, delete the CNB_SWITCH1 and CNB_SWITCH3 blocks and replace them with INOUT/From blocks. These will be the input signals. Also add one INOUT/Goto block, which will serve as an output and which will be controlled by the timer. You already know that a new branch of a line is created by right-button dragging, don’t you?

5.3 Working with I/O signals

5.3.1 Modiﬁcations in the project main ﬁle

Now we tell the compiler to use the Monarco HAT I/O driver. This is what needs to be done:

• Rename the MODULE block to MonarcoDrv – CASE SENSITIVE!

Next edit the IODRV block parameters. Link the IODRV block with the MonarcoDrv module by setting

• $\mathtt{\text{module}}=\mathtt{\text{MonarcoDrv}}$ – CASE SENSITIVE!

Continue editing the IODRV block parameters. For Monarco HAT set the following:

• $\mathtt{\text{classname}}=\mathtt{\text{MonarcoHatDrv}}$ – CASE SENSITIVE!
• $\mathtt{\text{cfgname}}=\mathtt{\text{monarcohat.rio}}$
• $\mathtt{\text{factor}}=\mathtt{\text{1}}$
• Leave the other parameters intact.

Remember to click the Conﬁgure button. This will create a default I/O driver conﬁguration ﬁle (.rio). Keep the default values and close the dialog.

As the ﬁnal step, rename the IODRV block to MNR, which will serve as a preﬁx for all I/O signals of this driver.

The executive of the REX Control System is conﬁgured, your project should look like this:

In the task double-click the input ﬂag and set $\mathtt{\text{GotoTag}}=\mathtt{\text{MNR__DI1}}$.Note the MNR preﬁx and two underscore characters. The ﬁrst physical switch will be connected to DI1.

The second physical switch will be connected to DI2 (MNR__DI2).

The timer output will be routed to DO1 which will serve as the output signal (MNR__DO1).

Similarly for other inputs and outputs we could use the following ﬂags:

• Goto, MNR__DO4 – digital output 4
• From, MNR__DI3 – digital input 3

A detailed description of the I/O driver for Monarco HAT is available in a separate manual [5].

The pinout of the Monarco HAT is shown in the following picture:

Your project should now look like this:

After compiling the project and downloading it to the Raspberry Pi the control algorithm interacts with the physical world. Again it is possible to switch to Watch mode and observe the signals in real-time or analyze the trends of signals. Flip the physical switches and watch the signals.

5.4 Updating the HMI

It is also necessary to update the HMI. The CNB_SWITCH1 and CNB_SWITCH3 blocks are no longer present in the algorithm. Moreover, we need to replace virtual input elements (DW) with indicators (DR). Therefore open the index.hmi.js ﬁle and replace

{type: 'DW', alias: 'switch1', desc: 'Switch 1',

with

{type: 'DR', alias: 'switch1', desc: 'Switch 1',

Similarly for switch no. 3, replace

{type: 'DW', alias: 'switch3', desc: 'Switch 3',

with

{type: 'DR', alias: 'switch3', desc: 'Switch 3',

Save the ﬁle, compile and download the project again and open the web interface. Push the two physical switches and wait until the timer triggers the output. Alternatively, you can still use the virtual switches. This demonstrates that you can combine physical and virtual input elements.

5.5.1 Detailed description of the driver

A detailed description of the IO driver for Monarco HAT is available in a separate manual [5].

5.5.2 Examples

Example projects and a set of all supported I/O ﬂags are included in the installation package of the REX Control System development tools. In RexDraw, go to menu File $\to$ Start from an Example Project and select one of the Monarco HAT examples. As mentioned earlier, the most up-to-date examples are available at
https://github.com/rexcontrols/REXexamples/archive/v2.50.zip

Chapter 6Summary

Congratulations, you have created the example 0121-01 from scratch! You have learned how to develop, compile and run your algorithms on the Raspberry Pi. The interaction with sensors and actuators is provided via input-output driver of the REX Control System, which you have learned to conﬁgure and use.

You have achieved quite a lot in a relatively short time, haven’t you? The purpose of this guide was to quickly show you the basic steps and tools for developing a project.

Now it’s time to focus on your own project and keep learning on the go. There are function blocks which are much more powerful than the ones mentioned in this guide, there are many inspiring example projects, there are additional I/O drivers which you can use to expand the scope of your project, there are many ways to exchange data with external systems and devices, etc.

Remember that whenever you have some achievement to share, we will be happy to hear from you. And whenever you encounter any diﬃculties, we will be happy to help. You can reach us at support@rexcontrols.com.

Appendix AGraphical HMI with RexHMI Designer

Chapter 4 describes the creation of a simple WebBuDi user interface. The REX development tools also contain the RexHMI Designer program which is a tool for designing custom graphical visualizations from predeﬁned components (Deﬁnition of custom components is also possible but it requires a bit of Javascript coding.). The RexHMI Designer is based on the well-known open-source vector editor InkscapeTM https://inkscape.org/en/.

In this chapter we’ll develop an alternative HMI for the example 0101-01. Just like in the case of the WebBuDi user interface, the SVG ﬁle created with RexHMI Designer will serve as a source ﬁle which will become a part of your REX project. During compilation of the project the SVG ﬁle will be processed and converted to HTML, JS and CSS ﬁles.

A.1 Initializing the HMI design

After launching the RexHMI Designer from Start Menu you will ﬁnd a clean page. The ﬁrst thing to do is to initialize the new visualization. The HMI is conﬁgured via the RexHMI extensions. Navigate to Extensions $\to$ RexHMI $\to$ Edit HMI Conﬁg in the menu.

This extension adds a special component which contains general settings of the HMI. Close it with the OK button for now.

In order to include the HMI during the REX project compilation, the ﬁle name has to end with .hmi.svg. Save the ﬁle as e.g. designer.hmi.svg to the hmisrc subfolder of your project. Use the standard File $\to$ Save as menu.

Note: If you want to replace the WebBuDi interface with the RexHMI Designer interface just delete the index.hmi.js and save the HMI as index.hmi.svg.

A.2 Adding the ﬁrst HMI components

Now we will add some displays and inputs. The RexHMI Designer contains a library of components which you can use to build your HMI. The library is available through Browse Components Library extensions. Navigate to Extensions $\to$ RexHMI $\to$ Browse Components Library (Ctrl+L). It will open the explorer window with several folders. Open the GENERAL folder and drag&drop the Display to the drawing. The display will be used as an indicator of the remaining time in the TIMER function block.

For conﬁguration of the display settings select the display by mouse click on top of it and use the Edit Component extension from Extensions $\to$ RexHMI $\to$ Edit Component (Ctrl+E). When the conﬁguration dialog is opened you can change the Title to Display_remaining. The Edit Component dialog has two tabs: Data points and Options.

The Data points tab contains three items deﬁning the behavior and animations of the component. Each data point contains an alias, which is in fact a connection to live data from the REX algorithm.

• value – The value to display.
• disable_by – If true the display is disabled and data are no longer updated.
• hide_by – If true the display is hidden.

The value property contains $T_value. The$T will be later automatically substituted by the Title of the component, resulting in the Display_remaining_value alias. The disable_by and hide_by data points are optional. Leave them blank at the moment.

The Options tab contains several properties which are speciﬁc for the Display component. You can ﬁnd the description of each component and property in [4]. Leave the default values for now and press OK.
Note: Each component is in fact one SVG group with unique content. You can copy the components all over the screen using copy (Ctrl+C) and paste (Ctrl+V) approach.

Now we will add controls for all the switches (CNB blocks). All of them will be controlled using the PushOnOﬀ components. Add them from the library. Select the ﬁrst PushOnOﬀ and open the editor dialog Extensions $\to$ RexHMI $\to$ Edit Component (Ctrl+E). Change the title to PushOnOﬀ_SW_1 and select the Options tab. Select the ToggleButton item in the type property list. Close the Edit Component dialog using OK button. Copy-paste the button three times and remember to change the titles to PushOnOﬀ_SW_2, PushOnOﬀ_SW_3, PushOnOﬀ_SW_4).

Note: Throughout the RexHMI Designer you can use double click in Options tab to open the corresponding conﬁguration dialog (color picker, number input, etc.).

Now we have four PushOnOﬀ buttons and one Display and we want to link all components with live data from the target device.

A.3 Linking HMI components with the running algorithm

Open the HMI Conﬁguration dialog either using Extensions $\to$ RexHMI $\to$ Edit HMI Conﬁg or just unselect all components in the drawing (click outside any component) and press Ctrl+E. The conﬁgurator parses all components and creates a list of used Aliases. Each of them should be linked with one signal in the running algorithm. You can either ﬁll in each connection string manually or you can use the Browse function.

The Browser requires a target device with running algorithm. Make sure the algorithm is running, see Section 4.2. Also the target URL must be set. Switch to the Options tab and double click on the right side of the target_url property. Change it to 192.168.1.100:8008. Then set the refresh_rate property to 100 (default is 500 ms) for more frequent display updates.

Return back to Connections tab and press Browse button. The login dialog will be opened. Unless you changed the login credentials, use the default username admin with an empty password. After a successful login the connection tab is expanded with a tree-view of the running algorithm (you have already seen this tree-view in algorithm diagnostics).

Select Connection String ﬁeld of the Display_remaining_value item and afterwards browse the tree to the TIMER_ block and double-click the rt parameter. The connection string of the parameter is copied to the Display_remaining_value alias, which is shown in the next ﬁgure.

Once the display is linked we will also link the switches. Just browse the tree to CNB_SWITCH1, select the Connection String ﬁeld of the PushOnOﬀ_SW_1 alias and double-click the YCN parameter. Repeat this for the remaining connection strings. Afterwards press OK to save the settings and close the dialog.

The interactive components in RexHMI Designer are just parts of the drawing. The user can position the components arbitrarily and add as many decorative static components to as needed. We will add some text descriptions to distinguish individual buttons. Use the Text tool (F8), click anywhere in an empty space and start typing. Pick the Select and Transform tool (F1) afterwards and move the texts and buttons.

Note: More information about custom drawing can be found in Inkscape tutorials (See the Help $\to$ Tutorials $\to$ Inkscape: Basic)

Next we will add more components to control the timer and show the status of the OR and AND blocks. Open the Elements library (Ctrl+L) and add one Input and four Led components. The LEDs will show the status of Boolean values and the Input will be used for changing the default timer interval value.

In the Led components just edit the Title via the Edit Component extension (select the component by single click and press Ctrl+E). The titles should be Led_OR_A, Led_OR_B, Led_AND, and Led_TIMER_OUT respectively. Finally edit the Input component by changing the Title to Input_interval.

The last component we need is a graph showing the time-plot of data from the TRND block. Use the components library (Ctrl+L) and add a TRND component. You can adjust its size to ﬁt the desired position. Edit the component (Ctrl+E) and change the Title to TRND and switch to the Options tab. Double-click the signals property. Add the following labels using the plus (+) button: timer out, rem. time, OR A, OR B. These labels will be shown in the legend of the graph.

When all the components are in place we link them to the running algorithm again. Just repeat the procedure described in Section A.3, open the HMI Conﬁguration dialog (Extensions $\to$ RexHMI $\to$ Edit HMI Conﬁg and browse the running algorithm to pair the remaining aliases with corresponding connection strings. The list is shown in the following image.

A.6 The ﬁnal steps

Congratulations, your ﬁrst graphical HMI is almost ready! Add a few rectangles which will visually divide the HMI into individual sections. Use the Squares and rectangles tool (F4), draw the rectangle, pick a color from the palette and send the rectangle to the background using the End key. Do not forget to save the drawing.

As mentioned earlier, the *.hmi.svg ﬁles in the hmisrc folder are automatically processed while the project is compiled in the RexDraw application. The project main ﬁle must contain the HMI block with GenerateRexHMI parameter enabled. This was already covered in Section 4.3 so you should have everything ready.

Once you compile the project again and download it to your Raspberry Pi, the HMI will be accessible via a web browser. Navigate to http://192.168.1.100:8008/hmi/designer.html. You will see your HMI with live data.

Appendix BLicensing of the REX Control System

The licensing model of the REX Control System is quite simple:

• The development tools are free to use, you can install it on as many computers as you want.
• The RexCore runtime module always needs a licence to run on your Raspberry Pi. There are DEMO licences available at no cost and there are permanent licences which you can purchase. Each Raspberry Pi needs an individual licence.

B.1 Obtaining a DEMO licence

The DEMO licence is intended for evaluating, testing and educational purposes. Feel free to experiment with the DEMO licence as long as you need. Commercial use of the DEMO licence is not allowed.

When you try to run your algorithm on a device which does not have a licence, you are oﬀered a chance to get a DEMO licence. Identify yourself and you’ll receive a DEMO licence via e-mail (the so-called SiteKey).

Once applied, you will see all the modules.

Evaluation version of the RexCore runtime core is functional for 2 hours. It is possible to run your algorithm on the Monarco HAT but you cannot store it permanently. The algorithm resides only in the memory. You can use almost all function blocks, see [1]. The RexCore runtime core on the target device is terminated after 2 hours of operation in demo mode without any warning. After a restart, you have another 2 hours for your experiments.

B.2 Obtaining a permanent licence

It is necessary to activate the RexCore runtime module and optional additional modules for permanent operation. This can be done using the licence, which you can obtain at

B.2.1 Activation of the permanent licence

Each device running the RexCore runtime module is identiﬁed by the so-called SiteID tag. The purchased licence must be associated with the hardware device, i.e. with the SiteID tag.

1. You can get the SiteID identiﬁer in RexDraw. Connect to the device and go to menu Target $\to$ Licensing.... A dialog pops up and you can copy the SiteID identiﬁer.

3. Use the SiteID identiﬁer to associate the licence with the hardware device.

4. You are asked to conﬁrm the association – this is the last and irreversible step.

5. The so-called SiteKey activation key is generated upon associating the licence.

6. This key will allow permanent operation of the runtime core, but it must be applied to the target device. To do that, open the licensing dialog in RexDraw again.
7. Delete any DEMO licence keys if present.
8. Afterwards apply the SiteKey using the Add button.

9. If the key is valid, the activated modules appear. The Monarco HAT must be restarted afterwards.

10. After reboot, check that the licence was applied correctly and that the RexCore runtime module no longer runs in demo mode.

Bibliography

[1]   REX Controls s.r.o.. Function blocks of the REX Control System – reference manual, 2017.

[2]   REX Controls s.r.o.. RexCore – User manual, 2017.

[3]   REX Controls s.r.o.. RexDraw – User manual, 2017.

[4]   REX Controls s.r.o.. RexHMI – User manual, 2017.

[5]   REX Controls s.r.o.. MonarcoDrv driver of the REX Control System – user guide, 2017.

Documentation reference number: 8614