@ali-pay/node-red-contrib-s7 3.4.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +14 -0
  2. package/package.json +3 -3
  3. package/red/s7.js +34 -18
package/README.md CHANGED
@@ -5,6 +5,20 @@ This node was created as part of the [ST-One](https://st-one.io) project.
5
5
 
6
6
  ## 更新日志
7
7
 
8
+ ### v3.6.1
9
+
10
+ - 更新 nodes7 版本
11
+
12
+ ### v3.6.0
13
+
14
+ - 同步原仓库代码
15
+
16
+ ### v3.5.0
17
+
18
+ - `_s7` 结构增加 `datetime` 字段
19
+
20
+ - `s7-out` 结构增加 `_s7` 的相同字段
21
+
8
22
  ### v3.4.0
9
23
 
10
24
  - `s7-out` 节点增加 `已重写次数` 的输出
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@ali-pay/node-red-contrib-s7",
3
- "version": "3.4.0",
3
+ "version": "3.6.1",
4
4
  "description": "A Node-RED node to interact with Siemens S7 PLCs",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
- "@st-one-io/nodes7": "1.1.0"
7
+ "@st-one-io/nodes7": "1.1.3"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "url": "https://github.com/ali-pay/node-red-contrib-s7/issues"
15
15
  },
16
16
  "scripts": {
17
- "publish": "npm publish"
17
+ "release": "npm publish"
18
18
  },
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org"
package/red/s7.js CHANGED
@@ -32,6 +32,35 @@ function equals(a, b) {
32
32
  return false;
33
33
  }
34
34
 
35
+ /**
36
+ * Returns a date as a string value in `YYYY-MM-DD HH:mm:ss` format.
37
+ * @param {Date} date
38
+ * @returns
39
+ */
40
+ function formatDate(date) {
41
+ const pad = (n, len = 2) => String(n).padStart(len, '0')
42
+ return (
43
+ date.getFullYear() +
44
+ '-' + pad(date.getMonth() + 1) +
45
+ '-' + pad(date.getDate()) +
46
+ ' ' + pad(date.getHours()) +
47
+ ':' + pad(date.getMinutes()) +
48
+ ':' + pad(date.getSeconds()) +
49
+ '.' + pad(date.getMilliseconds(), 3)
50
+ )
51
+ }
52
+
53
+ function get_s7(node) {
54
+ const time = new Date()
55
+ return {
56
+ plc: node.endpoint.name,
57
+ ip: node.endpoint.endpoint._connOptsTcp.host,
58
+ status: node.endpoint.getStatus() === 'online' ? '在线' : '离线',
59
+ time: time,
60
+ datetime: formatDate(time),
61
+ }
62
+ }
63
+
35
64
  var MIN_CYCLE_TIME = 50;
36
65
 
37
66
  var tools = require('../src/tools.js');
@@ -304,6 +333,7 @@ module.exports = function (RED) {
304
333
  itemGroup.readAllItems().then(cycleCallback).catch(e => {
305
334
  node.error(e, {});
306
335
  readInProgress = false;
336
+ manageStatus('offline');
307
337
  });
308
338
  readInProgress = true;
309
339
  } else {
@@ -383,12 +413,7 @@ module.exports = function (RED) {
383
413
  var msg = {
384
414
  topic: key,
385
415
  payload: data,
386
- _s7: {
387
- plc: node.endpoint.name,
388
- ip: node.endpoint.endpoint._connOptsTcp.host,
389
- status: node.endpoint.getStatus() === 'online' ? '在线' : '离线',
390
- time: new Date(),
391
- }
416
+ _s7: get_s7(node),
392
417
  };
393
418
  statusVal = status !== undefined ? status : data;
394
419
  node.send(msg);
@@ -421,12 +446,7 @@ module.exports = function (RED) {
421
446
  var msg = {
422
447
  topic: '',
423
448
  payload: {},
424
- _s7: {
425
- plc: node.endpoint.name,
426
- ip: node.endpoint.endpoint._connOptsTcp.host,
427
- status: node.endpoint.getStatus() === 'online' ? '在线' : '离线',
428
- time: new Date(),
429
- }
449
+ _s7: get_s7(node),
430
450
  };
431
451
  node.send(msg);
432
452
  }
@@ -515,12 +535,7 @@ module.exports = function (RED) {
515
535
  })
516
536
 
517
537
  // 调用 s7-out 后的输出消息
518
- msg._s7 = {
519
- plc: node.endpoint.name,
520
- ip: node.endpoint.endpoint._connOptsTcp.host,
521
- status: node.endpoint.getStatus() === 'online' ? '在线' : '离线',
522
- time: new Date(),
523
- }
538
+ msg._s7 = get_s7(node),
524
539
  msg.payload = {
525
540
  variable: variable, // 写入的键
526
541
  payload: payload, // 写入的值
@@ -530,6 +545,7 @@ module.exports = function (RED) {
530
545
  bingo: false, // plc的最新值跟写入值是否一致
531
546
  error: error, // 错误
532
547
  rewriteCount: 0, // 已重写次数
548
+ ...msg._s7,
533
549
  }
534
550
 
535
551
  // 处理错误 done(e) 不生效;需要使用 node.error(e)