opc-da
This library implements the OPC-DA specifications and allows to communicate with OPC Servers, relying on the node-dcom library for DCOM/DCE-RPC for protocol implementation. Currently this lib support browsing calls and synchronous reads. The code overall strucuture was heavly based on Utgard.
This node was created by Smart-Tech as part of the ST-One project.
Table of Contents
Install
Using npm:
npm install node-opc-da
Usage
OPC Server
An OPC server is on object you will be using as the basis for every operation and object instantiation to communicate with a remote OPC server. Since OPC-DA relies on COM/DCOM for all it's features, to create a basic OPC Server object we'll need to create a few COM objects first.
Creating a Server
let comSession = new Session();
comSession = comSession.createSession(domain, username, password);
comSession.setGlobalSocketTimeout(timeout);
let comServer = new ComServer(clsid, address, comSession);
await comServer.init();
let comObject = await comServer.createInstance();
let opcServer = new OPCServer();
await opcServer.init(comObject);
Removing a Server
To remove an OPC Server reference we call the end()
function. This call only release objects created from the server object (opcBrowser, opcItemManager, opcGroupStateManager) and the server object itself. See the node-dcom
library for more information on how to remove a COM session and server.
opcServer.end()
OPC Browse
Browsing function are used to explore the items stored in the server. OPC-DA offers mainly two types of browsing: flat browsing and tree browsing. Flat Browsing returns a flat list of all server items, ignoring any internal directory tree. Tree Browsing, walks throughout the internal directory tree and returns a list of directories, each containing a list of items.
Flat browsing
let opcBrowser = await opcServer.getBrowser();
let items = await opcBrowser.browseAllFlat();
Tree browsing
let opcBrowser = await opcServer.getBrowser();
let items = await opcBrowser.browseAllTree();
OPC Groups
After an OPC Server is created, if you want to read one or more items you must first create a group. To achieve this we call the function addGroup
giving a group name and a list of options as parameters.
Creating a Group
let opcGroup = await opcServer.addGroup(name, opts)
Removing a Group
To remove a group from an opcServer we call the function removeGroup
giving the group handle as paremeter, and a boolean
value to indicate if the server must wait any ongoing operation to end before being removed or not.
opcServer.removeGroup(groupHandle, force);
OPC Items
Adding an Item
let opcItemManager = await opcGroup.getItemManager();
opcItemManager.add(item | itemList);
Validating an Item
opcItemManager.validate(item | itemList);
Reading with OPC Sync
let opcSyncIO = await opcGroup.getSyncIO();
await opcSyncIO.read(dataSource, serverHandles);
Disclaimer
This is a work in progress. Expect things to break, crash and burn. We cannot be hold liable for any damage to any equipment or issues directly or indirectly caused by this library. You've been warned.
Contributing
This is a partial implementation and there are lots that could be done to improve what is already supported or to add support for more OPC-DA features. Feel free to dive in! Open an issue or submit PRs.
License
Copyright 2017 Smart-Tech, Apache 2.0 license.