Skip to content

Commit

Permalink
Finish covnert to typescript and add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
msvargas committed Oct 2, 2019
1 parent d566069 commit bd2ed44
Show file tree
Hide file tree
Showing 29 changed files with 2,749 additions and 4,175 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
__pycache__
node_modules
*.py
*.py

**/*.js
**/*.d.ts
9 changes: 8 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.git
__pycache__
.vscode
examples
yarn-error.log
yarn-error.log
*.py

**/*.ts
!**/*.d.ts
doc
80 changes: 46 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ Nodejs package to handle PLC as Micro820 of Allen Bradley

- Manager multiple connections to write/read tags using pooling with generic-pool

- Listener events as *connect*, *connect_error*, *disconnect* or *found* (discover function)
- Listener events as _connect_, _connect_error_, _disconnect_ or _found_ (discover function)

- Ardunio mode: functions as digitalRead, digitalWrite...
- Ardunio mode: functions as digitalRead, digitalWrite...

- Add typescript

## Install package

Expand Down Expand Up @@ -55,6 +57,7 @@ comm.on("disconnect", reason => {
## Example: Discover devices

Find devices using dgram socket

```js
const PLC = require("node-logix");

Expand All @@ -66,30 +69,24 @@ PLC.discover().then(devices => {
## Example: Arduino mode

```js
comm
.digitalRead(0)
.then(result => {
console.timeEnd("reading digital");
console.log("value of:", result.valueOf(), "tagName:", result.tagName);
})
.catch(console.error);
[0, 1, 2, 3, 4, 5, 6].forEach(p => {
comm
.digitalRead(0)
.then(result => {
console.timeEnd("reading digital");
console.log(
"value of:",
result.valueOf(),
"tagName:",
result.tagName
);
})
.catch(console.error);
[0, 1, 2, 3, 4, 5, 6].forEach(p => {
comm
.digitalWrite(p, false)
.then(console.log)
.catch(e => console.error("error write", e));
});

.digitalWrite(p, false)
.then(console.log)
.catch(e => console.error("error write", e));
});
```

## Default Options

**NOTE:** Micro800 option default: *true*:
**NOTE:** Micro800 option default: _true_:

```js
PLC.defaultOptions = {
Expand All @@ -101,7 +98,7 @@ PLC.defaultOptions = {
pool: { // options generic-pool
min: 0,
max: 3,
Promise, //bluebird
Promise : Bluebird, //bluebird
priorityRange: 2,
fifo: false,
testOnBorrow: true,
Expand All @@ -122,18 +119,19 @@ This project is licensed under the MIT License - see the [LICENCE](https://githu
- For Micro800 of CIP Service if limited, no working getProgramList, getModuleProperties(0)..., only get global tag names
- ArduinoMode only working with Micro800 enable, to working with other PLC, yout must be create custom pinMapping JSON and replacePin function:
- ArduinoMode only working with Micro800 enable, to working with other PLC, yout must be create custom pinMapping JSON and replacePin function:
```js
comm.pinMapping = {
"digital" : {
"output": "_IO_EM_DO_{dd}",
"input": "_IO_EM_DI_{dd}"
},
"analog" : {
"input" : "_IO_EM_AI_{dd}",
"output" : "_IO_EM_AO_{dd}"
}
comm.pinMapping = {
digital: {
output: "_IO_EM_DO_{dd}",
input: "_IO_EM_DI_{dd}"
},
analog: {
input: "_IO_EM_AI_{dd}",
output: "_IO_EM_AO_{dd}"
}
};
/**
* @description replace pin mapping
* @param {String} str
Expand All @@ -154,5 +152,19 @@ function _replacePin(str = "", pin) {
return str;
}
```
# Issues
- For write array, only write 256 positions
## More Examples
https://github.com/dmroeder/pylogix/tree/master/pylogix/examples
# NOTE:
**Connection size:**
- Packets have a ~500 byte limit, so you have to be cautions
about not exceeding that or the read will fail. It's a little
difficult to predict how many bytes your reads will take up becuase
the send packet will depend on the length of the tag name and the
reply will depened on the data type. Strings are a lot longer than
DINT's for example.
- Micro800 has CIP protocol Limited, check examples to check work functions
12 changes: 8 additions & 4 deletions examples/01_write_read_simple.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
"use-strict";

/**
* The simplest example of writing and reading a tag from a PLC
* @description The simplest example of writing and reading a tag from a PLC
*/

/**
* more @examples : https://github.com/dmroeder/pylogix/tree/master/pylogix/examples
*/
const PLC = require("../index").default;

PLC.defaultOptions.Micro800 = true;
const comm = new PLC("192.168.100.174");

comm
.connect()
.then(() => {
return comm.write("_IO_EM_DO_01", false).then(() => {
return comm.write("_IO_EM_DO_01", true).then(() => {
return comm.read("_IO_EM_DO_01").then(console.log);
});
})
Expand Down
154 changes: 0 additions & 154 deletions examples/02_pool_read.js

This file was deleted.

15 changes: 13 additions & 2 deletions examples/03_discover_promise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
"use-strict";

/**
* @description Found IPv4 devices - PLC
*/
const PLC = require("../index").default;
PLC.defaultOptions.Micro800 = true;

PLC.discover().then(devices => {
PLC.discover(3000, {
family: "IPv4",
onFound: (device, n) => {
console.log(`#${n}`, device.address());
},
onError: (msg, rinfo) => {
console.log("msg:", msg, "rinfo", rinfo);
}
}).then(devices => {
console.log(devices);
});
7 changes: 5 additions & 2 deletions examples/04_get_all_tags.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use-strict";

/**
* The simplest example of writing and reading a tag from a PLC
* @description The simplest example of writing and reading a tag from a PLC
*/

const PLC = require("../index").default;
PLC.defaultOptions.Micro800 = true;

const comm = new PLC("192.168.100.174");

Expand All @@ -12,7 +15,7 @@ comm
comm
.getTagList()
.then(tags => {
console.log("Tags list:", tags.length);
console.log("Tags list:", tags);
})
.catch(console.error);
})
Expand Down
Loading

0 comments on commit bd2ed44

Please sign in to comment.