Skip to content

Commit 650e285

Browse files
committed
fix: s7 DAQ of tags #1341
1 parent c44961c commit 650e285

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

client/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
</div>
4646
</div>
4747
</app-root>
48-
<script src="runtime.8ef63094e52a66ba.js" type="module"></script><script src="polyfills.df504f67f09f2fbb.js" type="module"></script><script src="scripts.a58f5e48421f8dfe.js" defer></script><script src="main.284789750866d50a.js" type="module"></script>
48+
<script src="runtime.8ef63094e52a66ba.js" type="module"></script><script src="polyfills.df504f67f09f2fbb.js" type="module"></script><script src="scripts.a58f5e48421f8dfe.js" defer></script><script src="main.149de4493b758fd7.js" type="module"></script>
4949

5050
</body></html>
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fuxa",
3-
"version": "1.2.0-1838",
3+
"version": "1.2.0-1839",
44
"keywords": [],
55
"author": "frangoteam <[email protected]>",
66
"description": "Web-based Process Visualization (SCADA/HMI/Dashboard) software",

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fuxa-server",
3-
"version": "1.2.0-1838",
3+
"version": "1.2.0-1839",
44
"description": "Web-based Process Visualization (SCADA/HMI/Dashboard) software",
55
"main": "main.js",
66
"scripts": {

server/runtime/devices/s7/index.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* 's7': snap7 wrapper to communicate with Siemens PLC (S7)
2+
* 's7': snap7 wrapper to communicate with Siemens PLC (S7)
33
*/
44

55
var snap7;
@@ -93,10 +93,10 @@ function S7client(_data, _logger, _events, _runtime) {
9393
}
9494

9595
/**
96-
* Read values in polling mode
96+
* Read values in polling mode
9797
* Update the tags values list, save in DAQ if value changed or in interval and emit values to clients
9898
*/
99-
this.polling = function () {
99+
this.polling = async function () {
100100
if (_checkWorking(true)) {
101101
var readVarsfnc = [];
102102
for (var dbnum in db) {
@@ -107,10 +107,11 @@ function S7client(_data, _logger, _events, _runtime) {
107107
readVarsfnc.push(_readVars(chunk));
108108
})
109109
}
110-
Promise.all(readVarsfnc).then(result => {
110+
try {
111+
const result = await Promise.all(readVarsfnc);
111112
_checkWorking(false);
112113
if (result.length) {
113-
let varsValueChanged = _updateVarsValue(result);
114+
let varsValueChanged = await _updateVarsValue(result);
114115
lastTimestampValue = new Date().getTime();
115116
_emitValues(varsValue);
116117
if (this.addDaq && !utils.isEmptyObject(varsValueChanged)) {
@@ -122,14 +123,14 @@ function S7client(_data, _logger, _events, _runtime) {
122123
if (lastStatus !== 'connect-ok') {
123124
_emitStatus('connect-ok');
124125
}
125-
}, reason => {
126+
} catch (reason) {
126127
if (reason && reason.stack) {
127128
logger.error(`'${data.name}' _readVars error! ${reason.stack}`);
128129
} else {
129130
logger.error(`'${data.name}' _readVars error! ${reason}`);
130131
}
131132
_checkWorking(false);
132-
});
133+
};
133134
} else {
134135
_emitStatus('connect-busy');
135136
}
@@ -220,7 +221,7 @@ function S7client(_data, _logger, _events, _runtime) {
220221

221222
/**
222223
* Set the Tag value
223-
* Read the current Tag object, write the value in object and send to SPS
224+
* Read the current Tag object, write the value in object and send to SPS
224225
*/
225226
this.setValue = async function (sigid, value) {
226227
var item = _getTagItem(data.tags[sigid]);
@@ -260,23 +261,23 @@ function S7client(_data, _logger, _events, _runtime) {
260261

261262
/**
262263
* Return the timestamp of last read tag operation on polling
263-
* @returns
264+
* @returns
264265
*/
265266
this.lastReadTimestamp = () => {
266267
return lastTimestampValue;
267268
}
268269

269270
/**
270271
* Return the Daq settings of Tag
271-
* @returns
272+
* @returns
272273
*/
273274
this.getTagDaqSettings = (tagId) => {
274275
return data.tags[tagId] ? data.tags[tagId].daq : null;
275276
}
276277

277278
/**
278279
* Set Daq settings of Tag
279-
* @returns
280+
* @returns
280281
*/
281282
this.setTagDaqSettings = (tagId, settings) => {
282283
if (data.tags[tagId]) {
@@ -305,7 +306,7 @@ function S7client(_data, _logger, _events, _runtime) {
305306

306307
/**
307308
* Update the Tags values read
308-
* @param {*} vars
309+
* @param {*} vars
309310
*/
310311
var _updateVarsValue = async (vars) => {
311312
var someval = false;
@@ -392,15 +393,15 @@ function S7client(_data, _logger, _events, _runtime) {
392393

393394
/**
394395
* Emit the PLC Tags values array { id: <name>, value: <value>, type: <type> }
395-
* @param {*} values
396+
* @param {*} values
396397
*/
397398
var _emitValues = function (values) {
398399
events.emit('device-value:changed', { id: data.id, values: values });
399400
}
400401

401402
/**
402403
* Emit the PLC connection status
403-
* @param {*} status
404+
* @param {*} status
404405
*/
405406
var _emitStatus = function (status) {
406407
lastStatus = status;
@@ -409,7 +410,7 @@ function S7client(_data, _logger, _events, _runtime) {
409410

410411
/**
411412
* Used to manage the async connection and polling automation (that not overloading)
412-
* @param {*} check
413+
* @param {*} check
413414
*/
414415
var _checkWorking = function (check) {
415416
if (check && working) {
@@ -455,7 +456,7 @@ function S7client(_data, _logger, _events, _runtime) {
455456
vars.map(v => {
456457
let value = null;
457458
if (v.type === 'BOOL') {
458-
// check the full byte and send all bit if there is a change
459+
// check the full byte and send all bit if there is a change
459460
value = datatypes['BYTE'].parser(res, v.Start - offset, -1);
460461
} else {
461462
value = datatypes[v.type].parser(res, v.Start - offset, v.bit);
@@ -472,7 +473,7 @@ function S7client(_data, _logger, _events, _runtime) {
472473

473474
/**
474475
* Read multiple Vars
475-
* @param {*} vars
476+
* @param {*} vars
476477
*/
477478
var _readVars = function (vars) {
478479
return new Promise((resolve, reject) => {
@@ -486,7 +487,7 @@ function S7client(_data, _logger, _events, _runtime) {
486487
} else {
487488
try {
488489
if (v.type === 'BOOL') {
489-
// check the full byte and send all bit if there is a change
490+
// check the full byte and send all bit if there is a change
490491
value = datatypes['BYTE'].parser(res[i].Data);//, v.Start, -1);
491492
} else {
492493
value = datatypes[v.type].parser(res[i].Data);
@@ -575,7 +576,7 @@ function S7client(_data, _logger, _events, _runtime) {
575576
if (variable) {
576577
var prefix = variable.substring(0, 2);
577578
if (prefix === 'DB') {
578-
// DB[n]"
579+
// DB[n]"
579580
var startpos = variable.indexOf('.');
580581
var dbNum = parseInt(variable.substring(2, startpos));
581582
if (dbNum >= 0) {
@@ -665,7 +666,7 @@ function S7client(_data, _logger, _events, _runtime) {
665666

666667
/**
667668
* Return error message, from error code
668-
* @param {*} s7err
669+
* @param {*} s7err
669670
*/
670671
var _getErr = function (s7err) {
671672
if (Array.isArray(s7err)) return new Error('Errors: ' + s7err.join('; '));

0 commit comments

Comments
 (0)