From 7fe7a0fdcf94e50ff69e8150df5c53da9582fcd7 Mon Sep 17 00:00:00 2001 From: grigals <42711835+grigals@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:48:47 +0000 Subject: [PATCH 1/2] Force await on read as now it returns empty promises --- lib/devices/S7.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/devices/S7.ts b/lib/devices/S7.ts index b3c365a..c379804 100644 --- a/lib/devices/S7.ts +++ b/lib/devices/S7.ts @@ -87,10 +87,10 @@ export class S7Connection extends DeviceConnection { * @param {array} metrics Array of metric objects to read to * @returns {array} Old metric values (for RbE checking) */ - readMetrics(metrics: Metrics, payloadFormat?: string,) { + async readMetrics(metrics: Metrics, payloadFormat?: string,) { const changedMetrics: sparkplugMetric[] = []; // Tell S7 to update metric values - let newVals = this.#itemGroup.readAllItems(); // name: value + let newVals = await this.#itemGroup.readAllItems(); // name: value this.emit('data', newVals, false); } From 4060ceda7dbb15edf24a33763f1b5d676ed59ff8 Mon Sep 17 00:00:00 2001 From: grigals <42711835+grigals@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:49:32 +0000 Subject: [PATCH 2/2] Make write and close use await as well as per lib. --- lib/devices/S7.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/devices/S7.ts b/lib/devices/S7.ts index c379804..efb7669 100644 --- a/lib/devices/S7.ts +++ b/lib/devices/S7.ts @@ -98,7 +98,7 @@ export class S7Connection extends DeviceConnection { * Writes metric values to the PLC * @param {array} metrics Array of metric objects to write to the PLC */ - writeMetrics(metrics: Metrics) { + async writeMetrics(metrics: Metrics) { // This doesn't seem to work for Ixxx value writes // Untested with other writes at present @@ -116,14 +116,14 @@ export class S7Connection extends DeviceConnection { // Notify user log(`Writing ${values} to ${addrs}`); // Write metric values - this.#itemGroup.writeItems(addrs, values); + await this.#itemGroup.writeItems(addrs, values); } } /** * Close connection and tidy up */ - close() { + async close() { // Clear the variable list this.#vars = {}; // Destroy the metric item group, if it exists @@ -131,7 +131,7 @@ export class S7Connection extends DeviceConnection { this.#itemGroup.destroy(); } // Close the PLC connection - this.#s7Conn.disconnect(); + await this.#s7Conn.disconnect(); } }