Gathering detailed insights and metrics for tlsupportfunctions
Gathering detailed insights and metrics for tlsupportfunctions
Gathering detailed insights and metrics for tlsupportfunctions
Gathering detailed insights and metrics for tlsupportfunctions
npm install tlsupportfunctions
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
3
This package includes frequently used functions used by the Transformation Layer (node red). Every aspect of the package can function on its own though the use case is highly specific and it is not recommended to use this package for anything but the project it was created for. It can however be used as an inspiration for similar projects.
In your user directory, go to ".node-red". Install package with:
npm i tlsupportfunctions
In the same directory, find "settings.js". Locate the object functionGlobalContext
and add the entry
1"tlsupportfunctions": require('tlsupportfunctions')
to the object. Now the package can be used in any function node. At the beginning of the function node, add the line
1const tls = global.get("tlsupportfunctions");
The functions implemented in the package can be used with the declared constant, for example
1tls.calculateCounterIncrement(10, 8);
Calculates a counter increment given the current counter value (counter) and previous counter value (lastCounter).
Parameters:
counter
: current counter value (e.g. 10)lastCounter
: previous counter value (e.g. 8)checkRange
(optional, default 15): detection range for overflows, should always be larger than normal counter increases but only as big as necessaryrange
(optional): value range of the counter, calculated as max + abs(min) (e.g. 65535)min
(optional): the lowest possible value of the counter, usually 0 or a negative power of 2 (e.g. -32768)reset
(optional): the value the counter takes when manually reset (e.g. 0)Returns a specifically formatted object.
Parameters:
msg
: the node red message objectincrement
: the counter increment (e.g. 2)Returns a specifically formatted object.
Parameters:
msg
: the node red message objectfaultCodes
(optional, default []): array containing fault codes of the machineUpdated 2023-03-10
Prepares a message for later use.
Parameters:
msg
: the node red message objectdynamic_line_data
: dynamic line data stored in the flowlineName
: line name stored in environmentf_metadata
: metadata stored in the flowone_time_cyclics
: cyclics data stored in the flowcontexualizer_func
: Contextualizer to be used (see below)messageintervall_in_s
: For non-time-synced OPC servers (metadata isTimeSynced=false), this is the capture time frame on the OPC forwarder (Default is 10 seconds)The function returns the following object:
1{ 2 success: false, 3 error_text: false, 4 flow_dynamic_line_data: false, 5 flow_one_time_cyclics: false, 6 returnMsg: false 7}
Example usage:
1let ppmsg = tls.messagePreprocessor( msg, 2 flow.get("dynamic_line_data", "file"), 3 env.get("LineName"), 4 flow.get("metadata"), 5 flow.get("one_time_cyclics")); 6if(ppmsg.success){ 7 msg = ppmsg.returnMsg; 8 flow.set("dynamic_line_data", ppmsg.flow_dynamic_line_data); 9 flow.set("one_time_cyclics", ppmsg.flow_one_time_cyclics); 10} else { 11 node.error(ppmsg.error_text); 12}
Converts and formats incoming messages.
Parameters:
msg
: the node red message objectThe transfomation layer needs some context information of the data to be processes. Therefore the messagePreprocessor
is enabled to add a context to each individual tag message.
The messagePreprocessor
expects a contextualizer to be a void function:
1(tag, machine_metadata) => { /* adding the context to the tag */ }
Contectualizers...
Context
on the tag message.InvalidTagName
to false
. Invalid tags will not be processed by the transformation layer.The Context
get extended with following properties:
Category
: To categorize the tag in groups of similar concerns, e.g. status, faults, counters, etc.Parameter
: Semantical name of the tagAttribute
: Optional context information for further differentiation of a parameterThis version of the tlsupportfunctions
provide two predefined contextualizers:
This contextualizer reads the context information from the tag.id
based on the local standard.
It sets the tag as valid if Category
and Parameter
are set.
This contextualizer does a lookup in the machine_metadata
property TagWhitelistAndContext
. It provides a white list of supported tags with each's context values:
1 TagWhitelistAndContext: { 2 "This.is.tag.a": { "Category": "MSTATE", "Parameter": "CurrentState", "Attribute": "PDA" }, 3 "This.is.tag.b": { "Category": "MFAULT", "Parameter": "MachineStop", "Attribute": "Code" }, 4 "This.is.tag.c": { "Category": "COUNTER", "Parameter": "Good" } 5 }
It sets the tag as valid if the tag.id
exists as object in the TagWhitelistAndContext
and provides context details for Category
and Parameter
.
These handler are providing standard functionality to maintain the a machiens fault code array base on the technical representation of machine faults.
The fault codes are maintained in an array of objects with the properties
code
: storing the numeric value of the machines fault codet
: the timestamp as provided by the connected OPC server in milliseconds1 faultArray = [ 2 {code: 1234, t : 1679392604015}, 3 {code: 815, t : 1679350658430}, 4 ... 5 ];
Returning an updated fault code array, not chaning the provided array. A value of zero empties the array, any other value gets stored in code
along with t
the timestamp or replaces the existing value.
1 let result = update_fault_codes_by_numeric_tag_value(fault_codes, preprocessed_tag);
Returning an updated fault code array, not chaning the provided array. A value of zero gets ignored, any other value gets added (pushed) with code
and t
the timestamp to the resulting array.
1 let result = update_fault_codes_by_adding_numeric_tag_value(fault_codes, preprocessed_tag);
Returning an updated fault code array, not chaning the provided array. The tag's context attribute provides the related fault code. Any numeric tag value greater than zero indicated the fault is set active, otherwise the fault is set inactive. Active fault codes gets added to the 'fault_codes' array if not already existing, inactive fault code gets removed from the array if existing.
1 let result = update_fault_codes_by_tag_value_boolean(fault_codes, preprocessed_tag);
(this implementation is based on a Siemens PLC representation)
The tag's context attribute provides details about the 1 up to 4 bytes sized tag value, including the start and end value of the bit rang, and optionally a mask to filter out non fault relevant bits that must be ignored. Example: 0-7-254
All masked bit gets updated in the fault code array, for a set bit (active fault) the code get added to the fault code array, an unset bit (inactive fault), the code gets removed. This happens in decending order! That means the highest value gets updates first.
1 let result = update_fault_codes_by_tag_value_bitwise_siemens(fault_codes, preprocessed_tag);
there are automated tests prepared to have a technical secification to check any code changes against.
It utilizes the mocha test framework and it is recommended to install the "Mocha Test Explorer" in VSCode for interacice code testing during development.
use the following statemnt to install all development dependencies on the development computer
npm install --save-dev
This installs the following "devDependencies" as registered in the package.json
file:
follow this sequence to deploy the tlsupportfunction to NPM:
npm version patch
npm publish
No vulnerabilities found.
No security vulnerabilities found.