plc-state-sanitizer

This modules sanitizes a composite of boolean plc signals that represent a state into one single variable.

Usage no npm install needed!

<script type="module">
  import plcStateSanitizer from 'https://cdn.skypack.dev/plc-state-sanitizer';
</script>

README

PLC state sanitizer

pipeline status coverage report

This modules sanitizes a composite of boolean plc signals that represent a state into one single variable. It enables the developer to register for state changes by providing an event emitter.

Usage

let plcSignalSanitizer = require('plc-signal-sanitizer');

let trafficLights = new plcSignalSanitizer(["red", "green"]);

trafficLights.eventEmitter("sanitized", (state) => {
    console.log("received new state: " + state);
})

trafficLights.changePlcSignal("red", true);
console.log(trafficLights.currentState;   // prints 'red'

trafficLights.changePlcSignal("red", false);
console.log(trafficLights.currentState);  // prints '😱 undefined'
console.log(trafficLights.lastGoodState); // prints 'red'

trafficLights.changePlcSignal("green", true);
console.log(trafficLights.currentState);  // prints 'green'