diff --git a/modules/wamo/src/wamo.processmodule.module.ts b/modules/wamo/src/wamo.processmodule.module.ts index 8ca3846..095a75f 100644 --- a/modules/wamo/src/wamo.processmodule.module.ts +++ b/modules/wamo/src/wamo.processmodule.module.ts @@ -2,7 +2,7 @@ * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-03-02 11:37:50 - * @modify date 2021-01-05 15:11:04 + * @modify date 2021-03-18 14:53:41 * @desc [description] */ @@ -11,6 +11,7 @@ import { exportMethod, exportProperty } from "../../../lib/decorators/moduleDecorators"; +import { copy } from "../../../lib/helpers/objectMethods"; import { getNopeLogger } from "../../../lib/logger/getLogger"; import { InjectableNopeBaseModule } from "../../../lib/module/BaseModule.injectable"; import { NopeObservable } from "../../../lib/observables/nopeObservable"; @@ -180,6 +181,18 @@ export class WaMOProcessModule type: "BeckhoffPlc" }); + // Change the Light of the Connector based on the + // Connector. + // + // The following Colors are used: + // * white = active / busy + // * red = error + // * green = no error and done + // * blue = no signal present + this.connector.subscribe(value => { + _this._adaptLightbar(value); + }); + // Subscribe to the Initialized PLC. this._plc.initialized.subscribe((rdy) => { // Only if the PLC is connected => Perform an update @@ -196,8 +209,9 @@ export class WaMOProcessModule _this._mqtt .subscribe( "+/processModule/connectorReplica", - (value) => { + async (topic, value) => { _this.connector.setContent(value); + }, { format: "json" @@ -211,17 +225,19 @@ export class WaMOProcessModule _this._plc.dynamicInstanceProperties[ "input.GVL_IOS." + dict[key] ].subscribe((value) => { - _this.connector.getContent()[key] = value; - _this.connector.forcePublish(); + const connector = _this.connector.getContent(); + connector[key] = value; + _this.connector.setContent(copy(connector)); }); // Publish on MQTT. _this._mqtt .subscribe( `+/processModule/connectorReplica/${key}`, - (value) => { - _this.connector.getContent()[key] = value; - _this.connector.forcePublish(); + async (topic, value) => { + const connector = _this.connector.getContent(); + connector[key] = value; + _this.connector.setContent(copy(connector)); }, { format: "json" @@ -278,4 +294,30 @@ export class WaMOProcessModule await this.connected.waitFor((value) => value === true); } } + + /** + * Helper Function to adapt the Light, based on connector Value. + * + * white = active / busy + * red = error + * green = no error and done + * blue = no signal present + * + * @protected + * @param {IConnectorReplicaProcessModuleToBaseModule} value + * @memberof WaMOProcessModule + */ + protected _adaptLightbar(value: IConnectorReplicaProcessModuleToBaseModule): void{ + if (value.active){ + this._plc.dynamicInstanceProperties["output.GVL_IOS.bOutputLightSegment02Color"].setContent("white"); + } + else if (value.result && value.error){ + this._plc.dynamicInstanceProperties["output.GVL_IOS.bOutputLightSegment02Color"].setContent("red"); + } + else if (value.result && !value.error){ + this._plc.dynamicInstanceProperties["output.GVL_IOS.bOutputLightSegment02Color"].setContent("green"); + } else { + this._plc.dynamicInstanceProperties["output.GVL_IOS.bOutputLightSegment02Color"].setContent("blue"); + } + } }