Skip to content

controlx-io/ethernet-ip-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ethernet/IP Controller Library

This library implements controller Ethernet/IP functionalities: Explicit Message Client and I/O Scanner written to support reads and writes to PLCs using Ethernet/IP protocol. Supports IO Scanner to interact with Ethernet/IP adapters.

Installation

Pick your command:

# Deno
deno add jsr:@controlx-io/ts-ethernet-ip

# npm (NodeJS)
npx jsr add @controlx-io/ts-ethernet-ip

# pnpm
pnpm i jsr:@controlx-io/ts-ethernet-ip

# yarn
yarn add jsr:@controlx-io/ts-ethernet-ip

# bun
bunx jsr add @controlx-io/ts-ethernet-ip

Example

To run the examples without downloading the library, install from Deno and run the commands.

Finds the first DINT tag and polls the value for 5 seconds.

deno --allow-net https://jsr.io/@controlx-io/ethernet-ip-controller/0.1.4/examples/basic.ts

or sends discovery packets for 10 seconds and displays the names of discovered Ethernet/IP devices.

deno --allow-net https://jsr.io/@controlx-io/ethernet-ip-controller/0.1.4/examples/discovery.ts

Or create a file main.ts with the content below and run deno --allow-net main.ts:

import { Controller } from "@controlx-io/ethernet-ip-controller";

const ipAddress = await prompt("Enter the IP address of the PLC:");
const plc = new Controller(true);

await plc.connect(ipAddress);
const dintTagInfo = plc.state.tagList.tags.find(
  (t) => t.type.typeName === "DINT",
);
if (!dintTagInfo) throw new Error("No DINT tags found");
console.log(dintTagInfo);

console.log("Starting polling for DINT tag for 5 seconds");
const tagToRead = plc.newTag(dintTagInfo.name, dintTagInfo.program);

let count = 0;
const tId = setInterval(async () => {
  count += 1;
  if (count > 5) {
    clearInterval(tId);
    console.log("Disconnecting from PLC");
    return plc.disconnect();
  }

  await plc.readTag(tagToRead);
  console.log(tagToRead.value);
}, 1000);

Inspirations

This project uses the following to achieve the desired.

https://github.com/cmseaton42/node-ethernet-ip
https://github.com/SerafinTech/ST-node-ethernet-ip
https://www.odva.org/wp-content/uploads/2020/05/PUB00213R0_EtherNetIP_Developers_Guide.pdf

About

A TypeScript library for controlling Ethernet/IP devices: Explicit Message Client and I/O Scanner

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published