基于区块链的毕业设计Node Ethernet/IP – 节点以太网/IP

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计Node Ethernet/IP – 节点以太网/IP 是一篇很好的国外资料

Node Ethernet/IP - 节点以太网/IP

Node Ethernet/IP

A simple and lightweight node based API for interfacing with Rockwell Control/CompactLogix PLCs.

Prerequisites

latest version of NodeJS

Getting Started

Install with npm

npm install SerafinTech/node-ethernet-ip --save 

The API

How the heck does this thing work anyway? Great question!

The Basics

Getting Connected

const { Controller } = require("ethernet-ip");  const PLC = new Controller();  // Controller.connect(IP_ADDR[, SLOT]) // NOTE: SLOT = 0 (default) - 0 if CompactLogix PLC.connect("192.168.1.1", 0).then(() => {     console.log(PLC.properties); });

Controller.properties Object

 {     name: String, // eg "1756-L83E/B"     serial_number: Number,      slot: Number,     time: Date, // last read controller WallClock datetime     path: Buffer,     version: String, // eg "30.11"     status: Number,     faulted: Boolean,  // will be true if any of the below are true     minorRecoverableFault: Boolean,     minorUnrecoverableFault: Boolean,     majorRecoverableFault: Boolean,     majorUnrecoverableFault: Boolean,     io_faulted: Boolean }

Set the Clock of the Controller

NOTE Controller.prototype.readWallClock and Controller.prototype.writeWallClock are experimental features and may not be available on all controllers. 1756-L8 ControlLogix Controllers are currently the only PLCs supporting these features.

Sync Controller WallClock to PC Datetime

const { Controller } = require("ethernet-ip");  const PLC = new Controller();  PLC.connect("192.168.1.1", 0).then(async () => {     // Accepts a JS Date Type     // Controller.writeWallClock([Date])     await PLC.writeWallClock(); // Defaults to 'new Date()' });

Set Controller WallClock to a Specific Date

const { Controller } = require("ethernet-ip");  const PLC = new Controller();  PLC.connect("192.168.1.1", 0).then(async () => {     const partyLikeIts1999 = new Date('December 17, 1999 03:24:00');     await PLC.writeWallClock(partyLikeIts1999); // Pass a custom Datetime });

Reading Tags

NOTE: Currently, the Tag Class only supports Atomic datatypes (SINT, INT, DINT, REAL, BOOL). Not to worry, support for STRING, ARRAY, and UDTs are in the plans and coming soon! =]

Reading Tags Individually

const { Controller, Tag } = require("ethernet-ip");  const PLC = new Controller();  // Create Tag Instances const fooTag = new Tag("contTag"); // Controller Scope Tag const barTag = new Tag("progTag", "prog"); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {     await PLC.readTag(fooTag);     await PLC.readTag(barTag);      console.log(fooTag.value);     console.log(barTag.value); });

Additional Tag Name Examples …

const fooTag = new Tag("Program:prog.progTag"); // Alternative Syntax for Program Scope Tag in PLC Program "prog" const barTag = new Tag("arrayTag[0]"); // Array Element const bazTag = new Tag("arrayTag[0,1,2]"); // Multi Dim Array Element const quxTag = new Tag("integerTag.0"); // SINT, INT, or DINT Bit const quuxTag = new Tag("udtTag.Member1"); // UDT Tag Atomic Member const quuzTag = new Tag("boolArray[0]", null, BIT_STRING); // bool array tag MUST have the data type "BIT_STRING" passed in

Reading Tags as a Group

const { Controller, Tag, TagGroup } = require("ethernet-ip");  const PLC = new Controller(); const group = new TagGroup();  // Add some tags to group group.add(new Tag("contTag")); // Controller Scope Tag group.add(new Tag("progTag", "prog")); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {     await PLC.readTagGroup(group);      // log the values to the console     group.forEach(tag => {         console.log(tag.value);     }); });

Writing Tags

NOTE: You MUST read the tags first or manually provide a valid CIP datatype. The following examples are taking the latter approach.

Writing Tags Individually

const { Controller, Tag, EthernetIP } = require("ethernet-ip"); const { DINT, BOOL } = EthernetIP.CIP.DataTypes.Types;  const PLC = new Controller();  // Create Tag Instances const fooTag = new Tag("contTag", null, DINT); // Controller Scope Tag const barTag = new Tag("progTag", "prog", BOOL); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {      // First way to write a new value     fooTag.value = 75;     await PLC.writeTag(fooTag);      // Second way to write a new value     await PLC.writeTag(barTag, true);      console.log(fooTag.value);     console.log(barTag.value); });

Writing Tags as a Group

const { Controller, Tag, TagGroup, EthernetIP } = require("ethernet-ip"); const { DINT, BOOL } = EthernetIP.CIP.DataTypes.Types;  const PLC = new Controller(); const group = new TagGroup();  // Create Tag Instances const fooTag = new Tag("contTag", null, DINT); // Controller Scope Tag const barTag = new Tag("progTag", "prog", BOOL); // Program Scope Tag in PLC Program "prog"  group.add(fooTag); // Controller Scope Tag group.add(barTag); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {     // Set new values     fooTag.value = 75;     barTag.value = true;      // Will only write tags whose Tag.controller_tag !== Tag.value     await PLC.writeTagGroup(group);      group.forEach(tag => {         console.log(tag.value);     }); });

Lets Get Fancy

Subscribing to Controller Tags

const { Controller, Tag } = require("ethernet-ip");  const PLC = new Controller();  // Add some tags to group PLC.subscribe(new Tag("contTag")); // Controller Scope Tag PLC.subscribe(new Tag("progTag", "prog")); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(() => {     // Set Scan Rate of Subscription Group to 50 ms (defaults to 200 ms)     PLC.scan_rate = 50;      // Begin Scanning     PLC.scan(); });  // Catch the Tag "Changed" and "Initialized" Events PLC.forEach(tag => {     // Called on the First Successful Read from the Controller     tag.on("Initialized", tag => {         console.log("Initialized", tag.value);     });      // Called if Tag.controller_value changes     tag.on("Changed", (tag, oldValue) => {         console.log("Changed:", tag.value);     }); });

Newest Capabilities

Getting a List of Available Controller Tags and Structure Templates

const { Controller, TagList } = require("ethernet-ip");  const PLC = new Controller();  const tagList = new TagList();  PLC.connect("192.168.1.1", 0).then(async () => {          // Get all controller tags and program tags     await PLC.getControllerTagList(tagList)      // Displays all tags     console.log(tagList.tags)      // Displays all templates     console.log(tagList.templates)      // Displays program names     console.log(tagList.programs)       });

TagList.tags[] Object

 {     id: Number, // Instance ID     program: String, // Name of program scope of tag. {Null} is controller scope     type {         typeCode: Number, // Data type code         typeName: String, // Data type name         structure: Boolean, // TRUE if is structure.         arrayDims: Number, // Number of dimmensions of array. If not array = 0         reserved: Boolean // TRUE if is reserved     } }

Reading/Writing LINT – Node.js >= 12.0.0

const { Controller, Tag } = require("ethernet-ip");  const PLC = new Controller();  const tag = new Tag('BigInteger1');  PLC.connect("192.168.1.1", 0).then(async () => {          // Read LINT     await PLC.readTag(tag)      // Displays all tags     console.log(tag.value)  // output: 123456789n      //Big Number Maths     tag.value = tag.value + 1n // add 1      console.log(tag.value) // output: 123456790n           //Write new Big Number to      await PLC.writeTag(tag)       });

Reading/Writing Strings

const { Controller, Tag, TagList, Structure } = require("ethernet-ip");  const PLC = new Controller();  PLC.connect("192.168.1.1", 0).then(async () => {          const tagList = new TagList();     await PLC.getControllerTagList(tagList);      const stringStructure = new Structure('String1', tagList, {Optional Program Name});     await PLC.readTag(stringStructure);      console.log(stringStructure.value);      stringStructure.value = "New String Value";     await PLC.writeTag(stringStructure)      });

Demos

  • Monitor Tags for Changes Demo

Node Ethernet/IP - 节点以太网/IP

const { Controller, Tag } = require("ethernet-ip");  // Intantiate Controller const PLC = new Controller();  // Subscribe to Tags PLC.subscribe(new Tag("TEST_TAG");); PLC.subscribe(new Tag("TEST", "Prog");); PLC.subscribe(new Tag("TEST_REAL", "Prog");); PLC.subscribe(new Tag("TEST_BOOL", "Prog"););  // Connect to PLC at IP, SLOT PLC.connect("10.1.60.205", 5).then(() => {     const { name } = PLC.properties;      // Log Connected to Console     console.log(`nnConnected to PLC ${name}...n`);      // Begin Scanning Subscription Group     PLC.scan(); });  // Initialize Event Handlers PLC.forEach(tag => {     tag.on("Changed", (tag, lastValue) => {         console.log(`${tag.name} changed from ${lastValue} -> ${tag.value}`);     }); })

Built With

  • NodeJS – The Engine
  • javascript – ES2017 – The Language

Contributers

  • Jason SerafinOwner – GitHub Profile
  • Canaan SeatonForked From Owner – GitHub Profile – Personal Website
  • Patrick McDonaghCollaborator – GitHub Profile
  • Jeremy HensonCollaborator – Github Profile

Related Projects

  • Node Red

Wanna become a contributor? Here’s how!

License

This project is licensed under the MIT License – see the LICENCE file for details

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.


Node Ethernet/IP - 节点以太网/IP

节点以太网/IP

一个简单而轻量级的基于节点的API,用于与罗克韦尔控制/CompactLogix PLC接口。

先决条件

NodeJS的最新版本

入门

用npm安装

npm install SerafinTech/node-ethernet-ip --save 

API

这个东西到底是怎么工作的?好问题!

基础知识

连接

const { Controller } = require("ethernet-ip");  const PLC = new Controller();  // Controller.connect(IP_ADDR[, SLOT]) // NOTE: SLOT = 0 (default) - 0 if CompactLogix PLC.connect("192.168.1.1", 0).then(() => {     console.log(PLC.properties); });

控制器.属性对象

 {     name: String, // eg "1756-L83E/B"     serial_number: Number,      slot: Number,     time: Date, // last read controller WallClock datetime     path: Buffer,     version: String, // eg "30.11"     status: Number,     faulted: Boolean,  // will be true if any of the below are true     minorRecoverableFault: Boolean,     minorUnrecoverableFault: Boolean,     majorRecoverableFault: Boolean,     majorUnrecoverableFault: Boolean,     io_faulted: Boolean }

设置控制器时钟

注释Controller.prototype.readWallClock以及Controller.prototype.writeWallClock是实验特性,可能并非所有控制器都可用。1756-L8 ControlLogix控制器是目前唯一支持这些功能的PLC。

将控制器WallClock同步到PC日期时间

const { Controller } = require("ethernet-ip");  const PLC = new Controller();  PLC.connect("192.168.1.1", 0).then(async () => {     // Accepts a JS Date Type     // Controller.writeWallClock([Date])     await PLC.writeWallClock(); // Defaults to 'new Date()' });

将控制器WallClock设置为特定日期

const { Controller } = require("ethernet-ip");  const PLC = new Controller();  PLC.connect("192.168.1.1", 0).then(async () => {     const partyLikeIts1999 = new Date('December 17, 1999 03:24:00');     await PLC.writeWallClock(partyLikeIts1999); // Pass a custom Datetime });

读取标签

注意:目前,Tag类仅支持原子数据类型(SINT、INT、DINT、REAL、BOOL)。不用担心,对STRING、ARRAY和udt的支持已经在计划中,而且很快就会推出!=]

分别读取标签。。。其他示例。。。

const { Controller, Tag } = require("ethernet-ip");  const PLC = new Controller();  // Create Tag Instances const fooTag = new Tag("contTag"); // Controller Scope Tag const barTag = new Tag("progTag", "prog"); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {     await PLC.readTag(fooTag);     await PLC.readTag(barTag);      console.log(fooTag.value);     console.log(barTag.value); });

作为一个组读取标记。。。

const fooTag = new Tag("Program:prog.progTag"); // Alternative Syntax for Program Scope Tag in PLC Program "prog" const barTag = new Tag("arrayTag[0]"); // Array Element const bazTag = new Tag("arrayTag[0,1,2]"); // Multi Dim Array Element const quxTag = new Tag("integerTag.0"); // SINT, INT, or DINT Bit const quuxTag = new Tag("udtTag.Member1"); // UDT Tag Atomic Member const quuzTag = new Tag("boolArray[0]", null, BIT_STRING); // bool array tag MUST have the data type "BIT_STRING" passed in

注意:您必须先读取标签或手动提供有效的CIP数据类型。以下示例采用后一种方法。

const { Controller, Tag, TagGroup } = require("ethernet-ip");  const PLC = new Controller(); const group = new TagGroup();  // Add some tags to group group.add(new Tag("contTag")); // Controller Scope Tag group.add(new Tag("progTag", "prog")); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {     await PLC.readTagGroup(group);      // log the values to the console     group.forEach(tag => {         console.log(tag.value);     }); });

让我们花点心思

分别写入标记。。。

将标记作为一个组写入。。。

const { Controller, Tag, EthernetIP } = require("ethernet-ip"); const { DINT, BOOL } = EthernetIP.CIP.DataTypes.Types;  const PLC = new Controller();  // Create Tag Instances const fooTag = new Tag("contTag", null, DINT); // Controller Scope Tag const barTag = new Tag("progTag", "prog", BOOL); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {      // First way to write a new value     fooTag.value = 75;     await PLC.writeTag(fooTag);      // Second way to write a new value     await PLC.writeTag(barTag, true);      console.log(fooTag.value);     console.log(barTag.value); });

标签列表.tags[]对象

const { Controller, Tag, TagGroup, EthernetIP } = require("ethernet-ip"); const { DINT, BOOL } = EthernetIP.CIP.DataTypes.Types;  const PLC = new Controller(); const group = new TagGroup();  // Create Tag Instances const fooTag = new Tag("contTag", null, DINT); // Controller Scope Tag const barTag = new Tag("progTag", "prog", BOOL); // Program Scope Tag in PLC Program "prog"  group.add(fooTag); // Controller Scope Tag group.add(barTag); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(async () => {     // Set new values     fooTag.value = 75;     barTag.value = true;      // Will only write tags whose Tag.controller_tag !== Tag.value     await PLC.writeTagGroup(group);      group.forEach(tag => {         console.log(tag.value);     }); });

订阅控制器标签

最新功能

const { Controller, Tag } = require("ethernet-ip");  const PLC = new Controller();  // Add some tags to group PLC.subscribe(new Tag("contTag")); // Controller Scope Tag PLC.subscribe(new Tag("progTag", "prog")); // Program Scope Tag in PLC Program "prog"  PLC.connect("192.168.1.1", 0).then(() => {     // Set Scan Rate of Subscription Group to 50 ms (defaults to 200 ms)     PLC.scan_rate = 50;      // Begin Scanning     PLC.scan(); });  // Catch the Tag "Changed" and "Initialized" Events PLC.forEach(tag => {     // Called on the First Successful Read from the Controller     tag.on("Initialized", tag => {         console.log("Initialized", tag.value);     });      // Called if Tag.controller_value changes     tag.on("Changed", (tag, oldValue) => {         console.log("Changed:", tag.value);     }); });

获取可用控制器标记和结构模板的列表

读/写LINT-节点.js>=12.0.0

const { Controller, TagList } = require("ethernet-ip");  const PLC = new Controller();  const tagList = new TagList();  PLC.connect("192.168.1.1", 0).then(async () => {          // Get all controller tags and program tags     await PLC.getControllerTagList(tagList)      // Displays all tags     console.log(tagList.tags)      // Displays all templates     console.log(tagList.templates)      // Displays program names     console.log(tagList.programs)       });

Node Ethernet/IP - 节点以太网/IP

 {     id: Number, // Instance ID     program: String, // Name of program scope of tag. {Null} is controller scope     type {         typeCode: Number, // Data type code         typeName: String, // Data type name         structure: Boolean, // TRUE if is structure.         arrayDims: Number, // Number of dimmensions of array. If not array = 0         reserved: Boolean // TRUE if is reserved     } }

读/写字符串

const { Controller, Tag } = require("ethernet-ip");  const PLC = new Controller();  const tag = new Tag('BigInteger1');  PLC.connect("192.168.1.1", 0).then(async () => {          // Read LINT     await PLC.readTag(tag)      // Displays all tags     console.log(tag.value)  // output: 123456789n      //Big Number Maths     tag.value = tag.value + 1n // add 1      console.log(tag.value) // output: 123456790n           //Write new Big Number to      await PLC.writeTag(tag)       });

演示

const { Controller, Tag, TagList, Structure } = require("ethernet-ip");  const PLC = new Controller();  PLC.connect("192.168.1.1", 0).then(async () => {          const tagList = new TagList();     await PLC.getControllerTagList(tagList);      const stringStructure = new Structure('String1', tagList, {Optional Program Name});     await PLC.readTag(stringStructure);      console.log(stringStructure.value);      stringStructure.value = "New String Value";     await PLC.writeTag(stringStructure)      });

使用

  • Jeremy Henson-Collaborator-GitHub Profile

想成为贡献者吗?方法如下!

const { Controller, Tag } = require("ethernet-ip");  // Intantiate Controller const PLC = new Controller();  // Subscribe to Tags PLC.subscribe(new Tag("TEST_TAG");); PLC.subscribe(new Tag("TEST", "Prog");); PLC.subscribe(new Tag("TEST_REAL", "Prog");); PLC.subscribe(new Tag("TEST_BOOL", "Prog"););  // Connect to PLC at IP, SLOT PLC.connect("10.1.60.205", 5).then(() => {     const { name } = PLC.properties;      // Log Connected to Console     console.log(`nnConnected to PLC ${name}...n`);      // Begin Scanning Subscription Group     PLC.scan(); });  // Initialize Event Handlers PLC.forEach(tag => {     tag.on("Changed", (tag, lastValue) => {         console.log(`${tag.name} changed from ${lastValue} -> ${tag.value}`);     }); })

贡献者构建的

  • Node Red
  • javascript – ES2017 – The Language

相关项目

  • Jason SerafinOwner – GitHub Profile
  • Canaan SeatonForked From Owner – GitHub Profile – Personal Website
  • Patrick McDonaghCollaborator – GitHub Profile
  • Jeremy HensonCollaborator – Github Profile

许可证

  • Node Red

本项目根据麻省理工学院许可证获得许可证-有关详细信息,请参阅许可证文件。

基本cookies

我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。了解更多。

我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。
您可以随时通过单击页面底部的Cookie首选项来更新您的选择。有关更多信息,请参阅我们的隐私声明。

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/18135.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计Node Ethernet/IP – 节点以太网/IP

提供最优质的资源集合

立即查看 了解详情