feat(lstv2): added zechetti stuff in so we can print :D

This commit is contained in:
2025-09-25 12:28:45 -05:00
parent e706e78d43
commit 1c40b6aa82
4 changed files with 66 additions and 45 deletions

View File

@@ -1,11 +1,6 @@
import { ControllerManager } from "st-ethernet-ip";
import { getMac } from "./getMachineId.js";
import { format } from "date-fns-tz";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getCurrentLabel } from "../../sqlServer/querys/ocp/getLabel.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { createLog } from "../../logger/logger.js";
import { getMac } from "../../../utils/getMachineId.js";
import { labelingProcess } from "../../labeling/labelProcess.js";
export const createPlcMonitor = (config: any) => {
let cm: any;
@@ -77,34 +72,39 @@ export const createPlcMonitor = (config: any) => {
setTimeout(async () => {
if (tag.value === 0) return;
const macId = await getMac(tag.value);
console.log(macId);
const { data, error } = (await tryCatch(
query(
getCurrentLabel
.replace(
"[macId]",
macId[0]?.HumanReadableId
)
.replace(
"[time]",
format(time, "yyyy-MM-dd HH:mm")
),
"Current label data"
)
)) as any;
// const { data, error } = (await tryCatch(
// query(
// getCurrentLabel
// .replace(
// "[macId]",
// macId[0]?.HumanReadableId
// )
// .replace(
// "[time]",
// format(time, "yyyy-MM-dd HH:mm")
// ),
// "Current label data"
// )
// )) as any;
createLog(
"info",
"zechettii",
"zechettii",
`${format(time, "yyyy-MM-dd HH:mm")} [${cfg.id}] ${
tag.name
}: ${prevVal} -> ${
tag.value
}, the running number is ${
error ? null : data.data[0]?.LfdNr
}}`
);
// createLog(
// "info",
// "zechettii",
// "zechettii",
// `${format(time, "yyyy-MM-dd HH:mm")} [${cfg.id}] ${
// tag.name
// }: ${prevVal} -> ${
// tag.value
// }, the running number is ${
// error ? null : data.data[0]?.LfdNr
// }}`
// );
const zechette = {
line: tag.value.toString(),
printer: cfg.printerId, // this is the id of the zechetti 2 to print we should move this to the db
printerName: cfg.id,
};
labelingProcess({ zechette: zechette });
}, 1000);
}
});

View File

@@ -1,20 +1,22 @@
import { createPlcMonitor } from "../../../utils/plcController.js";
import { createPlcMonitor } from "./plcController.js";
export const zechettiConnect = () => {
const config: any = {
controllers: [
{
id: "Z1",
id: "Zecchetti_1",
ip: "192.168.193.97",
slot: 0,
rpi: 250,
printerId: 22, // grabbed from 2.0
tags: ["N7[0]"],
},
{
id: "Z2",
id: "Zecchetti_2",
ip: "192.168.193.111",
slot: 0,
rpi: 100,
printerId: 23,
tags: ["N8[0]"],
},
],

View File

@@ -25,7 +25,7 @@ import labelRatio from "./routes/labeling/getLabelRatio.js";
import resetRatio from "./routes/labeling/resetLabelRatio.js";
import materialTransferLot from "./routes/materials/lotTransfer.js";
import pendingTransfers from "./routes/materials/currentPending.js";
import { createPlcMonitor } from "./utils/plcController.js";
import { createPlcMonitor } from "./controller/specialProcesses/zechettis/plcController.js";
import { zechettiConnect } from "./controller/specialProcesses/zechettis/zechettiConnect.js";
const app = new OpenAPIHono();

View File

@@ -55,13 +55,32 @@ MaterialHumanReadableId
,case when cp.Pieces >= 0.001 then (lot.TotalProducedLoadingUnits+1) * cp.Pieces else
(a.Weight *((case when cp.Percentage is null then 80 else cp.Percentage end) / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 end totalNeeded
,case when IsMainMaterial = 1 then
case when (case when x.ProvidedAmount <> 0
then x.ProvidedAmount else x.EffectiveConsumption end) >
(case when cp.Pieces >= 0.001 then (lot.TotalProducedQuantity+1) * cp.Pieces else
(a.Weight *((case when cp.Percentage is null then 80 else cp.Percentage end) / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 end)
then 'mmGood'
else 'noMM' end else null end as noMMShortage
,CASE
WHEN IsMainMaterial = 1 THEN
CASE
WHEN
(CASE
WHEN x.ProvidedAmount > 0
THEN x.ProvidedAmount
ELSE x.EffectiveConsumption
END)
>
(CASE
WHEN cp.Pieces >= 0.001
THEN (lot.TotalProducedQuantity + 1) * cp.Pieces
ELSE
(a.Weight *
(CASE
WHEN cp.Percentage IS NULL THEN 80
ELSE cp.Percentage
END) / 100
) * (lot.TotalProducedQuantity + 1) / 1000
END)
THEN 'mmGood'
ELSE 'noMM'
END
ELSE NULL
END AS noMMShortage
-- pkg check auto
,case when pkg.QuantityPosition is null then null else