CustomWebControl US
CustomWebControl US
Restrictions 8
Installing and using Custom
Web Controls 9
Updating Custom Web
Controls 10
Online documentation
02/2021
Online documentation
Legal information
Warning notice system
This manual contains notices you have to observe in order to ensure your personal safety, as well as to prevent damage
to property. The notices referring to your personal safety are highlighted in the manual by a safety alert symbol, notices
referring only to property damage have no safety alert symbol. These notices shown below are graded according to
the degree of danger.
DANGER
indicates that death or severe personal injury will result if proper precautions are not taken.
WARNING
indicates that death or severe personal injury may result if proper precautions are not taken.
CAUTION
indicates that minor personal injury can result if proper precautions are not taken.
NOTICE
indicates that property damage can result if proper precautions are not taken.
If more than one degree of danger is present, the warning notice representing the highest degree of danger will be
used. A notice warning of injury to persons with a safety alert symbol may also include a warning relating to property
damage.
Qualified Personnel
The product/system described in this documentation may be operated only by personnel qualified for the specific
task in accordance with the relevant documentation, in particular its warning notices and safety instructions.
Qualified personnel are those who, based on their training and experience, are capable of identifying risks and
avoiding potential hazards when working with these products/systems.
Proper use of Siemens products
Note the following:
WARNING
Siemens products may only be used for the applications described in the catalog and in the relevant technical
documentation. If products and components from other manufacturers are used, these must be recommended or
approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation and maintenance
are required to ensure that the products operate safely and without any problems. The permissible ambient
conditions must be complied with. The information in the relevant documentation must be observed.
Trademarks
All names identified by ® are registered trademarks of Siemens AG. The remaining trademarks in this publication may
be trademarks whose use by third parties for their own purposes could violate the rights of the owner.
Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and software described.
Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, the information in this
publication is reviewed regularly and any necessary corrections are included in subsequent editions.
Note
Observe the performance limit of Unified Comfort Panels. We do not recommend using, for
example, Custom Web Controls with 3D representations for Unified Comfort Panels.
• The component must not know in which environment it is deployed. The component must
be executable independent of the environment.
• All data exchange must take place through communication between client and server.
Application example
Based on an application example, you can learn more about the structure and development of
a Custom Web Control: SIOS entry (https://support.industry.siemens.com/cs/ww/en/view/
109779176).
"identity" sector
The "identity" sector contains identity information.
The following information of the data type "String" is required:
• "name": Defines the name of the Custom Web Control.
• "version": Defines the version of the Custom Web Control.
• "icon" (optional)
Includes the path for the logo that is displayed in the "Toolbox > My Controls" task card in the
TIA Portal.
The path can be specified as follows:
– URL starting with "http://" or "https://"
– Relative path to the storage location of the manifest starting with "./"
– Data URL that contains a Base64 encoded image starting with "data:"
The referenced image must be between 120x120 pixels and 320x320 pixels in size. The
following image formats are supported:
– JPG and JPEG
– PNG
– ICO
– TIFF
– BMP
Use a square image to avoid distortions.
If "icon" is not specified, only the display name ("displayname") is shown under "My Controls".
• "type": Each Custom Web Control can be referenced via the identity type and therefore
requires a pre-defined structure. Types must follow the 8-4-4-4-12 pattern of a 128-bit
integer (GUID).
Note
GUID generation
For example, a GUID can be created as follows:
• In Visual Studio under "Tools > Create GUID"
• Under https://www.guidgenerator.com/ (https://www.guidgenerator.com/)
• "start" (optional): The start directory must be specified to set the starting point of the Custom
Web Control for the browser.
If this value is not defined, "./control/index.html" is used.
Example: "identity"
"identity": {
"name": "GaugeMeter",
"version": "1.0",
"displayname": "GaugeMeter",
"icon": "./assets/logo.ico",
"type": "guid://551BF148-2F0D-4293-99C2-C9C3A1A6A073",
"start": "./control/index.html"
}
"environment" sector
The optional "environment" sector provides information on the environment that is integrated
into the Custom Web Control. If the sector does not exist, then no requirements and
dependencies exist.
Requirements are specified under the element "prerequesites". "renderingspace" can be used
below "prerequesites". Restrictions of the display of the Custom Web Control can be specified
under "renderingspace".
The following restrictions are permitted:
Example: "environment"
"environment": {
"prerequisites": {
"renderingspace": {
"defaultwidth": 450,
"defaultheight": 300,
"unit": "px"
}
}
"extensions": {
"HMI": {
"mandatory": true,
"version": "~1.0.0"
}
}
}
"metadata" sector
The following optional information can be stored, for example, as metadata:
• Author
• Keywords
• Description of the Custom Web Control
• Homepage
Metadata are not relevant for the execution of the Custom Web Control. User-defined metadata
can be supplemented.
Example: "metadata"
"metadata":{
"author": "Siemens",
"keywords": [
"Gauge",
"GaugeMeter"
]
"description": "Display tag value with a gauge."
"homepage": "https://www.siemens.com"
"company": "Siemens AG"
}
"contracts" sector
The "contracts" sector contains methods, events and properties as interface for use in the TIA
Portal.
The Custom Web Control has access to methods, events and properties and therefore receives
tag changes from the PLC, for example.
Data types can be used or referenced in this sector.
Note
A data type can be assigned with the keyword "type" below an element or it can be referenced
with "$ref". The two keywords cannot be used at the same time.
You can find additional information at Data types and references in the manifest (Page 17).
Note the following restrictions when naming methods, events, properties, arguments and
parameters:
• Only alphanumeric characters of the ASCII character set and "_" are permitted.
• The names must not start with a number.
• The entry is case-sensitive.
• Special characters are not permitted.
Methods
"methods" contain a list of methods used by the Custom Web Control.
Methods of a Custom Web Control can be used in Unified Scripting to transfer information from
the Unified server to the custom web control in the client. Methods are always executed
asynchronously.
For example, a method to flash the passed zone can be called as follows:
Screen.Items('GaugeMeter_1').BlinkZone(2)
Example: "methods"
"methods": {
"BlinkZone": {
"parameters": {
"zoneIndex": {
"type": "number"
}
},
"description": "Let the given zone blink."
}
}
Events
"events" contain a list of events used by the Custom Web Control.
Events are triggered by the Custom Web Control itself at any time. Events can be used in Unified
Scripting to transfer information from the client to the server. They can be found in the
engineering system under "Properties > Events".
An event can be assigned the following optional elements:
• "arguments": Contains arguments. Each argument specifies or references a data type.
• "description": Specifies the description of the event.
Example: "events"
"events": {
"ZoneChanged": {
"arguments": {
"zoneIndex": {
"type": "number"
}
},
"description": "Whenever the zone is changed, this event is raised and
gives you the new zone index."
}
}
Properties
"properties" contain a list of properties used by the Custom Web Control.
Properties can be found in the engineering system under "Properties > Properties > Interfaces".
The following elements can be assigned to a property:
• "type" or "$ref": A data type must be specified or referenced.
Note
Only individual elements can be connected
When using complex data types, such as an array or user data types, only the elements of the
bottom level can be linked to a property.
Example: "properties"
"properties": {
"GaugeValue": {
"type": "number",
"default": 20
"description": "This property represents the value of the gauge."
},
"MinValue": {
"type": "number",
"default": 0
"description": "This property represents the minimum value of the gauge."
},
"MaxValue": {
"type": "number",
"default": 50
"description": "This property represents the maximum value of the gauge."
},
}
"types" sector
The "types" sector contains local definitions for user-defined data types, objects and arrays.
A data type that is defined in this sector can only be referenced within this manifest. External
data types from a JSON Schema can be referenced under "contract" or "types".
Example: "types"
"types": {
"Color": {
"$id": "http://tia.siemens.com/wincc-unified/types/s/color",
"type": "number"
},
"AlignmentPart": {
"type": "object",
"properties": {
"Vertical": {
"$ref":"#/control/types/VerticalAlignment"
}
}
},
"VerticalAlignment": {
"type": "string",
"enum": [
"Top",
"Center",
"Bottom"
],
"default": "Center"
}
}
See also
Creating the ZIP file (Page 39)
Data types
Data types in the "contracts" sector of the manifest can be specified or referenced as follows:
• As basic data type
The following basic data types can be used without reference:
– Boolean
– Integer
– Number
– String
– Null
• As local reference to the "types" sector of the manifest
Arrays, objects or user-defined data types can be defined in the "types" sector.
• As external reference to a JSON Schema that is offered by Siemens, for example:
– "$id": "http://tia.siemens.com/wincc-unified/types/s/color"
– "$id": "http://tia.siemens.com/wincc-unified/types/c/font"
User-defined data types are, for example, structured data types or basic data types with
restrictions.
The following type restrictions are permitted in the manifest:
Note
Absolute URIs are preferred over fragments.
Note
Declaration
The name must match the name of the manifest file.
Note the following restrictions:
• Only alphanumeric characters of the ASCII character set and "_" are permitted.
• The names must not start with a number.
• The entry is case-sensitive.
• Special characters are not permitted.
{
//Methods
methods: {
BlinkZone: function(zoneIndex){
//code
}
},
//Events
events: ['ZoneChanged', 'Event2'],
//Properties
properties:{
GaugeValue: " ",
Property2: " "
}
}
Note
Download "webcc.min.js"
You can find the file "webcc.min.js" in the application example: SIOS entry (https://
support.industry.siemens.com/cs/ww/en/view/109779176)
<!doctype html>
<head>
<script>…</script>
<!-- Web Custom Control Facade -->
<script type= text/JavaScript src='webcc.min.js'>
</head>
See also
Extensions (Page 23)
"environment": {
"extensions": {
"HMI": {
"mandatory": true,
"version": "~1.0.0"
}
"Formatting": {
"mandatory": true,
"version": "~1.0.0"
}
"Dialogues": {
"mandatory": true,
"version": "~1.0.0"
}
}
}
See also
Dialog extension (Page 29)
Formatting extension (Page 28)
HMI extension (Page 24)
Example
WebCC.Extensions.HMI.Properties.WindowFlags = data.WindowFlags;
Example
5.2.3.1 Introduction
Prototypes are provided as extension of the installed JavaScript objects; they are used in the HMI
environment.
The prototypes are available in the global namespace.
Constructor Description
DatePrecise() Creates a "DatePrecise" object for the current date and
time.
DatePrecise(year, month[, day[, Creates a "DatePrecise" object. This constructor corre‐
hours[, minutes[, seconds[, sponds to the JavaScript "Date" constructor, but enables
milliseconds[, microseconds[, additional parameters for microseconds and nanosec‐
nanoseconds]]]]]]]) onds.
The parameters "year" and "month" are mandatory.
DatePrecise(DomHighResTimeStamp) Creates a "DatePrecise" object that accepts the "Dom‐
HighResTimeStamp" object of a browser with a millisec‐
ond value since January 1, 1970, and an accuracy in the
microsecond range.
DatePrecise([seconds, Creates a "DatePrecise" object that accepts the second
nanoseconds]) value since January 1, 1970, and an additional nanosec‐
ond offset.
DatePrecise(date) Creates a "DatePrecise" object from a passed JavaScript
"Date" object. The nanoseconds are "0".
DatePrecise(precise) Creates a "DatePrecise" object from a passed "DatePre‐
cise" object.
Method Description
getMicroseconds() Returns the number of microseconds (from 0 to 999).
getNanoseconds() Returns the number of nanoseconds (from 0 to 999).
getTime() Returns the number of milliseconds since January 1,
1970. This method corresponds to the method of the
JavaScript "Date" object.
getHrTime() Returns a precise date as an array with two numerical
values. The first value represents the seconds elapsed
since January 1, 1970. The second value is the offset in
nanoseconds.
setMicroseconds(microseconds) Sets the microseconds (from 0 to 999).
setNanoseconds(nanoseconds) Sets the nanoseconds (from 0 to 999).
setTime(DomHighResTimeStamp) Determines the date over a specific number of millisec‐
onds, starting from January 1, 1970.
This method corresponds to the method of the Java‐
Script "Date" object.
setHrTime([seconds, nanoseconds]) Specifies a precise date as array with two numerical val‐
ues. The first value represents the seconds elapsed since
January 1, 1970. The second value is the offset in nano‐
seconds.
toDate() Returns a "Date" object. The nanosecond accuracy is lost.
valueOf() Returns a "DomHighResTimeStamp" object. The nano‐
second accuracy is lost. The object is compatible with the
JavaScript "Date" object.
Examples
Note
The "n" parameter can take on the following data types:
• JavaScript data type "Number"
• "Big" data type
• "String" data type that contains a numerical value
Constructor Description
Big(n) Creates a number of the data type "Big" with the value "n".
Method Description
abs() Returns the absolute value of the "Big" number.
cmp(n) Compares two "Big" numbers. The following return values occur:
• If the "Big" number is greater than "n", 1 is returned.
• If the "Big" numbers are the same, 0 is returned.
• If the "Big" number is less than "n", -1 is returned.
div(n) Returns the value of the "Big" number divided by "n".
eq(n) Returns a Boolean value that indicates whether the "Big" number and "n" are
the same.
gt(n) Returns a Boolean value that indicates whether the "Big" number is greater
than "n".
gte(n) Returns a Boolean value that indicates whether the "Big" number is greater
than or equal to "n".
lt(n) Returns a Boolean value that indicates whether the "Big" number is less than
"n".
lte(n) Returns a Boolean value that indicates whether the "Big" number is less than
or equal to "n".
minus(n) Returns the value of the "Big" number minus "n".
mod(n) Returns the value of the "Big" number using modulo of value "n".
plus(n) Returns the value of the "Big" number plus "n".
pow(exp) Returns the value of the "Big" number to the power of "exp". The value for "exp"
must be an integer between -1e+6 and +1e+6.
round([dp [, rm]]) Returns the rounded value of the "Big" number to a maximum of "dp". The
value for "dp" must be an integer between -1e+6 and +1e+6. The default value
for the parameter "dp" is 20.
The "rm" parameter supports the following modes:
• 0: Rounded to zero.
• 1: Rounded to the nearest neighbor. If the distance is equal, the figures are
rounded up.
• 2: Rounded to the nearest neighbor. If the distance is the same, it is roun‐
ded to the straight neighbor.
• 3: Rounded up.
sqrt() Returns the square root of the "Big" number.
times(n) Returns the value of the "Big" number multiplied by "n".
toExponential([dp Returns a string that represents the value of the "Big" number type in expo‐
]) nential notation. The "dp" parameter defines the number of decimal places
displayed. The value for "dp" must be an integer between 0 and 1e+6. The
default value for the parameter "dp" is 20.
toFixed([dp]) Returns a string that represents the value of the "Big" number type in standard
notation. The "dp" parameter defines the number of decimal places displayed.
The value for "dp" must be an integer between 0 and 1e+6. The default value
for the parameter "dp" is 20.
Method Description
toPrecise(sd) Returns a string that represents the number of significant digits of the "Big"
number. The "sd" parameter defines the number of decimal places displayed.
The value for "sd" must be between 1 and 1e+6. The default value for the
parameter "sd" is 20.
If the "Big" number has more than the number of significant digits defined by
"sd", the return value is rounded to the number of significant digits defined by
'sd'. The rounding mode is 1.
toString() Returns a string that represents the value of the "Big" number. Under the
following conditions, the value is displayed in exponential notation:
• The positive exponent is greater than or equal to 21.
• The negative exponent is less than or equal to -7.
Constructor Description
Variant(value, type) Creates a "Variant" object using any value and data
type.
Methods Description
typeOf() Returns a numerical value that identifies the ele‐
mentary data type.
valueOf() Returns the value that was converted into the cor‐
responding data types "Number", "Boolean",
"String", "DataPrecise" or "Big".
"Time" and "DateTime" are returned as values of the
type "DatePrecise".
Numerical values that cannot be mapped without
loss of accuracy are returned as values of the type
"Big".
Examples
var variant = window.Variant(47111, 0x5);
var big = variant.valueOf();
Methods
Methods Description
format(value, pattern [, lcid]) Takes any number or random text and formats it
according to the parameters passed.
The language can optionally be specified via the
LCID. When the LCID is not transferred, the current
language is used.
Example
See also
Basics of extensions (Page 23)
"WebCC.Extensions.Dialogues" object
The "WebCC.Extensions.Dialogues" object allows for the creation and use of one or more dialogs.
Methods Description
create(id, view, data, [options]) Creates a "Dialog" object.
The "id" parameter is transferred as a string. The
"view" parameter is transferred as a string that con‐
tains a relative URL. The "data" parameter contains
random data this is transferred to the dialog. The
optional "options" parameter contains a JSON ob‐
ject with the following options:
• Information on the size of the dialog box: "min‐
width", "maxwidth", "minheight", "maxheight"
and "unit".
• A Boolean value "resizable" that defines wheth‐
er the size of the dialog box can be changed.
• A "caption" string that is displayed in the title of
the dialog.
list() Returns a string array that contains the IDs of cur‐
rently created and opened dialog boxes.
As soon as the dialog box is closed, the ID is no
longer displayed in the string array.
get(id) Returns a "Dialog" object with the transferred ID. If
the ID does not exist, ZERO is returned.
Property Description
self The "self" property contains the "Dialog" object.
"WebCC.Extensions.Dialog" prototype
The "WebCC.Extensions.Dialog" prototype enables the interaction with the dialog instance and
offers the following methods and events:
Methods Description
open(width, height) Creates a dialog and returns a "promise" property. If
the dialog is already open, only the "promise" prop‐
erty is returned.
The dialog is displayed in the current screen with
the specified width and height.
close([result]) Closes a dialog and fulfills the associated "promise"
property.
The "result" parameter is optional and can be of any
type. The "result" parameter normally contains the
data that were transferred when the dialog was
opened and were subsequently changed.
cancel([reason]) Closes a dialog. The "promise" property is rejected.
The "reason" parameter is optional and can be of
any type.
Property Description
id The "id" property contains the ID of the dialog. The
ID is available as a string.
promise The "promise" property contains information about
the status of a dialog.
data The "data" property contains the data that were
transferred when a dialog was created.
See also
Basics of extensions (Page 23)
function toColor(num) {
num >>>= 0;
var b = num & 0xFF,
g = (num & 0xFF00) >>> 8,
r = (num & 0xFF0000) >>> 16,
a = ((num & 0xFF000000) >>> 24) / 255;
return 'rgba(' + [r, g, b, a].join(',') + ')';
}
var defaultProperties = {
GaugeValue: 20,
GaugeBackColor: 4294967295,
Alignment:
{
Vertical: 'Center'
},
LineThickness: 20,
FontSize: 16,
MinValue: 0,
MaxValue: 50,
DivisionCount: 5,
Zones: [
{ Min: 0, Max: 30, StrokeColor: 4281381677 },
{ Min: 30, Max: 40, StrokeColor: 4294958336 },
{ Min: 40, Max: 50, StrokeColor: 4293934654 }
]
}
WebCC.start(
// callback function; occurs when the connection is done or failed.
// "result" is a boolean defining if the connection was successfull or
not.
function (result) {
if (result) {
console.log('connected successfully');
initializeGauge();
// Set current values
setProperty({ key: 'GaugeBackColor', value:
WebCC.Properties.GaugeBackColor });
setProperty({ key: 'Alignment', value: WebCC.Properties.Alignment });
setProperty({ key: 'LineThickness', value:
WebCC.Properties.LineThickness });
setProperty({ key: 'DivisionCount', value:
WebCC.Properties.DivisionCount });
setProperty({ key: 'FontSize', value: WebCC.Properties.FontSize });
setProperty({ key: 'Zones', value: WebCC.Properties.Zones });
setProperty({ key: 'MaxValue', value: WebCC.Properties.MaxValue });
setProperty({ key: 'MinValue', value: WebCC.Properties.MinValue });
setProperty({ key: 'GaugeValue', value:
WebCC.Properties.GaugeValue });
// Subscribe for value changes
WebCC.onPropertyChanged.subscribe(setProperty);
}
else {
console.log('connection failed');
}
},
// contract (see also manifest.json)
{
// Methods
methods: {
},
// Events
events: {
},
//Properties
//////////
properties: defaultProperties
},
// placeholder to include additional Unified dependencies (not used in
this example) [],
// connection timeout
10000
);
// Updates the alignment of the whole gauge inside the control. You can
place it at the top, middle or bottom.
// This function will be called by "setProperty" whenever the user changes
the alignment.
// - alignment: object that contains an enum property "Vertical" that can be
either "Top", "Center" or "Bottom".
function updateAlignment(alignment) {
const item = document.getElementById('gauge');
let vertVal = '0';
let topVal = '0';
switch (alignment.Vertical) {
case 'Top':
break;
case 'Center':
topVal = '50%';
vertVal = '-50%';
break;
case 'Bottom':
topVal = 'inherit';
break;
}
item.style.top = topVal;
item.style.transform = 'translate(0,' + vertVal + ')';
}
// Updates the labels of the gauge. All labels have to be updated whenever
the DivisionCount, MaxValue, MinValue or FontSize is changed.
// This function will be called by "setProperty" whenever one of those
contract properties change.
function updateLabels() {
const labels = new Array(.Properties.DivisionCount).fill(0).map(
(x, i) => (i + 1) * (WebCC.Properties.MaxValue -
WebCC.Properties.MinValue/WebCC.Properties.DivisionCount +
WebCC.Properties.MinValue
);
labels.unshift(WebCC.Properties.MinValue);
gauge.setOptions({
staticLabels: {
font: WebCC.Properties.FontSize + 'px "Siemens Sans"',
labels: labels
}
});
}
// Paints the given zones inside the gauge. This function will be called by
"setProperty" whenever a zone is changed or
// zones will be added or removed.
// - zones: array of new zones to be painted
function updateZones(zones) {
gauge.setOptions({
staticZones: zones.map(item => {
return { strokeStyle: toColor(item.StrokeColor), min: item.Min, max:
item.Max };
})
});
}
break;
case 'DivisionCount':
updateLabels();
break;
case 'Zones':
updateZones(data.value);
break;
}
}
// Let the given zone blink by descreasing and increasing the alpha value of
the zone color from 0% zu 100% and back to orininal value 2 times.
// - zoneIndex: integer as index of the zone that will blink.
function blinkZone(zoneIndex) {
const currentZone = gauge.options.staticZones[zoneIndex];
const rgba = currentZone.strokeStyle.split(',');
const originalRgba = Number(rgba[3].replace(')', ''));
let currentRgba = originalRgba;
let state = 0; // 0: falling, 1: raising, 2: falling again
let currentRound = 0;
const timerId = setInterval(() => {
switch (state) {
case 0:
currentRgba -= 0.2;
if (currentRgba <= 0) {
currentRgba = 0;
state = 1;
}
break;
case 1:
currentRgba += 0.2;
if (currentRgba >= 1) {
currentRgba = 1;
state = 2;
}
break;
case 2:
currentRgba -= 0.2;
if (currentRgba < originalRgba) {
currentRound++;
if (currentRound >= 2) {
clearInterval(timerId);
return;
} else {
currentRgba = originalRgba;
state = 0;
}
}
break;
} rgba[3] = currentRgba.toFixed(1);
currentZone.strokeStyle = rgba.join(',') + ')';
gauge.setOptions(gauge.options.staticZones);
}, 50);
}
Note
GUID generation
For example, a GUID can be created as follows:
• In Visual Studio under "Tools > Create GUID"
• Under https://www.guidgenerator.com/ (https://www.guidgenerator.com/)
Rounding error
The JavaScript data type "Number" is a 64-bit floating point data type. For integer values, a
secure display of up to 15 digits is possible before rounding errors occur.
Tags that use "DInt" or "Date", for example, can therefore lead to rounding errors when used in
Custom Web Controls.
To avoid rounding errors, use the prototypes "Big" and "DatePrecise".
Requirement
• A project has been created.
• An HMI device has been created.
• A screen has been created.
Procedure
If you want to update Custom Web Controls, proceed as follows:
1. In the TIA Portal, click on the "Update" button in the "Tools" > "My Controls" task card.
2. Custom Web Controls are updated.
A message appears in the Inspector window.