The function does the query only of the last alert attributes of a data point.
Alert(s) time of type WinccoaAlertTime.
Data point element name(s) with the alert config.
Optional
alertCount: number | number[]Serial number of alert (optional).
Promise that resolves to the requested value(s) of the DPE(s). The received values must be cast to their expected types before they can be used.
NOTE
The function can accept a list of data points for a single alert time. In this case, the data point should be the same, but the alert configs are different:
winccoa.alertGet(alertTime, [dpe + ':_alert_hdl.._value', dpe + ':_alert_hdl.._text']);
.The function can accept a list of alert times and a list of data points. In this case all lists must have the same length:
winccoa.alertGet([alertTime1, alertTime2], ['dpe1', 'dpe2']);
WinccoaError when DPE does not exist or current user has no read access to it.
import { WinccoaManager, WinccoaAlertTime } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function alertGetTest() {
const dpe = 'ExampleDP_AlertHdl1.';
try {
await winccoa.dpSet(dpe, true); // trigger alert on the dpe
const result = await winccoa.dpQuery(
"SELECT ALERT '_alert_hdl.._value' FROM '" +
dpe +
"'",
);
for (let i = 1; i < result.length; i++) {
const alertTime = result[i][1];
const values = (await winccoa.alertGet(alertTime,
[dpe + ':_alert_hdl.._value', dpe + ':_alert_hdl.._text'])) as [boolean, WinccoaLangString];
console.info(dpe, values);
}
} catch (exc) {
console.error(exc);
}
}
import { WinccoaManager, WinccoaAlertTime } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function alertGetTest() {
const dpes = ['ExampleDP_AlertHdl1.', 'ExampleDP_AlertHdl2.'];
try {
await winccoa.dpSet(dpes, [true, true]); // trigger alert on the dpes
let alertTimes: WinccoaAlertTime[] = [];
for (let d = 0; d < dpes.length; d++)
{
const result = await winccoa.dpQuery(
"SELECT ALERT '_alert_hdl.._value' FROM '" +
dpes[d] +
"'",
);
if (result.length > 1)
alertTimes.push(result[1][1]);
}
if (dpes.length == alertTimes.length)
{
const values = await winccoa.alertGet(alertTimes, [dpes[0] + ':_alert_hdl.._value', dpes[1] + ':_alert_hdl.._value']);
console.info(dpes, values);
}
} catch (exc) {
console.error(exc);
}
}
The function returns the values of the specified alert attributes of the data point elements for which alerts were triggered.
The start time for reading alerts.
The end time for reading alerts.
Alert handling attribute names.
Promise that resolves to an object containing two arrays, one containing WinccoaAlertTimes with the alert details and the other the corresponding values.
WinccoaError when alert attribute name does not exist or in case of an invalid argument type.
const startTime = new Date('2024-10-25T12:00:00.789Z');
const currentTime = new Date();
const dpes = [':_alert_hdl.._value', ':_alert_hdl.._text']
const { alertTimes, values } = await winccoa.alertGetPeriod(
startTime,
currentTime,
dpes,
);
for (let i = 0; i < alertTimes.length; i++) {
const alertTime: WinccoaAlertTime = alertTimes[i];
console.info(
'#' + i,
'alertTime: ' + alertTime.date,
alertTime.count,
alertTime.dpe,
);
console.info('#' + i, 'value: ' + values[i]);
}
Allows to set data point alert attributes.
Alert(s) of type WinccoaAlertTime to be set.
Attribute value(s) to be set. Must have the same size as alerts. If alerts is a single string and not an array, this parameter must also be a single value and not an array.
Boolean true
in case of a success, otherwise WinccoaError wil be thrown instead.
The attributes and their constants which can be set with this method are described in the chapter _alert_hdl
WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.
import { WinccoaManager, WinccoaAlertTime } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function alertSetTest() {
const dpeWithAlert = 'ExampleDP_AlertHdl1.'; // assuming alert is triggered
const result = await winccoa.dpQuery(
"SELECT ALERT '_alert_hdl.._act_state', '_alert_hdl.._value' FROM '" +
dpeWithAlert +
"'",
);
const ts = result[result.length - 1][1] as WinccoaAlertTime;
const alertTime = new WinccoaAlertTime(ts.date, ts.count, ts.dpe + '._comment');
let isSuccess = false;
try {
isSuccess = winccoa.alertSet(alertTime, 'Alert comment text from winccoa node manager.');
} catch (exc) {
console.error(exc);
}
console.info("AlertSet is called successfully - " + isSuccess);
}
Allows to set data point alert attributes with a given timestamp.
Source time for the attribute change.
Alert(s) of type WinccoaAlertTime to be set.
Attribute value to be set. Must have the same size as alerts. If alerts is a single string and not an array, this parameter must also be a single value and not an array.
Boolean true
in case of a success, otherwise WinccoaError wil be thrown instead.
The attributes and their constants which can be set with this method are described in the chapter _alert_hdl
WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.
import { WinccoaManager, WinccoaAlertTime } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function alertSetTimedTest() {
const dpeWithAlert = 'ExampleDP_AlertHdl1.'; // assuming alert is triggered
const result = await winccoa.dpQuery(
"SELECT ALERT '_alert_hdl.._act_state', '_alert_hdl.._value' FROM '" +
dpeWithAlert +
"'",
);
const timeStamp = new Date('2024-03-19T04:05:06.789Z');
const ts = result[result.length - 1][1] as WinccoaAlertTime;
const alertTime = new WinccoaAlertTime(ts.date, ts.count, ts.dpe + '._ack_state');
let isSuccess = false;
try {
isSuccess = winccoa.alertSetTimed(timeStamp, alertTime, 1);
} catch (exc) {
console.error(exc);
}
console.info("AlertSet is called successfully - " + isSuccess);
}
Allows to set data point alert attributes with a given timestamp.
Source time for the attribute change.
Alert(s) of type WinccoaAlertTime to be set.
Attribute value to be set. Must have the same size as alerts. If alerts is a single string and not an array, this parameter must also be a single value and not an array.
Promise that resolves to true
if successful. If not successful,
a WinccoaError wil be thrown instead.
The attributes and their constants which can be set with this method are described in the chapter _alert_hdl
WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.
import { WinccoaManager, WinccoaAlertTime } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function alertSetTimedWaitTest() {
const dpeWithAlert = 'ExampleDP_AlertHdl1.'; // assuming alert is triggered
const result = await winccoa.dpQuery(
`SELECT ALERT '_alert_hdl.._act_state', '_alert_hdl.._value' FROM '${dpeWithAlert}'`,
);
const timeStamp = new Date('2024-03-19T04:05:06.789Z');
const ts = result[result.length - 1][1] as WinccoaAlertTime;
const alertTime = new WinccoaAlertTime(
ts.date,
ts.count,
ts.dpe + '._ack_state',
);
try {
await winccoa.alertSetTimedWait(timeStamp, alertTime, 1);
console.info(`Alert is acknowledged at ${timeStamp}`);
} catch (exc) {
console.error(exc);
}
}
Allows to set data point alert attributes.
Alert(s) of type WinccoaAlertTime to be set.
Attribute value(s) to be set. Must have the same size as alerts. If alerts is a single string and not an array, this parameter must also be a single value and not an array.
Promise that resolves to true
if successful. If not successful,
a WinccoaError wil be thrown instead.
The attributes and their constants which can be set with this method are described in the chapter _alert_hdl
WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.
import { WinccoaManager, WinccoaAlertTime } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function alertSetWaitTest() {
const dpeWithAlert = 'ExampleDP_AlertHdl1.'; // assuming alert is triggered
const result = await winccoa.dpQuery(
`SELECT ALERT '_alert_hdl.._act_state', '_alert_hdl.._value' FROM '${dpeWithAlert}'`,
);
const ts = result[result.length - 1][1] as WinccoaAlertTime;
const alertTime = new WinccoaAlertTime(
ts.date,
ts.count,
ts.dpe + '._comment',
);
try {
await winccoa.alertSetWait(
alertTime,
'Alert comment text from winccoa node manager.',
);
console.info(`Comment for alert of '${dpeWithAlert}' is successfully set`);
} catch (exc) {
console.error(exc);
}
}
Checks whether name is a valid display name for CNS.
Display name to check.
Promise - will be resolved to:
0
- valid name-1
- incomplete langString
-2
- contains invalid charactersimport { WinccoaLangString, WinccoaManager } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function test(name: WinccoaLangString) {
switch (await winccoa.cns_checkName(name)) {
case 0:
console.info('valid CNS display name');
break;
case -1:
console.error('incomplete langString');
break;
case -2:
console.error('contains invalid characters');
break;
}
}
Returns the display name of the given CNS node type.
Name of the CNS node type.
Promise - will be resolved to the display name of the node type in the current multi-language string format or empty string if node type does not exist.
Gets all CNS node type details.
Promise for an object containing arrays with details for all defined CNS node types. All arrays have the same size.
Returns the name of the data point linked to given CNS viewName.
CNS view name.
If true
(default), a linked data point is
created if it does not already exist. If false
, an empty string
is returned if no linked data point exists.
Name of the data point linked to dpName or empty string if not found.
Adds a new node to a tree or sub-tree.
The ID path of the parent node of the new node.
Note: You must specify a node and not a view.
ID of the new node
Display name of the new node as multi-language string
The optional data point (element) which is linked to the node. If no data point shall be linked an empty string can be defined (= default).
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
Registers a callback for notification of CNS changes.
Callback function that will be registered.
ID of the callback.
import {
WinccoaManager,
WinccoaCnsAction,
WinccoaCnsChangeType,
} from 'winccoa-manager';
const winccoa = new WinccoaManager();
function cnsCB(
path: string,
changeType: WinccoaCnsChangeType,
action: WinccoaCnsAction,
) {
console.log(path, changeType, action);
}
const cbId = winccoa.cnsAddObserver(cnsCb);
Create a tree or sub-tree.
The path of the parent element (view, tree or node)
Details of the tree to create
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
try {
let tree = new WinccoaCnsTreeNode('MyTree', 'MyTree', '', [
new WinccoaCnsTreeNode('B', 'B', '', [
new WinccoaCnsTreeNode('dp', 'ExampleDP_Rpt1', 'System1:ExampleDP_Rpt1.')
]),
new WinccoaCnsTreeNode('C', {'de_AT.utf8': 'deC', 'en_US.utf8': 'enC'})
]);
await winccoa.cnsAddTree('System1.View1', tree);
} catch(exc) {
console.error(exc);
}
Replaces a tree or sub-tree with a new tree.
The ID path of the tree (or node) that shall be replaced.
Details of the tree to create
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
try {
let tree = new WinccoaCnsTreeNode('MyTree2', 'MyTree2', '', [
new WinccoaCnsTreeNode('B', 'B', '', [
new WinccoaCnsTreeNode('dp', 'ExampleDP_Rpt1', 'System1:ExampleDP_Rpt1.')
]),
new WinccoaCnsTreeNode('C', {'de_AT.utf8': 'deC', 'en_US.utf8': 'enC'})
]);
await winccoa.cnsChangeTree('System1.View1:MyTree', tree);
} catch(exc) {
console.error(exc);
}
Creates a new view with the given display name.
The ID path of the new view
The display name of the new view as multi-language string
The optional separator for the new view as multi-language string
Note: The following characters are not allowed for separators: ' (single quotation mark), " (quotation marks), * (asterisk), ? (question mark). Moreover, numbers and letters which are already used in the view or node name must not be used.
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
Delete a tree, sub-tree or node.
The ID path of the element that shall be deleted.
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
Delete a view with all its trees.
ID path of the view
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
Returns the AccessRight for the given node. Note: the CNS property must be an uint.
ID path of the node
The cns property key which is used for getting the AccessRight
accessRight of type WinccoaCnsAccessRight
WinccoaError for invalid parameters (cnsPath does not exist).
Returns the paths of all children nodes for the given cnsPath.
ID path of the node.
Array of paths for all children nodes for cnsPath.
WinccoaError for invalid parameters (cnsPath or child for the given cnsPath does not exist).
Returns the display names for node with given cnsPath.
CNS path for the node.
Display names in the current multi-language string format.
WinccoaError for invalid parameters (cnsPath does not exist).
Returns the display path for node with given cnsPath.
CNS path for the node.
Display path in the current multi-language string format.
WinccoaError for invalid parameters (cnsPath does not exist).
Returns the data point element name (and optionally type) linked with given cnsPath.
CNS path of the data point element.
Optional
typeOutput: { If given, the property type
will be set to the (customizable) ID of the CNS node.
Data point element name or empty string.
WinccoaError when cnsPath does not exist.
Returns a list of data point element names linked to nodes matching given pattern and additional criteria.
Search pattern for the paths, can use wildcards **
, *
and ?
. See
cnsGetIdSet()
for details.
Path to the view to be searched (optional, default: search all views).
Search mode (optional, default: search all names, case insensitive).
Index of the language to search when searchMode includes display names (optional, default: search all languages).
Type of the nodes to search (optional, default: search all types).
Array of data point element names linked to the matching nodes.
WinccoaError for invalid parameters.
import { WinccoaManager, WinccoaCnsSearchMode } from 'winccoa-manager';
const winccoa = new WinccoaManager();
// using default parameters
let dpeNames = winccoa.cnsGetIdSet('**1');
console.log(dpeNames);
// using explicit parameters
dpeNames = winccoa.cnsGetIdSet(
'**Report*',
'System1.View1:',
WinccoaCnsSearchMode.DisplayName | WinccoaCnsSearchMode.CaseInsensitive,
0, // first project language
55, // custom node type
);
console.log(dpeNames);
Returns all CNS paths for nodes that are linked to a given data point (element).
Name of the data point (element).
Type of the nodes to search (optional, default: search all types).
Path to the view to be searched (optional, default: search all views).
Array of matching CNS paths.
WinccoaError for invalid parameters.
Returns a CNS paths matching given pattern and additional criteria.
Search pattern for the paths, can use wildcards **
, *
and ?
. See
cnsGetNodesByName()
for details.
Path to the view to be searched (optional, default: search all views).
Search mode (optional, default: search all names, case insensitive).
Index of the language to search when searchMode includes display names (optional, default: search all languages).
Type of the nodes to search (optional, default: search all types).
Array of matching CNS paths.
WinccoaError for invalid parameters.
import { WinccoaManager, WinccoaCnsSearchMode } from 'winccoa-manager';
const winccoa = new WinccoaManager();
// using default parameters
let paths = winccoa.cnsGetNodesByName('**1');
console.log(paths);
// using explicit parameters
paths = winccoa.cnsGetNodesByName(
'**Report*',
'System1.View1:',
WinccoaCnsSearchMode.DisplayName | WinccoaCnsSearchMode.CaseInsensitive,
0, // first project language
55, // custom node type
);
console.log(paths);
Returns the OPC AccessLevel for the given node.
ID path of the node
accessRight of type WinccoaCnsAccessRight
WinccoaError for invalid parameters (cnsPath does not exist).
Returns the path of the parent node for the given cnsPath.
ID path of the node
The ID path of the parent node for the given cnsPath.
WinccoaError for invalid parameters (cnsPath or parent for the given cnsPath does not exist).
Returns the value of the property with given key from node with given cnsPath.
CNS path of the node for which the property value should be returned.
Key of the property
Value of the property
WinccoaError for invalid parameters (cnsPath or key does not exist).
Returns a list of the property keys existing for node with given cnsPath.
CNS path of the node for which the property keys should be returned.
List of property keys (possibly empty).
WinccoaError for invalid parameters (cnsPath does not exist).
Returns the ID path of the root node of the tree which contains the given node.
The ID path of the node
ID path of the root node
WinccoaError for invalid parameters (cnsNodePath does not exist).
Returns the display names of the given system.
System name in the current multi-language string format.
display names of the system
WinccoaError for invalid parameters (systemName does not exist).
Returns the ID paths of all trees of the given view.
Name of the view
The ID paths of all trees of the given view
WinccoaError for invalid parameters (view does not exist).
Returns the user data stored in a node.
ID path of the node
the user data stored in the node
WinccoaError for invalid parameters (cnsPath does not exist).
Returns the display names for given viewPath.
ID path of the view.
Display names in the current multi-language string format.
WinccoaError for invalid parameters (viewPath does not exist).
Returns the paths of all views for the given systemName.
System name.
Array of paths for all found views for systemName.
WinccoaError for invalid parameters (systemName does not exist).
Returns the separators for given viewPath.
ID path of the view.
Separators in the current multi-language string format.
WinccoaError for invalid parameters (viewPath does not exist).
Unregisters a callback for notification of CNS changes.
ID of the callback to unregister as returned by cnsAddObserver.
Callback ID.
WinccoaError when id is not registered.
Sets or add the property for the given node as key/value pair. The following keys are already used by WinCC OA internally:
Note: A maximum of 256 byte (sum of length of key, value and internal control characters) can be stored per node.
ID path of the node
name
value
Type of value (see WinccoaCtrlType).
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
Stores user data in a node.
ID path of the node
User data which shall be stored in the node. The blob is truncated to 255 bytes if it is too long.
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
Returns a sub-string of cnsPath.
ID path.
Flag(s) that determine which part(s) of cnsPath should be included
in the sub-string. Can be combined with a binary OR (|
).
If true
, cnsPath is resolved and existing elements
will be used to determine the system name and separate the path from the tail.
If false
or no elements of cnsPath can be found, the specified parts will
be extracted by parsing the path string. Disabling path resolution is mainly
useful when you already know whether the path exists, so that you can avoid
the overhead of accessing CNS.
Sub-string of cnsPath.
Returns the data point name for the specified alias.
Data point alias to look up
Data point name for given alias.
WinccoaError when alias is not found or invalid argument type.
Returns the data type of a given data point attribute.
The data point attribute name.
Returns the data type as a WinccoaCtrlType.
WinccoaError when the data point attribute does not exist or in case of an invalid argument type.
Cancel dpQuerySplit request.
from dpQuerySplit request.
boolean true
Creates a connection for being notified of data point element updates.
Function that is called whenever a connected value changes.
DPE name(s) to connect to.
- Each update will contain updates for all elements in dpeNames, not only the changed values.
if true
, callback is called with the initial values right away, if false
,
callback is only called after an actual value change.
ID of the new connection (>= 0). This can be used to disconnect from updates if required with dpDisconnect. Otherwise the connection will be closed when the manager exits.
WinccoaError when invalid parameter types, unknown data point element names etc.
For an example describing how to pass user data to a callback, see the second example for WinccoaDpQueryConnectCallback.
import {
WinccoaManager,
WinccoaConnectUpdateType,
WinccoaError
} from 'winccoa-manager';
const winccoa = new WinccoaManager();
function connectCB(
names: string[],
values: unknown[],
type: WinccoaConnectUpdateType,
error?: WinccoaError
) {
if (error) {
console.log(error);
return;
}
if (type == WinccoaConnectUpdateType.Answer)
console.warn('--- Initial update ---');
for (let i = 0; i < names.length; i++)
console.info(`[${i}] '${names[i]}' : ${values[i]}`);
}
function connect() {
let id = -1;
try {
id = winccoa.dpConnect(
connectCB,
['ExampleDP_Arg1.', 'ExampleDP_Arg2.'],
true
);
} catch (exc) {
console.error(exc);
}
}
Copies a data point including its configuration.
Name of the data point to copy.
Name of the new copied data point. Must not exist yet.
Optional
driver: numberOptional driver number (default 1).
Promise - will be resolved to true
if successful or rejected with an error.
In case of an error, error.details
will contain the same error code
that CTRL function dpCopy() would return (see there).
WinccoaError when given source data point does not exist, when data point is copied into itself, invalid argument given, etc.
Creates a data point.
Name of the data point to be created.
Type of data point to be created.
Optional
systemId: numberTo create a data point on a remote system in a distributed system, this parameter must contain the system number.
Optional
dpId: numberThe ID of the data point. If a data point with the given ID already exists, a random ID is chosen.
Promise - will be resolved to true
if successful or rejected with an error.
WinccoaError in case of:
Deletes a data point.
Name of the data point to be deleted. In case of a distributed system the name of the data point to be deleted must contain the system name.
Promise - will be resolved to true
if successful or rejected with an error.
WinccoaError when data point with the given name does not exist or current user has no privileges to delete a DP.
let isSuccess = false;
try {
isSuccess = await winccoa.dpCreate('newDpe', 'ExampleDP_Float');
} catch (exc) {
console.error(exc);
}
if (isSuccess)
{
try {
isSuccess = await winccoa.dpDelete('newDpe');
} catch (exc) {
console.error(exc);
}
}
console.info("DP newDpe was deleted successfully - " + isSuccess);
Disconnect from data point element update connections established with dpConnect.
ID of the connection to close as returned by dpConnect.
ID of the connection that has been closed (>= 0).
WinccoaError when id is not found or invalid.
Returns the data typeof a data point element.
Name of the data point element
Type of a data point element
WinccoaError when data point with the given dpeName is not found or invalid argument type.
import { WinccoaManager, WinccoaElementType } from 'winccoa-manager';
const winccoa = new WinccoaManager();
function dpElementTypeTest() {
try {
let dpType = winccoa.dpElementType('ExampleDP_Arg1.');
console.info('The type of ExampleDP_Arg1 is float - ' + (dpType == WinccoaElementType.Float));
} catch (exc) {
console.error(exc);
}
}
Checks the existence of a valid data point identifier.
A data point identifier: a sys, a DPT, a DP, a DPE, a config, a detail or an attr.
true if at least one part of a data point identifier can be resolved correctly, otherwise false.
WinccoaError when invalid argument type is given.
Get the current values of one or more data point elements.
Data point element name(s) of the values to get.
Promise that resolves to the current value(s) of the DPE(s). The received values must be cast to their expected types before they can be used.
WinccoaError when DPE does not exist or current user has no read access to it.
Returns the alias for the specified data point.
Data point element
the appropriate alias in the language. Note that the alias can be only unilingual.
WinccoaError when data point with the given dpeName is not found or invalid argument type.
Returns data points and their aliases with the possibility to filter by data point element and/or alias.
Pattern string for filtering the aliases (for example,'Engine*'
, '*'
).
Pattern string for filtering data point elements (for example '*.para'
).
An empty dpe pattern (''
) and a '*'
are treated like ALL DPEs. Also queries on
remote systems can be executed. The system is part of the dpeFilter (for example,
'Sys23:*.**'
- returns all aliases of a specific system; '*:*.**'
would return
the aliases of all systems. you can use it e.g. in a distributed system). Several
systems can be defined with a list (for example, 'Sys{1,2,3,45}:Ex*'
).
Object containing two arrays with DPE names and their aliases that matching filter criteria. Both arrays have the same size.
Aliases corresponding to the DPEs in dpNames.
Data point elements.
Returns all attributes for the given config name.
Name of the config.
Array of attributes of a config.
WinccoaError in case of an invalid argument type.
Returns all possible configs, which are allowed to configure for the given data point element or data point type.
Name of the data point element or data point type. See WinccoaElementType.
Array of configs for dpNameOrType.
WinccoaError when data point or type with the given dpNameOrType is not found or invalid argument type.
Returns all data points and all descriptions that correspond to the given filters.
Optional
descriptionFilter: stringPattern string for filtering the descriptions (optional, default: *
).
Optional
dpeFilter: stringPattern string for filtering data point elements (optional, default: *.**
).
An empty pattern ("") and a *
are treated like *.**
.
Optional
mode: numberMode of functionality.
For more details on all modes description see
CTRL function dpGetAllDescriptions()
.
Object containing two arrays with data point names and their corresponding description.
Descriptions corresponding to the DPEs in dpNames
Data point names.
Returns all details of a given config name.
Name of the config.
Array of details of a config.
WinccoaError in case of an invalid argument type.
Returns the comment (description) for the data point.
Data point element or data point
Optional
mode: numberMode of functionality.
For more details on all modes description see
CTRL function dpGetDescription()
.
Description in all available languages as or empty strings in all languages.
The returned data type can be defined with setOptions.
WinccoaError when data point with the given dpeName is not found or invalid argument type.
This function returns the numerical format(s) of a data point.
Data point element
Returns a string that contains the format (for example, '%6.2f') in one or several languages or an empty string if an error occured.
The returned data type can be defined with setOptions.
WinccoaError when data point with the given dpeName is not found or invalid argument type.
Returns the data point ID and the element ID of the given data point.
Name of the data point.
Array of size 2 with the first value - data point ID and the second value - element ID.
WinccoaError in case of an invalid argument type or data point does not exist.
The function returns the value(s) of one or more data point elements from the driver. This function is available for the OPC UA Client, Modbus, S7Plus, SNMP, OPC drivers and S-Bus driver. The use of this function is only useful if an input or input/output peripheral address exists for a data point element. If a peripheral address exists, the function triggers a singleQuery for a driver if the value of the data point element dpName is older than the parameter age. The function returns the value from the driver. If a peripheral address does not exist, the function works as the function dpGet meaning that the function returns a value immediately irrespective of how old the value is.
The maximum age of the value in milliseconds. When value is older than age, then value from the driver is returned.
Data point element name(s) whose value is queried.
Promise that resolves to the current value(s) of the DPE(s). The received values must be cast to their expected types before they can be used.
WinccoaError when DPE does not exist or current user has no read access to it.
const dpes = ['EIPtestCompactIN.BOOL', 'EIPtestCompactIN.INT', 'EIPtestCompactIN.STRING'];
try {
// get value with the max age less than 5 seconds
const values = (await winccoa.dpGetMaxAge(5000, dpes)) as [boolean, number, string];
for (let i = 0; i < dpes.length; i++) {
console.info(`${dpes[i]}: ${values[i]}`);
}
} catch (exc) {
console.error(exc);
}
Returns the data point name for the given data point ID and element ID.
Data point ID.
Element ID.
Optional
systemId: numberSystem ID (optional). When not specified - own system.
The data point name.
WinccoaError in case of an invalid argument type or data point does not exist with the given ID.
Queries DP attributes over a specified period of time.
The start time of the interval from which values should be returned.
The end time of the interval from which values should be returned.
Single or multiple Data Points in an array.
Optional number of values before startTime and after endTime that will also be returned.
Promise will be resolved to data for the given DPEs if successful. It consists of an array of results (one for each DPE, in the order they are given in dpeList), each result contains two arrays, one for the values and one for the corresponding value change timestamps).
Promise will be rejected with WinccoaError in case of:
Queries DP attributes over a specified period of time. There are two calls, the first call described below and subsequent calls with requestId.
The start time of the interval from which values should be returned.
The end time of the interval from which values should be returned.
Single or multiple Data Points in an array.
Optional
count: numberOptional number of values before startTime and after endTime that also have to be read out.
Promise will be resolved to an object containing:
Promise will be rejected with WinccoaError in case of:
async function test() {
const dpe = 'System1:ExampleDP_Trend1.';
const startTime = new Date(2023);
const endTime = new Date(2025);
const showResult = function (data: { times: Date[]; values: unknown[] }[]) {
if (data.length > 0) {
const { times, values } = data[0];
for (let i = 0; i < data[0].times.length; i++) {
console.info(
`query line - timestamp = '${times[i]}' - value = ${values[i]}`,
);
}
}
};
let result = await winccoa.dpGetPeriodSplit(startTime, endTime, [dpe]);
showResult(result.data);
while (result.progress != 100) {
result = await winccoa.dpGetPeriodSplit(result.id);
showResult(result.data);
}
}
await test();
Queries DP attributes over a specified period of time.
ID, only, subsequent calls.
Promise as described in dpGetPeriodSplit above.
This function returns the unit(s) of a data point.
Data point element
Returns the unit in one or several languages. In the event of an error, an empty string is returned.
The returned data type can be defined with setOptions.
WinccoaError when data point with the given dpeName is not found or invalid argument type.
Returns all the data point names or the data point element names that match a pattern in alphabetical order.
Serach pattern. When an empty pattern is given (=default), then returns all data points.
Wildcards are used to filter data point name.
The charcters *
and ?
are used for the purpose,
where the asterisk (*
) replaces any number of characters and the question mark ?
stands for just one character.
Only data points that have the same number of levels as specified are found.
Levels are separated by a period. dpNames(**)
is equivalent to dpNames(*.*)
.
Furthermore:
:*
returns all configs, :config.*
returns all details, :config.detail.*
returns all attributesdp.el:*
returns only the configs according to the DPE. , for example, no _original
for a node.
Wildcards can be used in arrays (square brackets , e.g.: [0,3,5-7]
- numbers 0,3,5,6,7) or outside arrays in option lists (in curly brackets {}
).
Example of wildcards in lists of options:
winccoa.dpNames('{*.Ala.*,*.Ala*}', dpType);
winccoa.dpNames('*{.Ala.,.Ala}*', dpType);
winccoa.dpNames('*.A{la.,la}*', dpType);
winccoa.dpNames('*.Al{a.,a}*', dpType);
winccoa.dpNames('*.Ala{.,}*', dpType);
winccoa.dpNames('*.Ala{.}*', dpType);
winccoa.dpNames('*.Ala.*', dpType);
winccoa.dpNames('*.Ala*', dpType);
Data point type. Allows to restrict the returned data points to a specific data point type. When using the parameter only data points that match the pattern and the selected data point type will be returned.
Defines if the search should ignore the casing of the search pattern (=true) or not (=false, default)
List with data points or data point element names.
WinccoaError when invalid argument type is given.
Retrieves attribute values with the help of SQL statements.
SQL statement.
Promise - will be resolved to true
if successful or rejected with an error.
The query result has a table-like structure:
[0][0] (empty) | [0][1] column header | ... |
---|---|---|
[1][0] line name | [1][0] content of line | ... |
[2][0] line name | [2][1] content of line | ... |
... | ... | ... |
e.g. this is the output for the query "SELECT '_original.._value' FROM 'ExampleDP_Arg*'"
converted
to JSON:
[
["",":_original.._value"],
["System1:ExampleDP_Arg1.",2.43],
["System1:ExampleDP_Arg2.",5.76]
]
WinccoaError when invalid parameter or query string is given.
let result;
try {
result = await winccoa.dpQuery(
`SELECT '_original.._stime', '_original.._value' FROM 'ExampleDP_Arg*'`,
);
} catch (exc) {
console.error(exc);
result = null;
}
if (result) {
const queryTable: string[][] = result as string[][];
for (let i = 0; i < queryTable.length; i++) {
console.info(
`query line - name: '%s' - timestamp = %s - value = %s`,
...queryTable[i],
);
}
}
Calls callback whenever one or more DPEs which meet the query condition change.
It is recommended to use dpQueryConnectSingle if possible from the performance point of view.
Function that is called whenever a subscribed DPE value changes. The update message will contain all subscribed DPEs.
if true, callback is called with the initial DPE values right away, if false, callback is only called for an actual value change.
query as an SQL statement.
Time in milli-seconds when the call of the callback function is blocked by an
open query. In this time, query results are collected and then returned after
blockingTime in a single callback. If blockingTime is set to 0, the
callback function is called immediately when a value is updated. If not given,
the blocking time is read from the config entry queryHLBlockedTime
.
ID of the new connection (>= 0). This can be used to disconnect from updates if required with dpQueryDisconnect. Otherwise the connection will be closed when the manager exits.
WinccoaError when invalid parameter types, empty or invalid query, etc.
When the query passed to this method is invalid, no exception is thrown, but the first (and only) callback will contain a WinccoaError instead.
For an example describing how to pass user data to a callback, see the second example for WinccoaDpQueryConnectCallback.
import {
WinccoaManager,
WinccoaConnectUpdateType,
WinccoaError
} from 'winccoa-manager';
const winccoa = new WinccoaManager();
function queryConnectCB (
values: unknown[][],
type: WinccoaConnectUpdateType,
error?: WinccoaError
) {
if (error) {
console.log(error);
return;
}
if (type == WinccoaConnectUpdateType.Answer)
console.warn('--- Initial update ---');
for (let i = 0; i < values.length; i++) {
console.info(`DPE = '%s', value = %s`, ...values[i]);
}
}
function connect() {
let id = -1;
try {
id = winccoa.dpQueryConnectAll(
queryConnectCB,
true,
`SELECT '_online.._value' FROM '*' WHERE _DPT="ExampleDP_Float"`
);
} catch (exc) {
console.error(exc);
}
}
Calls callback whenever one or more DPEs which meet the query condition are changed.
Function that is called whenever a subscribed DPE value changes. The update message will contain only changed DPEs.
if true, callback is called with the initial DPE values right away, if false, callback is only called for an actual value change.
query as an SQL statement.
Time in milli-seconds when the call of the callback function is blocked by an
open query. In this time, query results are collected and then returned after
blockingTime in a single callback. If blockingTime is set to 0, the
callback function is called immediately when a value is updated. If not given,
the blocking time is read from the config entry queryHLBlockedTime
.
ID of the new connection (>= 0). This can be used to disconnect from updates if required with dpQueryDisconnect. Otherwise the connection will be closed when the manager exits.
WinccoaError when invalid parameter types, empty query, etc.
When the query passed to this method is invalid, no exception is thrown, but the first (and only) callback will contain a WinccoaError instead.
For an example describing how to pass user data to a callback, see the second example for WinccoaDpQueryConnectCallback.
import {
WinccoaManager,
WinccoaConnectUpdateType,
WinccoaError
} from 'winccoa-manager';
const winccoa = new WinccoaManager();
function queryConnectCB (
values: unknown[][],
type: WinccoaConnectUpdateType,
error?: WinccoaError
) {
if (error) {
console.log(error);
return;
}
if (type == WinccoaConnectUpdateType.Answer)
console.warn('--- Initial update ---');
for (let i = 0; i < values.length; i++) {
console.info(`DPE = '%s', value = %s`, ...values[i]);
}
}
function connect() {
let id = -1;
try {
id = winccoa.dpQueryConnectSingle(
queryConnectCB,
true,
`SELECT '_online.._value' FROM '*' WHERE _DPT="ExampleDP_Float"`
);
} catch (exc) {
console.error(exc);
}
}
Disconnect from dpQueryConnectSingle (or dpQueryConnectAll) .
ID of the connection to close as returned by dpQueryConnectAll or dpQueryConnectSingle.
ID of the closed connection (>= 0).
WinccoaError when id is not found or invalid.
import {
WinccoaManager,
WinccoaConnectUpdateType,
WinccoaError
} from 'winccoa-manager';
const winccoa = new WinccoaManager();
function connect() {
let id = -1;
try {
id = winccoa.dpQueryConnectSingle(
function (
values: unknown[][],
type: WinccoaConnectUpdateType,
error?: WinccoaError
) {
if (error) {
console.log(error);
return;
}
console.info(values)
},
true,
"SELECT '_online.._value' FROM '*' WHERE _DPT= \"ExampleDP_Float\""
);
} catch (exc) {
console.error(exc);
}
}
function disconnect() {
try {
winccoa.dpQueryDisconnect(id);
} catch (exc) {
console.error(exc);
}
}
Query attributes of a set of data points as an SQL-like query string. Use the function when you query a large amount of data. The function reduces the system load and offers a considerable advantage when dealing with a large amount of data. To cancel a dpQuerySplit use dpCancelSplitRequest. After WinccoaOptions.splitTimeout milliseconds, the id is invalid.
First call: SQL statement, subsequent calls: ID.
Promise will be resolved to an object containing:
Promise will be rejected with WinccoaError in case of:
async function test() {
// TIMERANGE: use historic data, otherwise no split occur
const query = `SELECT '_original.._stime', '_original.._value' FROM '_*' TIMERANGE("1970-01-01T00:00:00.000Z", "2060-01-01T00:00:00.000Z", 0, 0)`;
let result;
const showResult = function (queryTable: string[][]) {
for (let i = 0; i < queryTable.length; i++) {
console.info(
`query line - name: '%s' - timestamp = %s - value = %s`,
...queryTable[i],
);
}
};
result = await winccoa.dpQuerySplit(query);
showResult(result.data as string[][]);
while (result.progress != 100) {
result = await winccoa.dpQuerySplit(result.id);
showResult(result.data as string[][]);
}
}
await test();
Set the value of one or more data point element(s).
Data point element name(s) of the values to set.
Values to set. Must have the same size as dpeNames. If dpeNames is a single string and not an array, this parameter must also be a single value and not an array.
true
if successful, otherwise WinccoaError wil be thrown instead.
Since this method does not wait for the actual value update in the database, the update can still fail after this method returned
true
. Use dpSetWait to also get informed about these errors.
WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch etc.
Sets the alias for the specified data point element.
Data point element
Alias to be set. Note that the alias can be set only unilingual.
Promise - will be resolved to true if successful or rejected with an error.
WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.
This function sets the data points listed in dpNamesSet to the values given in dpValuesSet and waits for another set of data points to change their values until all specified conditions are met (that is, all values of the data points listed in dpNamesWait are equal to the values given in conditions). Once conditions are fulfilled, it returns the values of another set of data points (given in dpNamesReturn). If the conditions are not met within the specified timeoutMs period, the promise is rejected.
NOTE
The values in conditions are compared directly in TypeScript, not by WinCC OA. Therefore the comparision is not as strict as it would be when using the CTRL function
dpSetAndWaitForValue()
, which also checks the type of the values. For example, in CTRL an integer value will never match a float value, also if both have the same numeric value, while in JavaScript the comparision will only based on the numeric value.
Names of the data points to set.
Values to set, must have the same size as dpNamesSet.
Names of the data points to wait for a value change.
Expected values for the data points in dpNamesWait to wait for. Must have the same size as dpNamesWait.
Names of the data points whose values will be returned in the Promise.
Optional timeout for waiting on conditions.
Promise containing the values for dpNamesReturn .
WinccoaError when timeout expired, DPE names do not exist, values cannot be converted, array sizes mismatch, no write access etc.
Sets a comment (description) for the data point.
Data point element to be commented on.
Comment in one or all languages.
Promise - will be resolved to true
if successful or rejected with an error.
WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.
let isSuccess = false;
try {
isSuccess = await winccoa.dpSetDescription('ExampleDP_Rpt1.', {
'de_AT.utf8': 'German description',
'en_US.utf8': 'English description',
'ru_RU.utf8': 'Russian description',
});
} catch (exc) {
console.error(exc);
}
console.info('DP description is set successfully - ' + isSuccess);
Sets the numerical format(s) of a data point.
Data point element
A string that contains the format (for example, '%6.2f') in one or several languages.
Promise - will be resolved to true
if successful or rejected with an error.
WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.
Set values of one or more data point element(s) with a given source time.
Source time for the value change.
Data point element name(s) of the values to set.
Values to set. Must have the same size as dpeNames. If dpeNames is a single string and not an array, this parameter must also be a single value and not an array.
Boolean true
in case of a success, otherwise false
.
Since this method does not wait for the actual value update in the database, the update can still fail after this method returned
true
. Use dpSetTimedWait to also get informed about these errors.
WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch etc.
Set values of one or more data point element(s) with a given source time.
Source time for the value change.
Data point element name(s) of the values to set.
Values to set. Must have the same size as dpeNames. If dpeNames is a single string and not an array, this parameter must also be a single value and not an array.
Promise that resolves to true
if succesful. If not successful,
a WinccoaError wil be thrown instead.
WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch, no write access etc.
Sets the unit(s) for a data point.
Data point
Unit (for example, kg) in one or several languages.
Promise - will be resolved to true
if successful or rejected with an error.
WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.
Set the value of one or more data point element(s).
Data point element name(s) of the values to set.
Values to set. Must have the same size as dpeNames. If dpeNames is a single string and not an array, this parameter must also be a single value and not an array.
Promise that resolves to true
if succesful. If not successful,
a WinccoaError wil be thrown instead.
WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch, no write access etc.
Returns all or selected data point types from the current project.
Pattern for the returned DPTs. When an empty pattern is given (=default), then returns all DP types.
Wildcards are used to filter data point type name.
The charcters *
and ?
are used for the purpose,
where the asterisk (*
) replaces any number of characters and the question mark ?
stands for just one character.
Wildcards can be used in arrays (square brackets , e.g.: [0,3,5-7]
- numbers 0,3,5,6,7) or outside arrays in option lists (in curly brackets {}
).
Example of wildcards in lists of options:
winccoa.dpTypes('{*.Ala.*,*.Ala*}');
winccoa.dpTypes('*{.Ala.,.Ala}*');
winccoa.dpTypes('*.A{la.,la}*');
winccoa.dpTypes('*.Al{a.,a}*');
winccoa.dpTypes('*.Ala{.,}*');
winccoa.dpTypes('*.Ala{.}*');
winccoa.dpTypes('*.Ala.*');
winccoa.dpTypes('*.Ala*');
The desired system if querying from other systems. Optional parameter. If this parameter is not defined, the own system is queried.
When this is set to false, data point types without existing data points will be ignored.
String array with all DP type names.
WinccoaError when invalid argument type or non-existing systemId is given.
This function waits for a set of data points to change their values until all specified conditions are met (that is, all values of the data points listed in dpNamesWait are equal to the values given in conditions). Once conditions are fulfilled, it returns the values of another set of data points (given in dpNamesReturn). If the conditions are not met within the specified timeoutMs period, the promise is rejected.
NOTE
The values in conditions are compared directly in TypeScript, not by WinCC OA. Therefore the comparision is not as strict as it would be when using the CTRL function
dpWaitForValue()
, which also checks the type of the values. For example, in CTRL an integer value will not match a float value, also if both have the same numeric value, while in JavaScript the comparision will only based on the numeric value.
Names of the data points to wait for a value change.
Expected values for the data points in dpNamesWait to wait for. Must have the same size as dpNamesWait.
Names of the data points whose values will be returned in the Promise.
Optional timeout for waiting on conditions.
Promise containing the values for dpNamesReturn .
WinccoaError when timeout expired, DPE names do not exist, values cannot be converted, array sizes mismatch etc.
Checks if a given name contains invalid characters for a specific use (e. g. as data point or project name) and also provides a version of that name with invalid characters removed.
The name to check
The type of check to perform, there is a different set of invalid characters for each type.
Promise for an object containing a valid flag and a version of name without invalid characters.
WinccoaError in case of an invalid arguments.
import { WinccoaManager, WinccoaNameCheckType } from 'winccoa-manager';
const winccoa = new WinccoaManager();
...
// checking if a name is valid
if (
!(await winccoa.nameCheck(nameToCheck, WinccoaNameCheckType.Project)).valid
)
console.error(`Invalid project name: ${nameToCheck}`);
// automatically correct name if necessary
const name = (await winccoa.nameCheck(nameToCheck, WinccoaNameCheckType.Dp)).name;
Returns all references to other DPTs in a DPT.
Name of the data point type to be checked for references (for example, "PUMP1")
Object containing two array with references and their corresponding data point element path.
Data point element paths corresponding to the references in refNames.
Reference names.
Returns all DPTs and DPs that contain the specified DPT as a reference.
Name of the DPT reference to check data point types and data points for (for example, "_MyReference" or "_ValueArchive").
Object containing two arrays with DPT names and the corresponding data point element path.
Data point element names corresponding to the the DPTs in dptNames.
DPT names.
Change an existing data point type tree. The startNode.name must be an existing Data point type name. The complete type structure under startNode will be replaced. Use WinccoaDpTypeNode.newName to rename an existing name.
the top data point type node of the tree.
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
import { WinccoaDpTypeNode, WinccoaElementType, WinccoaManager } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function test1() {
const tree =
new WinccoaDpTypeNode('MyType1', WinccoaElementType.Struct, '', [
new WinccoaDpTypeNode('text', WinccoaElementType.String, '', [], 'string'),
new WinccoaDpTypeNode('typeRef', WinccoaElementType.Typeref, 'ExampleDP_Int'),
new WinccoaDpTypeNode('struct', WinccoaElementType.Struct, '', [
new WinccoaDpTypeNode('id2', WinccoaElementType.Float)
])
]);
console.log(await winccoa.dpTypeChange(tree));
}
test1();
Creates a new data point type tree.
the first data point type node of the tree.
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
import { WinccoaDpTypeNode, WinccoaElementType, WinccoaManager } from 'winccoa-manager';
const winccoa = new WinccoaManager();
async function test1() {
const tree =
new WinccoaDpTypeNode('MyType1', WinccoaElementType.Struct, '', [
new WinccoaDpTypeNode('id', WinccoaElementType.Int),
new WinccoaDpTypeNode('text', WinccoaElementType.String),
new WinccoaDpTypeNode('typeRef', WinccoaElementType.Typeref, 'ExampleDP_Float'),
new WinccoaDpTypeNode('struct', WinccoaElementType.Struct, '', [
new WinccoaDpTypeNode('id2', WinccoaElementType.Int),
new WinccoaDpTypeNode('text2', WinccoaElementType.String)
])
]);
console.log(await winccoa.dpTypeCreate(tree));
}
test1();
Deletes an existing data point type.
Name of the data point type to delete.
Promise - will be resolved to true
if successful
or rejected with WinccoaError in case of:
Returns the structure of a data point type.
Data point type.
true: subtypes will be passed
Data point type structure as a tree of WinccoaDpTypeNode
Reports a security event, this must be called whenever a security-relevant action is made in JavaScript (like opening a server port).
ID of the security event.
Rest
...args: unknown[]Arguments for the security event, depending on the value of id. See WinccoaSecurityEventId for details.
WinccoaError when id is not known, required arguments are missing in args.
Constructor - creates new instance of an API object.
Gets access sysConnect updates, which uses the Node.js event emitter mechanism to inform clients of various events. For details and examples see WinccoaSysConnect.
Exits the WinCC OA manager.
NOTE
For details about using an exit listener with WinCC OA, see the note in the documentation for WinccoaSysConEvent.
Exit code to return to the operating system.
Search for file or directory in WinCC OA project and installation paths.
the file or directory to search for
full path of the file or directory or an empty string if not found
WinccoaError when invalid argument type is given.
Returns all available options and their values. The options can be set with setOptions.
Object containing all current option values.
Returns the system ID.
Optional
systemName: stringThe name of the system (optional). If it is not given, then the system ID of its own system will be returned.
The system ID.
WinccoaError when invalid system name is given.
Returns the system name.
Optional
systemId: numberSystem ID (optional). If it is not given, then the system name of its own system will be returned.
The system name.
WinccoaError when invalid system ID is given.
Returns information about current API and WinCC OA versions.
API and WinCC OA versions.
Set one or more options. The options and their values can be retrieved with getOptions.
The options to be set (see WinccoaOptions for possible options).
Boolean true
on success, otherwise WinccoaError wil be thrown instead.
The userId option cannot be set with this method.
The user can be set with setUserId for the instance of WinccoaManager
.
The user can be set with -user
manager option for the node manager,
see Administration of managers.
WinccoaError if option has wrong type or option value is out of range.
Sets the current user ID to the specified value for the current instance of WinccoaManager.
Note that when Server-side Authentication for Managers is activated and the JavaScript manager is not started as
root
, trying to change the user ID will lead to a fatal error and the JavaScript manager will be terminated immediately.
User ID to set.
Optional
password: stringPassword to use to set user (not needed if manager started as root
).
Boolean true
in case of a success, otherwise WinccoaError wil be thrown instead.
WinccoaError when id is not found or invalid.
Main class of the TypeScript/JavaScript API to the WinCC OA JavaScript Manager for Node.js®.
To use the API, an instance of this class needs to be created, e. g.:
Example