Skip to content

Commit b98e71a

Browse files
committed
examples
1 parent ed6c96e commit b98e71a

File tree

6 files changed

+144
-30
lines changed

6 files changed

+144
-30
lines changed

examples/async.js

-14
This file was deleted.

examples/async_LOGO.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const snap7 = require("napi-snap7");
2+
3+
const client = new snap7.S7Client();
4+
5+
const time = (ms) => console.log("| Execution time : %d ms", ms);
6+
7+
const res_p = client.SetConnectionParams("192.168.57.12", 0x2000, 0x2100);
8+
9+
const res_c = client.Connect();
10+
11+
// Read out the outputs Q1 - Q8 of a LOGO 0BA8
12+
// DB number (always 0 for LOGO!s)
13+
// | Offset to start
14+
// | | Size to read (bytes)
15+
// | | |
16+
client.DBRead(0, 1064, 1, (err, data) => {
17+
if (err) return console.log(client.ErrorText(err));
18+
console.log("Data", data);
19+
time(client.ExecTime());
20+
client.Disconnect();
21+
});
22+
23+
/* OR */
24+
25+
// Write a 1 in the bit of the VB address V300.5
26+
const buffer = Buffer.from([0b00100000]);
27+
// DB number (always 0 for LOGO!s)
28+
// | Offset to start
29+
// | | Size to write (bytes)
30+
// | | | User buffer
31+
// | | | |
32+
client.DBWrite(0, 300, 1, buffer, (err, data) => {
33+
if (err) return console.log(client.ErrorText(err));
34+
console.log("Data", data);
35+
time(client.ExecTime());
36+
client.Disconnect();
37+
});

examples/async_S7.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const snap7 = require("napi-snap7");
2+
3+
const client = new snap7.S7Client();
4+
5+
const time = (ms) => console.log("| Execution time : %d ms", ms);
6+
7+
const res = client.ConnectTo("192.168.57.12", 0, 1);
8+
9+
// Reading 100 bytes from DB 510 starts at 0
10+
// Area identifier (0x84 - S7AreaDB)
11+
// | DB number if area = S7AreaDB, otherwise ignored
12+
// | | Offset to start
13+
// | | | Amount of words to read
14+
// | | | | Word size (0x02 - Byte (8 bit))
15+
// | | | | |
16+
client.ReadArea(0x84, 510, 0, 100, 0x02, (err, data) => {
17+
if (err) return console.log(client.ErrorText(err));
18+
console.log("Data", data);
19+
time(client.ExecTime());
20+
client.Disconnect();
21+
});
22+
23+
/* OR */
24+
25+
// Write 42 to address 0 of DB 510
26+
const buffer = Buffer.from([42]);
27+
// Area identifier (0x84 - S7AreaDB)
28+
// | DB number if area = S7AreaDB, otherwise ignored
29+
// | | Offset to start
30+
// | | | Amount of words to write
31+
// | | | | Word size (0x02 - Byte (8 bit))
32+
// | | | | | User buffer
33+
// | | | | | |
34+
client.WriteArea(0x84, 510, 0, 1, 0x02, buffer, (err, data) => {
35+
if (err) return console.log(client.ErrorText(err));
36+
console.log("Data", data);
37+
time(client.ExecTime());
38+
client.Disconnect();
39+
});

examples/sync.js

-16
This file was deleted.

examples/sync_LOGO.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const snap7 = require('napi-snap7')
2+
3+
const client = new snap7.S7Client()
4+
5+
const time = (ms) => console.log('| Execution time : %d ms', ms)
6+
7+
const res_p = client.SetConnectionParams("192.168.57.12", 0x2000, 0x2100);
8+
9+
const res_c = client.Connect();
10+
console.log('ConnectTo', res_c)
11+
time(client.ExecTime())
12+
console.log('Connected', client.GetConnected())
13+
14+
// Read out the outputs Q1 - Q8 of a LOGO 0BA8
15+
// DB number (always 0 for LOGO!s)
16+
// | Offset to start
17+
// | | Size to read (bytes)
18+
// | | |
19+
const data_r = client.DBReadSync(0, 1064, 1)
20+
console.log('Data', data_r)
21+
time(client.ExecTime())
22+
23+
// Write a 1 in the bit of the VB address V300.5
24+
const buffer = Buffer.from([0b00100000]);
25+
// DB number (always 0 for LOGO!s)
26+
// | Offset to start
27+
// | | Size to write (bytes)
28+
// | | | User buffer
29+
// | | | |
30+
const data_w = client.DBWriteSync(0, 300, 1, buffer)
31+
32+
client.Disconnect()

examples/sync_S7.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const snap7 = require('napi-snap7')
2+
3+
const client = new snap7.S7Client()
4+
5+
const time = (ms) => console.log('| Execution time : %d ms', ms)
6+
7+
const res = client.ConnectTo('192.168.20.55', 0, 1)
8+
console.log('ConnectTo', res)
9+
time(client.ExecTime())
10+
console.log('Connected', client.GetConnected())
11+
12+
// Reading 20 words from DB 510 starts at 0
13+
// Area identifier (0x84 - S7AreaDB)
14+
// | DB number if area = S7AreaDB, otherwise ignored
15+
// | | Offset to start
16+
// | | | Amount of words to read
17+
// | | | | Word size (0x04 - Word (16 bit))
18+
// | | | | |
19+
const data_r = client.ReadAreaSync(0x84, 510, 0, 20, 0x04)
20+
console.log('Data', data_r)
21+
time(client.ExecTime())
22+
23+
// Write 42 to address 0 of DB 510
24+
const buffer = Buffer.from([42]);
25+
// Area identifier (0x84 - S7AreaDB)
26+
// | DB number if area = S7AreaDB, otherwise ignored
27+
// | | Offset to start
28+
// | | | Amount of words to write
29+
// | | | | Word size (0x02 - Byte (8 bit))
30+
// | | | | | User buffer
31+
// | | | | | |
32+
const data_w = client.WriteAreaSync(0x84, 510, 0, 1, 0x02, buffer)
33+
console.log('Data', data_w)
34+
time(client.ExecTime())
35+
36+
client.Disconnect()

0 commit comments

Comments
 (0)