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 { createLog } from "../../../../logger/logger.js";
|
||||
import { getMac } from "../../../utils/getMachineId.js";
|
||||
import { labelingProcess } from "../../labeling/labelProcess.js";
|
||||
|
||||
@@ -23,7 +24,7 @@ export const createPlcMonitor = (config: any) => {
|
||||
cfg.slot,
|
||||
cfg.rpi,
|
||||
true,
|
||||
cfg.retrySP || 3000
|
||||
cfg.retrySP || 3000,
|
||||
);
|
||||
|
||||
plc.connect();
|
||||
@@ -51,18 +52,28 @@ export const createPlcMonitor = (config: any) => {
|
||||
if (s.lastDisconnectedAt) {
|
||||
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", () => {
|
||||
const s = stats[cfg.id];
|
||||
s.connected = false;
|
||||
s.lastDisconnectedAt = nowISO();
|
||||
console.log(`[${cfg.id}] Disconnected`);
|
||||
createLog("info", "zechette", "ocp", `[${cfg.id}] Disconnected`);
|
||||
});
|
||||
|
||||
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) => {
|
||||
@@ -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
|
||||
printerName: cfg.id,
|
||||
};
|
||||
createLog(
|
||||
"info",
|
||||
"zechette",
|
||||
"ocp",
|
||||
`Date being sent to labeler: ${JSON.stringify(zechette)}`,
|
||||
);
|
||||
labelingProcess({ zechette: zechette });
|
||||
}, 1000);
|
||||
}
|
||||
@@ -143,8 +160,7 @@ export const createPlcMonitor = (config: any) => {
|
||||
if (s.connected && s.lastConnectedAt) {
|
||||
uptimeMs = Date.now() - new Date(s.lastConnectedAt).getTime();
|
||||
} else if (!s.connected && s.lastDisconnectedAt) {
|
||||
downtimeMs =
|
||||
Date.now() - new Date(s.lastDisconnectedAt).getTime();
|
||||
downtimeMs = Date.now() - new Date(s.lastDisconnectedAt).getTime();
|
||||
}
|
||||
result[id] = { ...s, uptimeMs, downtimeMs };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user