Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OpcuaConnector

A connector service that provides base OPC UA Client functionality to be used by a Coaty controller class.

Create an instance of this service class in the onInit method of the controller passing in OpcuaOptions. Invoke connect on this service in the onCommunicationManagerStarting method. Invoke disconnect on this service in the onCommunicationManagerStopping method.

Invoke registerDataSources to register OPC UA data sources at run time, in addition to any data sources specified in the constructor options.

Register event handlers on the OpcuaConnector.on() method to get notified of data value changes of a monitored data source item ("dataValueChange" event), of errors ("error" event), and of OPC UA session establishment.

The event handler signatures are defined as follows:

// Emitted whenever an OPC UA error occurs.
on("error", (error: any) => void);

// Emitted whenever a monitored OPC UA data item changes its value.
on("dataValueChange", (
       dataSourceIdentifier: string,
       dataSource: OpcuaDataSource,
       dataValue: any,
       sourceTimestamp?: Date,  // undefined if not provided by OPC UA server
  ) => void);

// Emitted when the OPC UA client session has been created or closed.
// You can access the session object using the getter `opcuaClientSession`.
on("sessionCreated", () => void);
on("sessionClosed", () => void);

This class also provides convenience methods to read and write variable values, to read attribute values, to read analog item metadata, to browse data items, and to call OPC UA methods.

Note: To enable debug logging on the OPC UA client library level, set the process environment variable DEBUG to ALL.

remarks

This service only runs in a Node.js runtime, not in a browser.

Hierarchy

  • EventEmitter
    • OpcuaConnector

Index

Constructors

constructor

Properties

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: unique symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Accessors

opcuaClientSession

  • get opcuaClientSession(): ClientSession
  • Gets the OPC UA client session, as defined by the interface ClientSession of node-opcua-client package.

    The client session of the connector can be used to access OPC UA client functionality which is not exposed by connector methods.

    Returns undefined if the OPC UA client is not connected, i.e. session is not existing.

    Returns ClientSession

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

browse

  • browse(dataSource: OpcuaDataSource, options?: BrowseDescriptionOptions): Promise<ReferenceDescription[]>
  • Browse the given OPC UA data item, i.e. asynchronously receive a list of all its OPC UA child nodes.

    Parameters

    • dataSource: OpcuaDataSource

      OPC UA data source for an OPC UA item to browse

    • Optional options: BrowseDescriptionOptions

      optional OPC UA browse description options as defined in interface BrowseDescriptionOptions

    Returns Promise<ReferenceDescription[]>

    a promise that resolves to an array of ReferenceDescription objects describing child nodes (imported from node-opcua-client) or rejects if the given item couldn't be browsed.

call

  • call(objectDataSource: OpcuaDataSource, methodDataSource: OpcuaDataSource, inputArguments: Array<{ dataType: string | DataType; value: any }>): Promise<any[]>
  • Calls an OPC UA method on the given object node. The method is specified by its method node, and the input arguments.

    Parameters

    • objectDataSource: OpcuaDataSource

      OPC UA data source of the object node that provides the method

    • methodDataSource: OpcuaDataSource

      OPC UA data source of the method node to call

    • inputArguments: Array<{ dataType: string | DataType; value: any }>

      an array of objects defining OPC UA data type and value of input arguments.

    Returns Promise<any[]>

    a promise that resolves to an array of result values for the output arguments of the method call; the promise rejects if the given method call fails.

connect

  • connect(): Promise<any>
  • Asynchronously connects to the OPC UA server, creates a session emitting a sessionCreated event, and starts monitoring OPC UA data items if requested.

    Returns Promise<any>

disconnect

  • disconnect(): Promise<any>
  • Asynchronously disconnects from the OPC UA server, closing the client session and emitting a sessionClosed event.

    Returns Promise<any>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

readAnalogDataItem

  • Reads metadata of an OPC UA Analog Item defined by the given data source.

    remarks

    This method doesn't read the variable value of the analog data item, only its metadata.

    Parameters

    Returns Promise<OpcuaAnalogDataItem>

    a promise that resolves to an OpcuaAnalogDataItem object or rejects if analog data item cannot be read.

readAttributeValue

  • readAttributeValue(dataSource: OpcuaDataSource, attributeId: AttributeIds): Promise<any>
  • Reads an attribute value of an OPC UA item defined by the given data source and resolves it in the returned promise.

    remarks

    To use this method in your application code, import { AttributeIds } from "node-opcua-client".

    Parameters

    • dataSource: OpcuaDataSource

      OPC UA data source for an OPC UA item

    • attributeId: AttributeIds

      an OPC UA compliant AttributeId as defined by enum AttributeIds

    Returns Promise<any>

    a promise that resolves to the attribute value of the given item or rejects if attribute value can't be read or coerced

readVariableValue

  • Reads the value of an OPC UA variable defined by the given data source and resolves it in the returned promise.

    Parameters

    Returns Promise<any>

    a promise that resolves to the value of the given variable or rejects if value can't be read or coerced

registerDataSources

  • registerDataSources(dataSources: {}): void
  • Register the given OPC UA data sources.

    If a given data source identifier has already been registered (e.g. if specified in constructor options), the given data source is silently ignored.

    Parameters

    • dataSources: {}

      object hash of data sources identified by a unique key

    Returns void

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this

writeVariableValue

  • writeVariableValue(dataSource: OpcuaDataSource, value: any): Promise<any>
  • Writes the value of an OPC UA variable defined by the given data source.

    remarks

    The OPC UA data type of the value to write is defined by the OpcuaDataSource.dataType property.

    Parameters

    • dataSource: OpcuaDataSource

      OPC UA data source for an OPC UA variable

    • value: any

      value to write

    Returns Promise<any>

    a promise that resolves if the variable as been written successfully or rejects if value can't be coerced or written

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc