Skip to content

Commit

Permalink
fix: s7 DAQ of tags #1341
Browse files Browse the repository at this point in the history
  • Loading branch information
unocelli committed Sep 3, 2024
1 parent c44961c commit 650e285
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
</div>
</div>
</app-root>
<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>
<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>

</body></html>

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fuxa",
"version": "1.2.0-1838",
"version": "1.2.0-1839",
"keywords": [],
"author": "frangoteam <info@frangoteam.org>",
"description": "Web-based Process Visualization (SCADA/HMI/Dashboard) software",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fuxa-server",
"version": "1.2.0-1838",
"version": "1.2.0-1839",
"description": "Web-based Process Visualization (SCADA/HMI/Dashboard) software",
"main": "main.js",
"scripts": {
Expand Down
41 changes: 21 additions & 20 deletions server/runtime/devices/s7/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* 's7': snap7 wrapper to communicate with Siemens PLC (S7)
* 's7': snap7 wrapper to communicate with Siemens PLC (S7)
*/

var snap7;
Expand Down Expand Up @@ -93,10 +93,10 @@ function S7client(_data, _logger, _events, _runtime) {
}

/**
* Read values in polling mode
* Read values in polling mode
* Update the tags values list, save in DAQ if value changed or in interval and emit values to clients
*/
this.polling = function () {
this.polling = async function () {
if (_checkWorking(true)) {
var readVarsfnc = [];
for (var dbnum in db) {
Expand All @@ -107,10 +107,11 @@ function S7client(_data, _logger, _events, _runtime) {
readVarsfnc.push(_readVars(chunk));
})
}
Promise.all(readVarsfnc).then(result => {
try {
const result = await Promise.all(readVarsfnc);
_checkWorking(false);
if (result.length) {
let varsValueChanged = _updateVarsValue(result);
let varsValueChanged = await _updateVarsValue(result);
lastTimestampValue = new Date().getTime();
_emitValues(varsValue);
if (this.addDaq && !utils.isEmptyObject(varsValueChanged)) {
Expand All @@ -122,14 +123,14 @@ function S7client(_data, _logger, _events, _runtime) {
if (lastStatus !== 'connect-ok') {
_emitStatus('connect-ok');
}
}, reason => {
} catch (reason) {
if (reason && reason.stack) {
logger.error(`'${data.name}' _readVars error! ${reason.stack}`);
} else {
logger.error(`'${data.name}' _readVars error! ${reason}`);
}
_checkWorking(false);
});
};
} else {
_emitStatus('connect-busy');
}
Expand Down Expand Up @@ -220,7 +221,7 @@ function S7client(_data, _logger, _events, _runtime) {

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

/**
* Return the timestamp of last read tag operation on polling
* @returns
* @returns
*/
this.lastReadTimestamp = () => {
return lastTimestampValue;
}

/**
* Return the Daq settings of Tag
* @returns
* @returns
*/
this.getTagDaqSettings = (tagId) => {
return data.tags[tagId] ? data.tags[tagId].daq : null;
}

/**
* Set Daq settings of Tag
* @returns
* @returns
*/
this.setTagDaqSettings = (tagId, settings) => {
if (data.tags[tagId]) {
Expand Down Expand Up @@ -305,7 +306,7 @@ function S7client(_data, _logger, _events, _runtime) {

/**
* Update the Tags values read
* @param {*} vars
* @param {*} vars
*/
var _updateVarsValue = async (vars) => {
var someval = false;
Expand Down Expand Up @@ -392,15 +393,15 @@ function S7client(_data, _logger, _events, _runtime) {

/**
* Emit the PLC Tags values array { id: <name>, value: <value>, type: <type> }
* @param {*} values
* @param {*} values
*/
var _emitValues = function (values) {
events.emit('device-value:changed', { id: data.id, values: values });
}

/**
* Emit the PLC connection status
* @param {*} status
* @param {*} status
*/
var _emitStatus = function (status) {
lastStatus = status;
Expand All @@ -409,7 +410,7 @@ function S7client(_data, _logger, _events, _runtime) {

/**
* Used to manage the async connection and polling automation (that not overloading)
* @param {*} check
* @param {*} check
*/
var _checkWorking = function (check) {
if (check && working) {
Expand Down Expand Up @@ -455,7 +456,7 @@ function S7client(_data, _logger, _events, _runtime) {
vars.map(v => {
let value = null;
if (v.type === 'BOOL') {
// check the full byte and send all bit if there is a change
// check the full byte and send all bit if there is a change
value = datatypes['BYTE'].parser(res, v.Start - offset, -1);
} else {
value = datatypes[v.type].parser(res, v.Start - offset, v.bit);
Expand All @@ -472,7 +473,7 @@ function S7client(_data, _logger, _events, _runtime) {

/**
* Read multiple Vars
* @param {*} vars
* @param {*} vars
*/
var _readVars = function (vars) {
return new Promise((resolve, reject) => {
Expand All @@ -486,7 +487,7 @@ function S7client(_data, _logger, _events, _runtime) {
} else {
try {
if (v.type === 'BOOL') {
// check the full byte and send all bit if there is a change
// check the full byte and send all bit if there is a change
value = datatypes['BYTE'].parser(res[i].Data);//, v.Start, -1);
} else {
value = datatypes[v.type].parser(res[i].Data);
Expand Down Expand Up @@ -575,7 +576,7 @@ function S7client(_data, _logger, _events, _runtime) {
if (variable) {
var prefix = variable.substring(0, 2);
if (prefix === 'DB') {
// DB[n]"
// DB[n]"
var startpos = variable.indexOf('.');
var dbNum = parseInt(variable.substring(2, startpos));
if (dbNum >= 0) {
Expand Down Expand Up @@ -665,7 +666,7 @@ function S7client(_data, _logger, _events, _runtime) {

/**
* Return error message, from error code
* @param {*} s7err
* @param {*} s7err
*/
var _getErr = function (s7err) {
if (Array.isArray(s7err)) return new Error('Errors: ' + s7err.join('; '));
Expand Down

0 comments on commit 650e285

Please sign in to comment.