npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-opc-da

v1.0.7

Published

A library to communicate with OPC-DA servers

Downloads

2,635

Readme

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

// creates a COM Session from a domain, an username, and a password
let comSession = new Session();
comSession = comSession.createSession(domain, username, password);

// sets a global timeout for connections related to this session
comSession.setGlobalSocketTimeout(timeout);

// create a COM Server from a classid, an IP address and the previously created session
let comServer = new ComServer(clsid, address, comSession);

// star the COM Server
await comServer.init();

/* from the COM Server, we create a instance we'll use to create every other COM related object */
let comObject = await comServer.createInstance();

// with the comObjet created, we create an OPC Server object and call init()
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

/* opts {
 * {Boolean} [active]
 * {Number} [updateRate]
 * {Number} [clientHandle]
 * {Number} [timeBias]
 * {Number} [deadband] - until asyn read is implemented this does nothing
 * {Number} [localeID]
 * }
 */
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.

/* {Number} [handle]
 * {Boolean} [force]
 */
opcServer.removeGroup(groupHandle, force);

OPC Items

Adding an Item

// create a item manager from the group object
let opcItemManager = await opcGroup.getItemManager();

/* item {
 * {String} [itemID] - the name of the item on the server, can be obtained through browser
 * {Number} [clientHandle] - a locally generated number to identify this item
 * }
 * calls the add() function passing one or more item objects as parameter
 */
opcItemManager.add(item | itemList);

Validating an Item

/* item {
 * {String} [itemID] - the name of the item on the server, can be obtained through browser
 * {Number} [clientHandle] - a locally generated number to identify this item
 * }
 */
opcItemManager.validate(item | itemList);

Reading with OPC Sync

// create a reading object for the group
let opcSyncIO = await opcGroup.getSyncIO();

/* {Number} [dataSource] - from where it will be read
 * {Number} [serverHandles] - one or more handles. An item handle is obtained by calling 
 * the add() function, which returns an array of properties for each item readed.
*/
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.