refactor(plc connection zechetti): added in more logging due to a weird issue with line 7 not sendin
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { ControllerManager } from "st-ethernet-ip";
|
import { ControllerManager } from "st-ethernet-ip";
|
||||||
|
import { createLog } from "../../../../logger/logger.js";
|
||||||
import { getMac } from "../../../utils/getMachineId.js";
|
import { getMac } from "../../../utils/getMachineId.js";
|
||||||
import { labelingProcess } from "../../labeling/labelProcess.js";
|
import { labelingProcess } from "../../labeling/labelProcess.js";
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ export const createPlcMonitor = (config: any) => {
|
|||||||
cfg.slot,
|
cfg.slot,
|
||||||
cfg.rpi,
|
cfg.rpi,
|
||||||
true,
|
true,
|
||||||
cfg.retrySP || 3000
|
cfg.retrySP || 3000,
|
||||||
);
|
);
|
||||||
|
|
||||||
plc.connect();
|
plc.connect();
|
||||||
@@ -51,18 +52,28 @@ export const createPlcMonitor = (config: any) => {
|
|||||||
if (s.lastDisconnectedAt) {
|
if (s.lastDisconnectedAt) {
|
||||||
s.reconnectCount++;
|
s.reconnectCount++;
|
||||||
}
|
}
|
||||||
console.log(`[${cfg.id}] Connected @ ${cfg.ip}:${cfg.slot}`);
|
createLog(
|
||||||
|
"info",
|
||||||
|
"zechette",
|
||||||
|
"ocp",
|
||||||
|
`[${cfg.id}] Connected @ ${cfg.ip}:${cfg.slot}`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
plc.on("Disconnected", () => {
|
plc.on("Disconnected", () => {
|
||||||
const s = stats[cfg.id];
|
const s = stats[cfg.id];
|
||||||
s.connected = false;
|
s.connected = false;
|
||||||
s.lastDisconnectedAt = nowISO();
|
s.lastDisconnectedAt = nowISO();
|
||||||
console.log(`[${cfg.id}] Disconnected`);
|
createLog("info", "zechette", "ocp", `[${cfg.id}] Disconnected`);
|
||||||
});
|
});
|
||||||
|
|
||||||
plc.on("error", (err: any) => {
|
plc.on("error", (err: any) => {
|
||||||
console.error(`[${cfg.id}] Error:`, err.message);
|
createLog(
|
||||||
|
"error",
|
||||||
|
"zechette",
|
||||||
|
"ocp",
|
||||||
|
`[${cfg.id}] Error: ${JSON.stringify(err.message)}`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
plc.on("TagChanged", async (tag: any, prevVal: any) => {
|
plc.on("TagChanged", async (tag: any, prevVal: any) => {
|
||||||
@@ -104,6 +115,12 @@ export const createPlcMonitor = (config: any) => {
|
|||||||
printer: cfg.printerId, // this is the id of the zechetti 2 to print we should move this to the db
|
printer: cfg.printerId, // this is the id of the zechetti 2 to print we should move this to the db
|
||||||
printerName: cfg.id,
|
printerName: cfg.id,
|
||||||
};
|
};
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"zechette",
|
||||||
|
"ocp",
|
||||||
|
`Date being sent to labeler: ${JSON.stringify(zechette)}`,
|
||||||
|
);
|
||||||
labelingProcess({ zechette: zechette });
|
labelingProcess({ zechette: zechette });
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
@@ -143,8 +160,7 @@ export const createPlcMonitor = (config: any) => {
|
|||||||
if (s.connected && s.lastConnectedAt) {
|
if (s.connected && s.lastConnectedAt) {
|
||||||
uptimeMs = Date.now() - new Date(s.lastConnectedAt).getTime();
|
uptimeMs = Date.now() - new Date(s.lastConnectedAt).getTime();
|
||||||
} else if (!s.connected && s.lastDisconnectedAt) {
|
} else if (!s.connected && s.lastDisconnectedAt) {
|
||||||
downtimeMs =
|
downtimeMs = Date.now() - new Date(s.lastDisconnectedAt).getTime();
|
||||||
Date.now() - new Date(s.lastDisconnectedAt).getTime();
|
|
||||||
}
|
}
|
||||||
result[id] = { ...s, uptimeMs, downtimeMs };
|
result[id] = { ...s, uptimeMs, downtimeMs };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user