Class WinccoaManager

Main class of the TypeScript/JavaScript API to the WinCC OA JavaScript Manager for Node.js®.

IMPORTANT

All methods described in this documentation must be called from code inside a method or function to prevent unexpected or undefined behavior.

To use the API, an instance of this class needs to be created, e. g.:

Example

import { WinccoaManager } from 'winccoa-manager';
const winccoa = new WinccoaManager();

Constructors

  • Constructor - creates new instance of an API object.

    Returns WinccoaManager

    Example

    import { WinccoaManager } from 'winccoa-manager';
    const winccoa = new WinccoaManager();

Properties

api: WinccoaManagerApi
winccoaManagerConnection: ConnectionBinding

Methods

  • Allows to set data point alert attributes.

    Parameters

    • alerts: WinccoaAlertTime | WinccoaAlertTime[]

      Alert(s) of type WinccoaAlertTime to be set.

    • values: unknown

      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.

    Returns boolean

    Boolean true in case of a success, otherwise WinccoaError wil be thrown instead.

    Note

    The attributes and their constants which can be set with this method are described in the chapter _alert_hdl

    Throws

    WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.

    See

    Example

    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.

    Parameters

    • time: Date

      Source time for the attribute change.

    • alerts: WinccoaAlertTime | WinccoaAlertTime[]

      Alert(s) of type WinccoaAlertTime to be set.

    • values: unknown

      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.

    Returns boolean

    Boolean true in case of a success, otherwise WinccoaError wil be thrown instead.

    Note

    The attributes and their constants which can be set with this method are described in the chapter _alert_hdl

    Throws

    WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.

    See

    Example

    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.

    Parameters

    • time: Date

      Source time for the attribute change.

    • alerts: WinccoaAlertTime | WinccoaAlertTime[]

      Alert(s) of type WinccoaAlertTime to be set.

    • values: unknown

      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.

    Returns Promise<unknown>

    Promise that resolves to true if successful. If not successful, a WinccoaError wil be thrown instead.

    Throws

    WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.

    See

    Example

    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.

    Parameters

    • alerts: WinccoaAlertTime | WinccoaAlertTime[]

      Alert(s) of type WinccoaAlertTime to be set.

    • values: unknown

      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.

    Returns Promise<unknown>

    Promise that resolves to true if successful. If not successful, a WinccoaError wil be thrown instead.

    Throws

    WinccoaError when DPE does not exist, mismatch number of DPs and values, invalid argument type, etc.

    See

    Example

    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);
    }
    }
  • Creates a connection for being notified of datapoint element updates.

    Parameters

    • callback: WinccoaDpConnectCallback

      Function that is called whenever a connected value changes.

    • dpeNames: string | string[]

      DPE name(s) to connect to.

      • Each update will contain updates for all elements in dpeNames, not only the changed values.
      • Each update will contain an array of values, also if only a single datapoint element name is given.
    • answer: boolean = true

      if true, callback is called with the initial values right away, if false, callback is only called after an actual value change.

    Returns number

    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.

    Throws

    WinccoaError when invalid parameter types, unknown datapoint element names etc.

    Remark

    For an example describing how to pass user data to a callback, see the second example for WinccoaDpQueryConnectCallback.

    See

    Example

    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.

    Parameters

    • source: string

      Name of the datapoint to copy.

    • destination: string

      Name of the new copied datapoint. Must not exist yet.

    • Optional driver: number

      Optional driver number (default 1).

    Returns Promise<boolean>

    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).

    Throws

    WinccoaError when given source datapoint does not exist, when datapoint is copied into itself, invalid argument given, etc.

    See

    Example

    async function dpCopyTest() {
    let isSuccess = false;
    try {
    isSuccess = await winccoa.dpCopy('ExampleDP_Arg1', 'ExampleDP_Arg3');
    } catch (exc) {
    console.error(exc);
    }

    console.info("DP ExampleDP_Arg1 is copied to ExampleDP_Arg3 successfully - " + isSuccess);
    }
  • Creates a data point.

    Parameters

    • dpeName: string

      Name of the data point to be created.

    • dpType: string

      Type of data point to be created.

    • Optional systemId: number

      To create a data point on a remote system in a distributed system, this parameter must contain the system number.

    • Optional dpId: number

      The ID of the data point. If a data point with the given ID already exists, a random ID is chosen.

    Returns Promise<boolean>

    Promise - will be resolved to true if successful or rejected with an error.

    Throws

    WinccoaError in case of:

    • invalid argument type is given,
    • invalid dpeName, dpType or non-existing systemId is given,
    • data point with the given dpeName is already exist.

    See

    Example

    let dpCreated = false;
    try {
    dpCreated = await winccoa.dpCreate('newFloatDpe', 'ExampleDP_Float');
    } catch (exc) {
    console.error(exc);
    }

    console.info("DP newFloatDpe is created - " + dpCreated);
  • Deletes a data point.

    Parameters

    • dpName: string

      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.

    Returns Promise<boolean>

    Promise - will be resolved to true if successful or rejected with an error.

    Throws

    WinccoaError when datapoint with the given name does not exist or current user has no privileges to delete a DP.

    See

    Example

    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 datapoint element update connections established with dpConnect.

    Parameters

    • id: number

      ID of the connection to close as returned by dpConnect.

    Returns number

    ID of the connection that has been closed (>= 0).

    Throws

    WinccoaError when id is not found or invalid.

    See

    Example

    function connect() {
    let id = -1;
    try {
    id = winccoa.dpConnect(
    connectCB,
    ['ExampleDP_Arg1.', 'ExampleDP_Arg2.'],
    true
    );
    } catch (exc) {
    console.error(exc);
    }
    }

    function disconnect() {
    try {
    winccoa.dpDisconnect(id);
    } catch (exc) {
    console.error(exc);
    }
    }
  • Returns the data typeof a data point element.

    Parameters

    • dpeName: string

      Name of the data point element

    Returns WinccoaElementType

    Type of a data point element

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type.

    See

    Example

    import { WinccoaManager, WinccoaElementType } from 'winccoa-manager';
    const winccoa = new WinccoaManager();

    async function dpElementTypeTest()
    try {
    let dpType = await 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.

    Parameters

    • dpeName: string

      A data point identifier: a sys, a DPT, a DP, a DPE, a config, a detail or an attr.

    Returns boolean

    true if at least one part of a data point identifier can be resolved correctly, otherwise false.

    Throws

    WinccoaError when invalid argument type is given.

    See

    Example

    let isDpExists = false;
    try {
    isDpExists = winccoa.dpExists('ExampleDP_Arg1.');
    } catch (exc) {
    console.error(exc);
    }
    console.info("Is ExampleDP_Arg1 exists - " + isDpExists);
  • Get the current values of one or more datapoint elements.

    Parameters

    • dpeNames: string | string[]

      Datapoint element name(s) of the values to get.

    Returns Promise<unknown>

    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.

    Async

    Throws

    WinccoaError when DPE does not exist or current user has no read access to it.

    See

    CTRL function dpGet()

    Example

    const dpes = ['ExampleDP_Arg1.', 'ExampleDP_DDE.b1'];
    try {
    const values = (await winccoa.dpGet(dpes)) as [number, boolean];
    for (let i = 0; i < dpes.length; i++) {
    console.info(`${dpes[i]}: ${values[i]}`);
    }
    } catch (exc) {
    console.error(exc);
    }
  • Returns the alias for the specified data point.

    Parameters

    • dpeName: string

      Data point element

    Returns string

    the appropriate alias in the language. Note that the alias can be only unilingual.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type.

    See

    Example

    try {
    let alias = winccoa.dpGetAlias('ExampleDP_Rpt1.');
    console.info('DP alias: ' + alias);
    } catch (exc) {
    console.error(exc);
    }
  • Returns the comment (description) for the data point.

    Parameters

    • dpeName: string

      Data point element or data point

    • Optional mode: number

      Mode of functionality. For more details on all modes description see CTRL function dpGetDescription().

    Returns unknown

    Description in all available languages as langText or empty strings in all languages.

    The returned data type can be defined with setOptions.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type.

    See

    Example

    let description;
    try {
    description = winccoa.dpGetDescription('ExampleDP_Rpt1.');
    } catch (exc) {
    console.error(exc);
    description = null;
    }

    if (description)
    console.info('DP description: ' + description);
  • This function returns the numerical format(s) of a data point.

    Parameters

    • dpeName: string

      Data point element

    Returns unknown

    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.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type.

    See

    Example

    let formats;
    try {
    formats = winccoa.dpGetFormat('ExampleDP_Rpt1.');
    } catch (exc) {
    console.error(exc);
    formats = null;
    }

    if (formats)
    console.info('DP formats: ' + formats);
  • This function returns the unit(s) of a data point.

    Parameters

    • dpeName: string

      Data point element

    Returns unknown

    Returns the unit as langText 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.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type.

    See

    Example

    try {
    let units = winccoa.dpGetUnit('ExampleDP_Rpt1.');
    console.info('DP units: ' + units);
    } catch (exc) {
    console.error(exc);
    }
  • Returns all the data point names or the data point element names that match a pattern in alphabetical order.

    Parameters

    • dpPattern: string = ''

      Serach pattern. When an empty pattern is given (=default), then returns all datapoints.
      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 attributes
      • dp.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);
    • dpType: string = ''

      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.

    • ignoreCase: boolean = false

      Defines if the search should ignore the casing of the search pattern (=true) or not (=false, default)

    Returns string[]

    List with data points or data point element names.

    Throws

    WinccoaError when invalid argument type is given.

    See

    Example

    let foundDpNames: string[] = [];
    try {
    foundDpNames = winccoa.dpNames('ExampleDP*', 'ExampleDP_Float');
    } catch (exc) {
    console.error(exc);
    }

    for (let i = 0; i < foundDpNames.length; i++) {
    console.info("DPE name: " + foundDpNames.at(i));
    }
  • Retrieves attribute values with the help of SQL statements.

    Parameters

    • query: string

      SQL statement.

    Returns Promise<unknown[][]>

    Promise - will be resolved to true if successful or rejected with an error.

    Note

    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]
    ]

    Throws

    WinccoaError when invalid parameter or query string is given.

    See

    Example

    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.

    Parameters

    • callback: WinccoaDpQueryConnectCallback

      Function that is called whenever a subscribed DPE value changes. The update message will contain all subscribed DPEs.

    • answer: boolean

      if true, callback is called with the initial DPE values right away, if false, callback is only called for an actual value change.

    • query: string

      query as an SQL statement.

    Returns number

    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.

    Throws

    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.

    Remark

    For an example describing how to pass user data to a callback, see the second example for WinccoaDpQueryConnectCallback.

    See

    Example

    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.

    Parameters

    • callback: WinccoaDpQueryConnectCallback

      Function that is called whenever a subscribed DPE value changes. The update message will contain only changed DPEs.

    • answer: boolean

      if true, callback is called with the initial DPE values right away, if false, callback is only called for an actual value change.

    • query: string

      query as an SQL statement.

    Returns number

    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.

    Throws

    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.

    Remark

    For an example describing how to pass user data to a callback, see the second example for WinccoaDpQueryConnectCallback.

    See

    Example

    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) .

    Parameters

    Returns number

    ID of the closed connection (>= 0).

    Throws

    WinccoaError when id is not found or invalid.

    See

    Example

    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);
    }
    }
  • Set the value of one or more datapoint element(s).

    Parameters

    • dpeNames: string | string[]

      Datapoint element name(s) of the values to set.

    • values: unknown

      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.

    Returns boolean

    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.

    Throws

    WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch etc.

    See

    Example

    const dpes = ['ExampleDP_Arg1.', 'ExampleDP_DDE.b1'];
    const values = [123.456, false];
    try {
    winccoa.dpSet(dpes, values); // Two arrays of size 2
    winccoa.dpSet('ExampleDP_Arg2.', 2); // single value
    } catch (exc) {
    console.error(exc);
    }
  • Sets the alias for the specified data point element.

    Parameters

    • dpeName: string

      Data point element

    • alias: string

      Alias to be set. Note that the alias can be set only unilingual.

    Returns Promise<unknown>

    Promise - will be resolved to true if successful or rejected with an error.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.

    See

    Example

    let isSuccess = false;
    try {
    isSuccess = await winccoa.dpSetAlias('ExampleDP_Rpt1.', 'rpt1Alias');
    } catch (exc) {
    console.error(exc);
    }

    console.info('DP alias is set successfully - ' + isSuccess);
  • Sets a comment (description) for the data point.

    Parameters

    • dpeName: string

      Data point element to be commented on

    • comment: unknown

      Comment as langText

    Returns Promise<boolean>

    Promise - will be resolved to true if successful or rejected with an error.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.

    See

    Example

    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.

    Parameters

    • dpeName: string

      Data point element

    • format: unknown

      A string that contains the format (for example, '%6.2f') in one or several languages.

    Returns Promise<unknown>

    Promise - will be resolved to true if successful or rejected with an error.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.

    See

    Example

    let isSuccess = false;
    try {
    isSuccess = await winccoa.dpSetFormat('ExampleDP_Rpt1.', {
    'de_AT.utf8': '%.4f',
    'en_US.utf8': '%.4f',
    'ru_RU.utf8': '%.2f',
    });
    } catch (exc) {
    console.error(exc);
    }

    console.info('DP formats are set successfully - ' + isSuccess);
  • Set values of one or more datapoint element(s) with a given source time.

    Parameters

    • time: Date

      Source time for the value change.

    • dpeNames: string | string[]

      Datapoint element name(s) of the values to set.

    • values: unknown

      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.

    Returns boolean

    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.

    Throws

    WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch etc.

    See

    Example

    const timeStamp = new Date('2023-01-03T04:05:06.789Z');
    let isSuccess = false;
    try {
    isSuccess = winccoa.dpSetTimed(timeStamp, 'ExampleDP_Arg1.', 2);
    } catch (exc) {
    console.error(exc);
    }

    console.info("dpSetTimed call is successed - " + isSuccess);
  • Set values of one or more datapoint element(s) with a given source time.

    Parameters

    • time: Date

      Source time for the value change.

    • dpeNames: string | string[]

      Datapoint element name(s) of the values to set.

    • values: unknown

      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.

    Returns Promise<boolean>

    Promise that resolves to true if succesful. If not successful, a WinccoaError wil be thrown instead.

    Throws

    WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch, no write access etc.

    See

    Example

    const timeStamp = new Date('2023-01-03T04:05:06.789Z');
    let isSuccess = false;
    try {
    isSuccess = await winccoa.dpSetTimedWait(timeStamp, 'ExampleDP_Arg1.', 2);
    } catch (exc) {
    console.error(exc);
    }

    console.info("Time and value are set for ExampleDP_Arg1 - " + isSuccess);
  • Sets the unit(s) for a data point.

    Parameters

    • dpeName: string

      Data point

    • unit: unknown

      Unit (for example, kg) in one or several languages as langText.

    Returns Promise<boolean>

    Promise - will be resolved to true if successful or rejected with an error.

    Throws

    WinccoaError when data point with the given dpeName is not found or invalid argument type, etc.

    See

    Example

    let isSuccess = false;
    try {
    isSuccess = await winccoa.dpSetUnit('ExampleDP_Rpt1.', {
    'de_AT.utf8': 's',
    'en_US.utf8': 's',
    'ru_RU.utf8': 'c',
    });
    } catch (exc) {
    console.error(exc);
    }

    console.info('DP units are set successfully - ' + isSuccess);
  • Set the value of one or more datapoint element(s).

    Parameters

    • dpeNames: string | string[]

      Datapoint element name(s) of the values to set.

    • values: unknown

      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.

    Returns Promise<boolean>

    Promise that resolves to true if succesful. If not successful, a WinccoaError wil be thrown instead.

    Throws

    WinccoaError when DPE names do not exist, values cannot be converted, array sizes mismatch, no write access etc.

    See

    Example

    const dpes = ['ExampleDP_Arg1.', 'ExampleDP_DDE.b1'];
    const values = [123.456, false];
    try {
    await winccoa.dpSetWait(dpes, values); // Two arrays of size 2
    await winccoa.dpSetWait('ExampleDP_Arg2.', 2); // single value
    } catch (exc) {
    console.error(exc);
    }
  • Returns all or selected data point types from the current project.

    Parameters

    • pattern: string = ''

      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*');
    • systemId: number = -1

      The desired system if querying from other systems. Optional parameter. If this parameter is not defined, the own system is queried.

    • includeEmpty: boolean = true

      When this is set to false, data point types without existing data points will be ignored.

    Returns string[]

    String array with all DP type names.

    Throws

    WinccoaError when invalid argument type or non-existing systemId is given.

    See

    Example

    try {
    const foundDpTypes = winccoa.dpTypes('ExampleDP*', 1, true);
    for (let i = 0; i < foundDpTypes.length; i++) {
    console.info("DP type: " + foundDpTypes.at(i));
    }
    } catch (exc) {
    console.error(exc);
    }
  • Exits the WinCC OA manager.

    Parameters

    • exitCode: number = 0

      Exit code to return to the operating system.

    Returns void

    Example

    winccoa.exit();
    
  • Search for file or directory in WinCC OA project and installation paths.

    Parameters

    • fileDirName: string

      the file or directory to search for

    Returns string

    full path of the file or directory or an empty string if not found

    Throws

    WinccoaError when invalid argument type is given.

    Example

    let configPath;
    try {
    configPath = winccoa.findFile('config/config');
    } catch (exc) {
    console.error(exc);
    }

    console.info("Config file full path: " + configPath);
  • Returns all available options and their values. The options can be set with setOptions.

    Returns WinccoaOptions

    Object containing all current option values.

    See

    Example

    let options = winccoa.getOptions();
    for (const [key, value] of Object.entries(options)) {
    console.info(`Name: ${key} - Value: ${value}`);
    }
  • Returns list of project, sub-project and product installation paths.

    Returns string[]

    List of project, sub-project and product installation paths. The project path is always a first entry and the installation path is always the last.

    Example

    let paths = winccoa.getPaths();
    for (let i = 0; i < paths.length; i++) {
    console.info(paths.at(i));
    }
  • Returns the system ID.

    Parameters

    • Optional systemName: string

      The name of the system (optional). If it is not given, then the system ID of its own system will be returned.

    Returns number

    The system ID.

    Throws

    WinccoaError when invalid system name is given.

    See

    Example

    let ownId;
    let system1Id;
    try {
    ownId = winccoa.getSystemId();
    system1Id = winccoa.getSystemId('System1:');
    } catch (exc) {
    console.error(exc);
    }

    console.info("Own system id = " + ownId);
    console.info("System1 id = " + system1Id);
  • Returns the system name.

    Parameters

    • Optional systemId: number

      System ID (optional). If it is not given, then the system name of its own system will be returned.

    Returns string

    The system name.

    Throws

    WinccoaError when invalid system ID is given.

    See

    Example

    try {
    const ownName = winccoa.getSystemName();
    const id1Name = winccoa.getSystemName(1);
    console.info(
    `Own system name = '${ownName}, system with id 1 name = '${id1Name}'`
    );
    } catch (exc) {
    console.error(exc);
    }
  • Checks if the event manager to which this manager is connected is currently the active REDU partner.

    Returns boolean

    true if the event manager to which this manager is connected is currently the active REDU partner.

    See

    Example

    const isEventReduActive = winccoa.isReduActive();
    console.info('Event currently is active - ' + isEventReduActive);
  • Checks whether the project has been configured as redundant.

    Returns boolean

    true if project has been configured as redundant.

    See

    Example

    const isProjectRedundant = winccoa.isRedundant();
    console.info('My project is redundant - ' + isProjectRedundant);
  • Writes a fatal error log entry. This also exits the WinCC OA manager.

    Parameters

    • Rest ...args: unknown[]

      Fatal error information to be written to log.

    Returns void

    Example

    let note = "Additional note.";
    winccoa.logFatal("Fatal message", note);
  • Writes an information log entry. console.log() and console.info() are mapped to this method.

    Parameters

    • Rest ...args: unknown[]

      Information to be written to log.

    Returns void

    Example

    let note = "Additional note.";
    winccoa.logInfo("Info message", note);
  • Writes a severe error log entry. console.error() is mapped to this method.

    Parameters

    • Rest ...args: unknown[]

      Severe error information to be written to log.

    Returns void

    Example

    let note = "Additional note.";
    winccoa.logSevere("Severe message", note);
  • Writes a warning log entry. console.warn() is mapped to this method.

    Parameters

    • Rest ...args: unknown[]

      Warning information to be written to log.

    Returns void

    Example

    let note = "Additional note.";
    winccoa.logWarning("Warning message", note);
  • Returns the host name of the Event Manager this manager is connected to. Use this method only on redundant computers.

    Returns string

    Host name of the Event Manager this manager is connected to.

    See

    Example

    const reduHostName = winccoa.myReduHost();
    console.info('My redu host name - ' + reduHostName);
  • Returns host number in a redundant system depending on the connection to the Event Manager - manager 1 or 2 (for example, eventHost = "host1$host2"). In a non-redundant configuration this always returns 1.

    Returns number

    Host number.

    See

    Example

    const reduHostNumber = winccoa.myReduHostNum();
    console.info('My redu host number - ' + reduHostNumber);
  • Reports a security event, this must be called whenever a security-relevant action is made in JavaScript (like opening a server port).

    Parameters

    Returns void

    Throws

    WinccoaError when id is not known, required arguments are missing in args.

    See

    WinccoaSecurityEventId

    Example

    import { WinccoaManager, WinccoaSecurityEventId } from 'winccoa-manager';
    const winccoa = new WinccoaManager();

    winccoa.securityEvent(WinccoaSecurityEventId.PortOpened, 8443, 'https://');
  • Set one or more options. The options and their values can be retrieved with getOptions.

    Parameters

    Returns boolean

    Boolean true on success, otherwise WinccoaError wil be thrown instead.

    Note

    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.

    Throws

    WinccoaError if option has wrong type or option value is out of range.

    See

    Example

    import { WinccoaManager, WinccoaLangTextFormat } from 'winccoa-manager';
    const winccoa = new WinccoaManager();

    function setOptionsTest() {
    try {
    winccoa.setOptions({
    langTextFormat: WinccoaLangTextFormat.StringFixed,
    langIdx: 1,
    });
    } catch (exc) {
    console.error(exc);
    }
    }
  • Sets the current user ID to the specified value for the current instance of WinccoaManager.

    Parameters

    • id: number

      User ID to set.

    • Optional password: string

      Password to use to set user (not needed if manager started as root).

    Returns boolean

    Boolean true in case of a success, otherwise WinccoaError wil be thrown instead.

    Throws

    WinccoaError when id is not found or invalid.

    See

    Example

    let isSuccess = false;
    try {
    isSuccess = winccoa.setUserId(2048); // operatorAll user id
    } catch (exc) {
    console.error(exc);
    }

    console.info('User id is set to operatorAll user id successfully - ' + isSuccess);