Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port support #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { ENIP, CIP } = require("../enip");
const dateFormat = require("dateformat");
const TagGroup = require("../tag-group");
const { delay, promiseTimeout } = require("../utilities");
const { EIP_PORT } = require("../config");
const Queue = require("task-easy");

const compare = (obj1, obj2) => {
Expand Down Expand Up @@ -105,17 +106,21 @@ class Controller extends ENIP {
* @override
* @param {string} IP_ADDR - IPv4 Address (can also accept a FQDN, provided port forwarding is configured correctly.)
* @param {number} SLOT - Controller Slot Number (0 if CompactLogix)
* @param {number} TCP_PORT - Port For TCP/IP Connection (defaults to stand Ethernet/IP Port)
* @returns {Promise}
* @memberof ENIP
*/
async connect(IP_ADDR, SLOT = 0) {
async connect(IP_ADDR, SLOT = 0, TCP_PORT = EIP_PORT) {
const { PORT } = CIP.EPATH.segments;
const BACKPLANE = 1;

this.state.controller.slot = SLOT;
this.state.controller.path = PORT.build(BACKPLANE, SLOT);

const sessid = await super.connect(IP_ADDR);
const sessid = await super.connect(
IP_ADDR,
TCP_PORT
);

if (!sessid) throw new Error("Failed to Register Session with Controller");

Expand Down Expand Up @@ -516,7 +521,6 @@ class Controller extends ENIP {
// Wait for Response
await promiseTimeout(
new Promise((resolve, reject) => {

// Full Tag Writing
this.on("Write Tag", (err, data) => {
if (err) reject(err);
Expand Down Expand Up @@ -688,7 +692,7 @@ class Controller extends ENIP {
break;
case WRITE_TAG_FRAGMENTED:
this.emit("Write Tag Fragmented", error, data);
break;
break;
case READ_MODIFY_WRITE_TAG:
this.emit("Read Modify Write Tag", error, data);
break;
Expand Down
6 changes: 4 additions & 2 deletions src/enip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ class ENIP extends Socket {
*
* @override
* @param {string} IP_ADDR - IPv4 Address (can also accept a FQDN, provided port forwarding is configured correctly.)
* @param {number} PORT - Port For TCP/IP Connection (defaults to stand Ethernet/IP Port)
* @returns {Promise}
* @memberof ENIP
*/
async connect(IP_ADDR) {
async connect(IP_ADDR, TCP_PORT = EIP_PORT) {
if (!IP_ADDR) {
throw new Error("Controller <class> requires IP_ADDR <string>!!!");
}

await new Promise((resolve, reject) => {
lookup(IP_ADDR, (err, addr) => {
if (err) reject(new Error("DNS Lookup failed for IP_ADDR " + IP_ADDR));
Expand All @@ -114,7 +116,7 @@ class ENIP extends Socket {
await promiseTimeout(
new Promise(resolve => {
super.connect(
EIP_PORT,
TCP_PORT,
IP_ADDR,
() => {
this.state.TCP.establishing = false;
Expand Down