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

netvar

v1.2.1

Published

Communicate to your codeSys plc over Network Variable Lists easily

Downloads

126

Readme

Changes to original package by alexander98

  • openList supports an additional boolean packed. Needed if the PLC has pack variables activated. In this mode, a set(), setMore() or cyclic send will always send all variables in one packed message, instead of sending each variable in an individual UDP packet. Also receive detects if message is packed and handles it correctly
  • send port not hardcoded to 1202, can be defined as an optional parameter in client().
  • debug: log sent and received messages
  • UDP message parts are encoded properly so listId can be larger than 0xF and the message counters increment correctly

CoDeSys NetworkVariableLists

To exchange global variables with a CoDeSys-PLC is very easy. Just create a NetworkVariableList (NVL (Sender)) and add your variables to the list. With this package you can receive this UDP-packages and parse them.

To send data to a CoDeSys-PLC, you define a new list with this node-module and use the generated definition to define the network variable list in your PLC as NVL (receiver).

How to do

The package is type-save and will hint you on your inputs. You can use it in Typescript and JavaScript. Please be careful with the types when you use it with JavaScript.

Create a new client

Create a new client with the netvar package

import { client } from 'netvar'

const netVar = client()
const netVar1 = client('192.168.0.123') //defaults to port 1202
const netVar2 = client('192.168.0.255', {port: 1202}) //uses the same port for send and receive
const netVar3 = client('192.168.0.123', {port: 1202, send_port: 1302}) //receive from port 1202, send to port 1302
const netVar4 = client('192.168.0.123', {debug: true}) //enable debug messages

Define a new or connect to existing list

Define a new variable list or enter the definition of an existing network variable list. The names do not matter for the communication and can be adjusted to your naming conventions.

Note: If you add a onChange callback you get all updates on this list live from the network.

const list1 = netVar.openList(
  { listId: 1 },
  {
    emergency: t.boolean(0),
    working: t.word(1),
    counter: t.dWord(2, 4242),
  },
)

// more lists
const list2 = netVar.openList({
  {
    listId: 2,
    onChange: (name, value) => console.log(name, value),
    cyclic: true,
    cycleInterval: 2000,
    packed: true, //pack all variables on send (when set() or setMore()). Some PLCs only support this mode
  },
  {
    Active: t.boolean(0),
    Next_Task: t.string(1, 'nut'),
    Speed: t.real(2, Math.PI),
  },
)

Get value

Read the value of a property from the list.

This value will be your initial values until you change it or you get different information over the network.

const value = list1.get('working')
console.log(value)

Set value

Set a one new value to a specific property from the list or set a number of new values.

The new values are send to the other peers (PLC).

list1.set('working', false)
list1.setMore({
  working: false,
  counter: 42,
})

Get Definition

Build the Definition to set the network variable list configuration on a PLC (receiver)

import fs from 'fs'
fs.writeFileSync('definiting.gvl', list1.definition)

Available data types

| Type | Node | PLC | | --------- | ------- | ------- | | t.boolean | boolean | BOOLEAN | | t.word | number | WORD | | t.string | string | STRING | | t.wString | string | WSTRING | | t.byte | number | BYTE | | t.dWord | number | DWORD | | t.time | number | TIME | | t.real | number | REAL | | t.lReal | number | LREAL |

Example:

import { t } from 'netvar'
const vars = {
  test: t.real(1, Math.PI),
}