5.2 Reference Guide for REX.HMI
The main entry-point for all RexHMI visualization. This class exposes all methods necessary for reading and writing variables in control scheme over WebSockets.
Emits: event:time, event:online, event:offline
Name |
Type |
Description |
|
||
REX.HMI.kioskMode |
boolean |
Set true to enable kioskMode od the HMI |
REX.HMI.disableAutoReload |
boolean |
Set to true if autoreload of the web page should be disabled Autoreload is call when the REX executive or HMI changes. This can be useful if general signals are read to Graph and one do not want to loose history |
|
||
|
||
|
List of all available functions
- .init()
- .connect() =>Promise
- .disconnect()
- .getTarget(url) =>WSTarget
- .setTargetUrl(url, force) =>Promise
- .setRefreshRate(period)
- .addItem(opt) =>Item
- .addItems(items) =>Array.<Item>
- .removeItem(alias) =>Promise
- .get(alias) =>Item
- .$i(alias) =>Item
- .addGroup(g)
- .removeGroup(g)
- .addTrend(t)
- .removeTrend(t)
- .writeValues(aliases, values) =>Promise
- .setTitle(title)
- .setHeaderTitle(title)
- .showHeartBeatClock(show)
- .useClientTime(use)
- .getItemsEventSynchonizer(aliases, events) =>EventSync
This method can be override by the user. The init is called when the websocket connection is opened and one can add own items for RW operations. The method can be called either synchronously or asynchronously with callback. Example of the REX.HMI.init function is part of the HTML template
Example
2REX.HMI.init = function(){
3REX.HMI.addItem({alias:"SP", cstring:"task.block:param"});
4}
5
6// Init with callback
7REX.HMI.init = function(done){
8done();
9}
Connect the RexHMI to the target. This function is called automatically
Disconnect all items from the target. Stop reading and dispose connections to all targets.
REX.HMI.getTarget(url) =>WSTarget
Return REX target base on the given URL. If URL is null (the most common case) then it returns the default target.
Param |
Type |
Description |
|
||
url |
String |
URL of the requested target |
|
||
|
||
|
Example
2REX.HMI.getTarget().getVersion().then((data)=>{console.log(data)})
REX.HMI.setTargetUrl(url, force) =>Promise
Sets the new default target URL. When the page is served from server (not localhost) and the location.hostname is set the setTargetURL function sets NULL to use default targetURL. So the target connects to the location which the page is served from.
This behaviour can be changed by setting the force parameter tu true. Than the ‘url’ will be used on any occasion.
Param |
Description |
|
|
url |
URL of the target |
force |
set true if the URL should be set even run from server with hostname |
|
|
|
|
|
Example
2// If run locally from file:// connect to IP, when uploaded to server (RexCore)
3// then connect to location.hostname
4REX.HMI.setTargetUrl("ws://192.168.0.100:8008");
5
6// Always connect to the localhost
7REX.HMI.setTargetUrl("ws://127.0.0.1:8008", true);
8
9// Always use secure WebSocket
10REX.HMI.setTargetUrl("wss://192.168.0.100:8008", true);
REX.HMI.setRefreshRate(period)
Change the default refresh rate (how fast the data from RexCore will be read)
Param |
Type |
Default |
Description |
|
|||
period |
number |
500 |
New refresh period [ms] |
|
|||
|
|||
|
Example
Register new Item defined by alias and cstring for periodical reading and asynchronous writing.
Returns: Item - - Registered item
Param |
Type |
Description |
|
||
opt |
Object |
Main configuration object |
opt.alias |
string |
Alias for the connection string |
opt.cstring |
string |
Connection string of the signal from REX |
[opt.url] |
string |
URL of the target, if NULL the default is used |
[opt.period] |
number |
Item refresh period [ms] |
[opt.writeCString] |
string |
If defined the value of the item will be written to this cstring |
|
||
|
||
|
Example
2var sp = REX.HMI.addItem({alias:"SP", cstring:"task.block:param"});
3sp.on('change',(data)=>{console.log(data)});
4
5// Different location of reading and writing (eg. Write before saturation and read after)
6REX.HMI.addItem({alias:"SP", cstring:"task.SAT:y", writeCString:"task.CNR:ycn"});
REX.HMI.addItems(items) =>Array.<Item>
Add several Items at once. See HMI\#addItem for more details
Returns: Array.<Item> - - Return array of added items
Param |
Type |
Description |
|
||
items |
Array. <Object> |
An array of items |
|
||
|
||
|
REX.HMI.removeItem(alias) =>Promise
Remove an Item based on its alias
Param |
Description |
|
|
alias |
Items alias used during registration |
|
|
|
|
|
Param |
Description |
|
|
alias |
Items alias used during registration |
|
|
|
|
|
Param |
Description |
|
|
alias |
Items alias used during registration |
|
|
|
|
|
Register custom group of items for R/W operations
Param |
Type |
Description |
|
||
g |
REX.WS.Group |
Group for registering |
|
||
|
||
|
Example
2var g = new REX.WS.Group({id:"group1", period:100, url:""});
3
4// Add some items
5g.addItem(new REX.WS.Item({id:"ITEM-1", cstring:"task.block:param", url:""}));
6
7// Register events
8g.on('read',(data)=>{console.log(data)});
9
10// Register group
11REX.HMI.addGroup(g);
Param |
Type |
Description |
|
||
g |
REX.WS.Group |
Instance of group which will be unregistered |
|
||
|
||
|
Unlike REX.WS.Group the Trend reads data from TRND* blocks. These blocks store several signal with buffered data. Once registered the user can process the data from TRND* blocks.
Param |
Type |
Description |
|
||
t |
REX.WS.Trend |
Trend which will be registered |
|
||
|
||
|
Example
2var trend = REX.WS.Trend({cstring:"task.TRND", id:"TRND-1", period:500, readWholeBuffer:true});
3
4// Register
5REX.HMI.addTrend(trend);
6// Add event handlers
7trend.on('read',(data)=>{console.log(data)});
Param |
Type |
|
|
t |
REX.WS.Trend |
|
|
|
|
|
REX.HMI.writeValues(aliases, values) =>Promise
Write one or several values to the control system. Using already registered items (aliases).
Param |
Type |
Description |
|
||
aliases |
Array. <String> |
An array of already registered aliases |
values |
Array |
An array of values to be written |
|
||
|
||
|
Example
2REX.HMI.addItems([{alias:"A1",cstring:"task.A1:ycn"},{alias:"A2",cstring:"task.A2:ycn"}]);
3
4// Write values
5REX.HMI.writeValues(["A1","A2"],[0.5, 0.7]);
Change bot title in header and title of the webpage
Param |
Type |
Description |
|
||
title |
String |
New title for header and webpage |
|
||
|
||
|
Example
Param |
Type |
Description |
|
||
title |
String |
New title for the header |
|
||
|
||
|
REX.HMI.showHeartBeatClock(show)
If true, the template will display CLOCK in upper right corner of the main screen. When the update of the time stops, the default target is disconnected and the HMI is not updated
Param |
Type |
Description |
|
||
show |
Boolean |
True to show the clock |
|
||
|
||
|
Set to True if the time should be displayed in client time not target time. When the target is not able to synchronize with some time server is it possible to use and display times in a client time
Param |
Type |
Description |
|
||
use |
Boolean |
True to use client time instead of target one |
|
||
|
||
|
REX.HMI.getItemsEventSynchonizer(aliases, events) =>EventSync
Return an EventSync object which emits events when all registered items have emitted the same event.
Param |
Type |
Description |
|
||
aliases |
Array | String |
Array of item aliases or one alias as a string |
events |
Array | String |
Array of events which will be monitored |
|
||
|
||
|
Example
2REX.HMI.addItems([{alias:"A1",cstring:"task.A1:ycn"},{alias:"A2",cstring:"task.A2:ycn"}]);
3
4var sync = REX.HMI.getItemsEventSynchonizer(["A1","A2"],["read"]);
5
6sync.on("read",()=>{console.log("All read events emitted")});
[Previous] [Back to top] [Up]