refactor(ocp): lots of work for rfid and dyco contorl
This commit is contained in:
@@ -10,7 +10,9 @@ export const bookInLabel = async (data: any) => {
|
|||||||
// update sscc so we can book in
|
// update sscc so we can book in
|
||||||
const SSCC = data.SSCC.slice(2);
|
const SSCC = data.SSCC.slice(2);
|
||||||
// api url
|
// api url
|
||||||
const url = await prodEndpointCreation("public/v1.0/Warehousing/BookIn");
|
const url = await prodEndpointCreation(
|
||||||
|
"/public/v1.1/Manufacturing/ProductionControlling/BookIn"
|
||||||
|
);
|
||||||
|
|
||||||
// create bookin
|
// create bookin
|
||||||
const newBookin = {
|
const newBookin = {
|
||||||
@@ -26,12 +28,12 @@ export const bookInLabel = async (data: any) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.data.Result !== 0) {
|
if (res.status != 200) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"labeling",
|
"labeling",
|
||||||
"ocp",
|
"ocp",
|
||||||
`${data.printer.name}, Error:${res.data.Message}`
|
`${data.printer[0].name}, Error:${res.data}`
|
||||||
);
|
);
|
||||||
//printerUpdate(data.printer, 7, "Error while booking in.");
|
//printerUpdate(data.printer, 7, "Error while booking in.");
|
||||||
|
|
||||||
@@ -44,7 +46,7 @@ export const bookInLabel = async (data: any) => {
|
|||||||
|
|
||||||
// update the label.
|
// update the label.
|
||||||
try {
|
try {
|
||||||
await db
|
const booked = await db
|
||||||
.update(prodlabels)
|
.update(prodlabels)
|
||||||
.set({
|
.set({
|
||||||
status: "Booked in",
|
status: "Booked in",
|
||||||
@@ -52,7 +54,22 @@ export const bookInLabel = async (data: any) => {
|
|||||||
})
|
})
|
||||||
.where(
|
.where(
|
||||||
eq(prodlabels.runningNr, parseInt(data.SSCC.slice(10, -1)))
|
eq(prodlabels.runningNr, parseInt(data.SSCC.slice(10, -1)))
|
||||||
);
|
)
|
||||||
|
.returning({ runningNr: prodlabels.runningNr });
|
||||||
|
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"labeling",
|
||||||
|
"ocp",
|
||||||
|
`${booked[0].runningNr} , was just booked in.`
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `${parseInt(
|
||||||
|
data.SSCC.slice(10, -1)
|
||||||
|
)}, was just booked in`,
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
@@ -61,24 +78,12 @@ export const bookInLabel = async (data: any) => {
|
|||||||
`Error creating new runningNumber in the DB.`
|
`Error creating new runningNumber in the DB.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// label was booked in
|
|
||||||
createLog(
|
|
||||||
"info",
|
|
||||||
"labeling",
|
|
||||||
"ocp",
|
|
||||||
`${parseInt(data.SSCC.slice(10, -1))}, was just booked in`
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
message: `${parseInt(data.SSCC.slice(10, -1))}, was just booked in`,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"labeling",
|
"labeling",
|
||||||
"ocp",
|
"ocp",
|
||||||
`${data.printer.name}, "Error: ${error}`
|
`${data.printer[0].name}, "Error: ${error}`
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export const createLabel = async (data: any, userPrinted: any) => {
|
|||||||
const plantToken = settingsData.filter((n) => n.name === "plantToken");
|
const plantToken = settingsData.filter((n) => n.name === "plantToken");
|
||||||
const newLabel = {
|
const newLabel = {
|
||||||
scannerId: 99,
|
scannerId: 99,
|
||||||
lotNr: data.LOT,
|
lotNr: data.lot,
|
||||||
machineId: data.machineID,
|
machineId: data.machineID,
|
||||||
printerId: data.printerID,
|
printerId: data.printerID,
|
||||||
//layoutId: cartonCustomers.includes(data.CustomerId.toString()) ? data.cartonLabel : data.palletLabel,
|
//layoutId: cartonCustomers.includes(data.CustomerId.toString()) ? data.cartonLabel : data.palletLabel,
|
||||||
@@ -87,14 +87,24 @@ export const createLabel = async (data: any, userPrinted: any) => {
|
|||||||
let newlabel = res.data;
|
let newlabel = res.data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await db.insert(prodlabels).values({
|
const insertLabel = await db
|
||||||
printerID: parseInt(printer[0]?.humanReadableId!, 10),
|
.insert(prodlabels)
|
||||||
runningNr: parseInt(newlabel.SSCC.slice(10, -1)),
|
.values({
|
||||||
printerName: printer[0].name.toLowerCase(),
|
printerID: parseInt(printer[0]?.humanReadableId!, 10),
|
||||||
line: data.MachineLocation,
|
runningNr: parseInt(newlabel.SSCC.slice(10, -1)),
|
||||||
status: "printed",
|
printerName: printer[0].name.toLowerCase(),
|
||||||
add_user: userPrinted || "LST_System",
|
line: data.MachineLocation,
|
||||||
});
|
status: "printed",
|
||||||
|
add_user: userPrinted || "LST_System",
|
||||||
|
})
|
||||||
|
.returning({ runningNr: prodlabels.runningNr });
|
||||||
|
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"labeling",
|
||||||
|
"ocp",
|
||||||
|
`${insertLabel[0]?.runningNr} was just inserted into the db.`
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
@@ -119,7 +129,7 @@ export const createLabel = async (data: any, userPrinted: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// check if we can remove labels or not
|
// check if we can remove labels or not
|
||||||
deleteLabels();
|
//deleteLabels();
|
||||||
return { sucess: true, message: "Label created", data: returnData }; // returning label data to be able to book in if active
|
return { sucess: true, message: "Label created", data: returnData }; // returning label data to be able to book in if active
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog(
|
createLog(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { desc, lte, sql } from "drizzle-orm";
|
import { desc, gte, lte, sql } from "drizzle-orm";
|
||||||
import { db } from "../../../../../database/dbclient.js";
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
@@ -8,7 +8,7 @@ export const getLabels = async (hours: string) => {
|
|||||||
.select()
|
.select()
|
||||||
.from(prodlabels)
|
.from(prodlabels)
|
||||||
.where(
|
.where(
|
||||||
lte(
|
gte(
|
||||||
prodlabels.upd_date,
|
prodlabels.upd_date,
|
||||||
sql.raw(`NOW() - INTERVAL '${hours} hours'`)
|
sql.raw(`NOW() - INTERVAL '${hours} hours'`)
|
||||||
)
|
)
|
||||||
@@ -27,6 +27,7 @@ export const getLabels = async (hours: string) => {
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Current labels order by upd_Date.",
|
message: "Current labels order by upd_Date.",
|
||||||
|
count: labelInfo.length,
|
||||||
data: labelInfo,
|
data: labelInfo,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,9 +50,10 @@ export const labelingProcess = async ({
|
|||||||
// if we got a line passed over we need to get the machine id from this.
|
// if we got a line passed over we need to get the machine id from this.
|
||||||
if (line) {
|
if (line) {
|
||||||
const macId = await getMac(line);
|
const macId = await getMac(line);
|
||||||
|
|
||||||
// filter out the lot for the line
|
// filter out the lot for the line
|
||||||
filteredLot = lots.data.filter((l: any) => l.machineId === macId);
|
filteredLot = lots.data.filter(
|
||||||
|
(l: any) => l.MachineID === macId[0].HumanReadableId
|
||||||
|
);
|
||||||
|
|
||||||
if (filteredLot.length === 0) {
|
if (filteredLot.length === 0) {
|
||||||
createLog(
|
createLog(
|
||||||
@@ -160,7 +161,10 @@ export const labelingProcess = async ({
|
|||||||
`Main material is not prepaired for lot ${filteredLot[0].lot}`
|
`Main material is not prepaired for lot ${filteredLot[0].lot}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return {
|
||||||
|
success: false,
|
||||||
|
message: `Main material is not prepaired for lot ${filteredLot[0].lot}`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// comment only but will check for color
|
// comment only but will check for color
|
||||||
@@ -198,16 +202,19 @@ export const labelingProcess = async ({
|
|||||||
"ocp",
|
"ocp",
|
||||||
`Prolink does not match for ${filteredLot[0].MachineDescription}`
|
`Prolink does not match for ${filteredLot[0].MachineDescription}`
|
||||||
);
|
);
|
||||||
return;
|
return {
|
||||||
|
success: false,
|
||||||
|
message: `Prolink does not match for ${filteredLot[0].MachineDescription}`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
createLog("info", "labeling", "ocp", `Is prolink good? ${prolink}`);
|
createLog("info", "labeling", "ocp", `Is prolink good? ${prolink}`);
|
||||||
|
|
||||||
// create the label
|
// create the label
|
||||||
const label = await createLabel(filteredLot[0], userPrinted);
|
const label = await createLabel(filteredLot[0], userPrinted);
|
||||||
|
|
||||||
if (!label.success) {
|
// if (!label.success) {
|
||||||
return { sucess: false, message: label.message, data: label.data };
|
// return { sucess: false, message: label.message, data: label.data };
|
||||||
}
|
// }
|
||||||
|
|
||||||
// send over to be booked in if we can do it.
|
// send over to be booked in if we can do it.
|
||||||
const bookin = settingData.filter((s) => s.name === "bookin");
|
const bookin = settingData.filter((s) => s.name === "bookin");
|
||||||
|
|||||||
52
server/services/ocp/controller/labeling/manualLabelLog.ts
Normal file
52
server/services/ocp/controller/labeling/manualLabelLog.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
|
import { manualPrinting } from "../../../../../database/schema/ocpManualPrint.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { manualTag } from "../../../rfid/controller/tags/manualTag.js";
|
||||||
|
import { labelingProcess } from "./labelProcess.js";
|
||||||
|
|
||||||
|
export const manualPrint = async (manualPrint: any) => {
|
||||||
|
/**
|
||||||
|
* add the reason we did a manual print.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const manualPrintData = {
|
||||||
|
line: manualPrint.line,
|
||||||
|
printReason: manualPrint.printReason,
|
||||||
|
initials: manualPrint.initials,
|
||||||
|
additionalComments: manualPrint?.additionalComments,
|
||||||
|
add_user: "lst",
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data, error } = await tryCatch(
|
||||||
|
db.insert(manualPrinting).values(manualPrintData).returning({
|
||||||
|
line: manualPrinting.line,
|
||||||
|
printReason: manualPrinting.printReason,
|
||||||
|
initials: manualPrinting.initials,
|
||||||
|
additionalComments: manualPrinting?.additionalComments,
|
||||||
|
add_user: manualPrinting.add_user,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "There was an error posting the manualPrintData",
|
||||||
|
data: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let label = await labelingProcess({ line: manualPrint.line });
|
||||||
|
|
||||||
|
if (manualPrint.rfidTag) {
|
||||||
|
manualTag(
|
||||||
|
manualPrint.rfidTag,
|
||||||
|
"wrapper1",
|
||||||
|
parseInt(label.data.SSCC.slice(10, -1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Log Entered label will be coming soon.",
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -43,8 +43,6 @@ export const prolinkCheck = async (lot: any) => {
|
|||||||
// run the query
|
// run the query
|
||||||
try {
|
try {
|
||||||
const prolink = await query(prolinkQuery, "Prolink Checks");
|
const prolink = await query(prolinkQuery, "Prolink Checks");
|
||||||
|
|
||||||
//console.log(lot);
|
|
||||||
// filter out the lot
|
// filter out the lot
|
||||||
const filterdLot = prolink.filter(
|
const filterdLot = prolink.filter(
|
||||||
(p: any) => p.AlplaLabelOnline === lot
|
(p: any) => p.AlplaLabelOnline === lot
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
import { db } from "../../../../database/dbclient.js";
|
|
||||||
import { manualPrinting } from "../../../../database/schema/ocpManualPrint.js";
|
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
|
||||||
|
|
||||||
export const manualPrint = async (manualPrint: any) => {
|
|
||||||
/**
|
|
||||||
* add the reason we did a manual print.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const manualPrintData = {
|
|
||||||
line: manualPrint.line,
|
|
||||||
printReason: manualPrint.printReason,
|
|
||||||
initials: manualPrint.initials,
|
|
||||||
additionalComments: manualPrint?.additionalComments,
|
|
||||||
add_user: "lst",
|
|
||||||
};
|
|
||||||
|
|
||||||
const { data, error } = await tryCatch(
|
|
||||||
db
|
|
||||||
.insert(manualPrinting)
|
|
||||||
.values(manualPrintData)
|
|
||||||
.returning({
|
|
||||||
line: manualPrinting.line,
|
|
||||||
printReason: manualPrinting.printReason,
|
|
||||||
initials: manualPrinting.initials,
|
|
||||||
additionalComments: manualPrinting?.additionalComments,
|
|
||||||
add_user: manualPrinting.add_user,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: "There was an error posting the manualPrintData",
|
|
||||||
data: error,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
message: "There was an error posting the manualPrintData",
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -2,13 +2,14 @@ import { Controller, Tag } from "st-ethernet-ip";
|
|||||||
import { createLog } from "../../../../logger/logger.js";
|
import { createLog } from "../../../../logger/logger.js";
|
||||||
import { labelerTagRead } from "./plcTags/labelerTag.js";
|
import { labelerTagRead } from "./plcTags/labelerTag.js";
|
||||||
import { palletSendTag } from "./plcTags/palletSendTag.js";
|
import { palletSendTag } from "./plcTags/palletSendTag.js";
|
||||||
|
import { strapperFaults } from "./plcTags/strapperFault.js";
|
||||||
|
|
||||||
let PLC = new Controller();
|
let PLC = new Controller();
|
||||||
let isDycoRunning = false;
|
let isDycoRunning = false;
|
||||||
|
|
||||||
// PLC address
|
// PLC address
|
||||||
let plcAddress = "10.44.5.4";
|
let plcAddress = "10.44.5.4";
|
||||||
|
let isReading = false;
|
||||||
// Initialize the interval variable outside the function
|
// Initialize the interval variable outside the function
|
||||||
let plcCycle: any;
|
let plcCycle: any;
|
||||||
let plcInterval = 500;
|
let plcInterval = 500;
|
||||||
@@ -31,17 +32,42 @@ export const dycoConnect = async () => {
|
|||||||
await PLC.connect(plcAddress, 0).then(async () => {
|
await PLC.connect(plcAddress, 0).then(async () => {
|
||||||
createLog("info", "dyco", "ocp", `We are connected to the dyco.`);
|
createLog("info", "dyco", "ocp", `We are connected to the dyco.`);
|
||||||
isDycoRunning = true;
|
isDycoRunning = true;
|
||||||
let buffer = "";
|
|
||||||
plcCycle = setInterval(async () => {
|
plcCycle = setInterval(async () => {
|
||||||
await PLC.readTag(labelerTag);
|
if (isReading) {
|
||||||
await PLC.readTag(palletSend);
|
createLog(
|
||||||
|
"warn",
|
||||||
|
"dyco",
|
||||||
|
"ocp",
|
||||||
|
"Skipping cycle: previous read still in progress."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isReading = true; // Set flag
|
||||||
|
try {
|
||||||
|
await PLC.readTag(labelerTag);
|
||||||
|
await PLC.readTag(palletSend);
|
||||||
|
await PLC.readTag(strapperError);
|
||||||
|
|
||||||
// send the labeler tag data over
|
// strapper check
|
||||||
labelerTagRead(labelerTag);
|
strapperFaults(strapperError);
|
||||||
|
|
||||||
// send the end of line check over.
|
// send the labeler tag data over
|
||||||
palletSendTag(palletSend);
|
labelerTagRead(labelerTag);
|
||||||
}, 500);
|
|
||||||
|
// send the end of line check over.
|
||||||
|
palletSendTag(palletSend);
|
||||||
|
} catch (error: any) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"dyco",
|
||||||
|
"ocp",
|
||||||
|
`Error reading PLC tag: ${error.message}`
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
isReading = false; // Reset flag
|
||||||
|
}
|
||||||
|
}, plcInterval);
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog(
|
createLog(
|
||||||
@@ -50,6 +76,7 @@ export const dycoConnect = async () => {
|
|||||||
"ocp",
|
"ocp",
|
||||||
`There was an error in the dyco: ${error}`
|
`There was an error in the dyco: ${error}`
|
||||||
);
|
);
|
||||||
|
await PLC.disconnect();
|
||||||
isDycoRunning = false;
|
isDycoRunning = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
|
|||||||
import { createLog } from "../../../../../logger/logger.js";
|
import { createLog } from "../../../../../logger/logger.js";
|
||||||
import { readTags } from "../../../../../rfid/controller/readTags.js";
|
import { readTags } from "../../../../../rfid/controller/readTags.js";
|
||||||
import { labelingProcess } from "../../../labeling/labelProcess.js";
|
import { labelingProcess } from "../../../labeling/labelProcess.js";
|
||||||
|
import { stapperFaulted, strapperFaults } from "./strapperFault.js";
|
||||||
|
|
||||||
|
export let cameraPalletCheck = 20;
|
||||||
|
export let currentPalletCheck = 0;
|
||||||
let lastProcessedTimestamp = 0;
|
let lastProcessedTimestamp = 0;
|
||||||
|
|
||||||
export const labelerTagRead = async (tagData: any) => {
|
export const labelerTagRead = async (tagData: any) => {
|
||||||
@@ -41,11 +44,48 @@ export const labelerTagRead = async (tagData: any) => {
|
|||||||
// Only process if this is a new timestamp within the last 5 seconds
|
// Only process if this is a new timestamp within the last 5 seconds
|
||||||
if (tagTime !== lastProcessedTimestamp && Date.now() - tagTime <= 5000) {
|
if (tagTime !== lastProcessedTimestamp && Date.now() - tagTime <= 5000) {
|
||||||
lastProcessedTimestamp = tagTime;
|
lastProcessedTimestamp = tagTime;
|
||||||
//console.log(numericString, tagData.state.timestamp);
|
/**
|
||||||
|
* add logic in to see if this is the first time we run this so we return an error to validate we are in sync.
|
||||||
|
*/
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"dyco",
|
||||||
|
"ocp",
|
||||||
|
`Current pallet at the wrapper is: ${numericString}`
|
||||||
|
);
|
||||||
if (dycoPrint[0].value === "1") {
|
if (dycoPrint[0].value === "1") {
|
||||||
createLog("info", "dyco", "ocp", "Dyco will be printing the label");
|
createLog("info", "dyco", "ocp", "Dyco will be printing the label");
|
||||||
// send over to print.
|
// if (!dycoControlCheck) {
|
||||||
labelingProcess({ line: numericString });
|
// createLog(
|
||||||
|
// "error",
|
||||||
|
// "dyco",
|
||||||
|
// "ocp",
|
||||||
|
// `Dyco was switch to be the printer guys. please validate the line is in sync, Current line is ${numericString}`
|
||||||
|
// );
|
||||||
|
// dycoControlCheck = true;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// check the stapper error logic.
|
||||||
|
|
||||||
|
if (stapperFaulted) {
|
||||||
|
createLog("error", "dyco", "ocp", `Strapper is faulted.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if we need to manual check due to 20 pallets.
|
||||||
|
if (currentPalletCheck <= cameraPalletCheck) {
|
||||||
|
currentPalletCheck = currentPalletCheck + 1;
|
||||||
|
labelingProcess({ line: numericString });
|
||||||
|
} else {
|
||||||
|
currentPalletCheck = 0;
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"dyco",
|
||||||
|
"ocp",
|
||||||
|
`You have reached 20 pallets since the last check please validate the labeler is still in sync.`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dycoPrint[0].value === "0") {
|
if (dycoPrint[0].value === "0") {
|
||||||
@@ -56,7 +96,9 @@ export const labelerTagRead = async (tagData: any) => {
|
|||||||
"Rfid system is contorlling the printing"
|
"Rfid system is contorlling the printing"
|
||||||
);
|
);
|
||||||
// trigger the reader so we can get the label from the tag readers.
|
// trigger the reader so we can get the label from the tag readers.
|
||||||
await readTags("wrapper1");
|
setTimeout(async () => {
|
||||||
|
await readTags("wrapper1");
|
||||||
|
}, 2 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { db } from "../../../../../../../database/dbclient.js";
|
||||||
|
import { settings } from "../../../../../../../database/schema/settings.js";
|
||||||
|
import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
|
||||||
|
import { createLog } from "../../../../../logger/logger.js";
|
||||||
|
|
||||||
|
// strapper related issues
|
||||||
|
export let strapperActive = true;
|
||||||
|
export let stapperFaulted = false;
|
||||||
|
export let strapperFaultCount = 3; // move to db so we can control it outside the app
|
||||||
|
|
||||||
|
export const strapperFaults = async (tagData: any) => {
|
||||||
|
const { data, error } = await tryCatch(db.select().from(settings));
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return { success: false, message: "Failed to get settings." };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strapperActive) {
|
||||||
|
// monitor strapper
|
||||||
|
//console.log(`Strapper fault is ${strapperError.value}`);
|
||||||
|
if (tagData.value && strapperFaultCount > 0) {
|
||||||
|
// strapper faulted we want to start the trigger to force the check
|
||||||
|
if (!stapperFaulted) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"dyco",
|
||||||
|
"ocp",
|
||||||
|
`Strapper errored triggering manual checks will be required for the next ${strapperFaultCount}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
stapperFaulted = true;
|
||||||
|
|
||||||
|
// change move fault count to db....
|
||||||
|
strapperFaultCount = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const strapperCheckSetting = data.filter((n) => n.name === "strapperCheck");
|
||||||
|
|
||||||
|
if (strapperCheckSetting[0]?.value === "1") {
|
||||||
|
if (stapperFaulted && strapperFaultCount > 0) {
|
||||||
|
createLog(
|
||||||
|
"warn",
|
||||||
|
"dyco",
|
||||||
|
"ocp",
|
||||||
|
`There was a strapper error, remaining pallets to check ${strapperFaultCount}.`
|
||||||
|
);
|
||||||
|
strapperFaultCount = strapperFaultCount - 1;
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: `There was a strapper error, remaining pallets to check ${strapperFaultCount}.`,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
createLog(
|
||||||
|
"debug",
|
||||||
|
"dyco",
|
||||||
|
"ocp",
|
||||||
|
`Strapper check is active but not faulted, remaining pallets to check ${strapperFaultCount}.`
|
||||||
|
);
|
||||||
|
|
||||||
|
// reset everything
|
||||||
|
stapperFaulted = false;
|
||||||
|
strapperFaultCount = 3; // move to db as well
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `Strapper check is active but not faulted, remaining pallets to check ${strapperFaultCount}.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
|
|
||||||
// routes
|
// routes
|
||||||
import manualLabelLog from "./routes/manualPrintLog.js";
|
import manualLabelLog from "./routes/labeling/manualPrintLog.js";
|
||||||
import getPrinters from "./routes/printers/getPritners.js";
|
import getPrinters from "./routes/printers/getPritners.js";
|
||||||
import { db } from "../../../database/dbclient.js";
|
import { db } from "../../../database/dbclient.js";
|
||||||
import { settings } from "../../../database/schema/settings.js";
|
import { settings } from "../../../database/schema/settings.js";
|
||||||
@@ -12,6 +12,7 @@ import getLabels from "./routes/labeling/getLabels.js";
|
|||||||
import { dycoConnect } from "./controller/specialProcesses/dyco/plcConnection.js";
|
import { dycoConnect } from "./controller/specialProcesses/dyco/plcConnection.js";
|
||||||
import dycoCon from "./routes/specialProcesses/dyco/connection.js";
|
import dycoCon from "./routes/specialProcesses/dyco/connection.js";
|
||||||
import dycoClose from "./routes/specialProcesses/dyco/closeConnection.js";
|
import dycoClose from "./routes/specialProcesses/dyco/closeConnection.js";
|
||||||
|
import manualprint from "./routes/labeling/manualPrint.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ const routes = [
|
|||||||
getLots,
|
getLots,
|
||||||
// labeling
|
// labeling
|
||||||
getLabels,
|
getLabels,
|
||||||
|
manualprint,
|
||||||
//dyco
|
//dyco
|
||||||
dycoCon,
|
dycoCon,
|
||||||
dycoClose,
|
dycoClose,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ app.openapi(
|
|||||||
return c.json({
|
return c.json({
|
||||||
success: labelData.success,
|
success: labelData.success,
|
||||||
message: labelData.message,
|
message: labelData.message,
|
||||||
|
count: labelData.count,
|
||||||
data: labelData.data,
|
data: labelData.data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
50
server/services/ocp/routes/labeling/manualPrint.ts
Normal file
50
server/services/ocp/routes/labeling/manualPrint.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// an external way to creating logs
|
||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["ocp"],
|
||||||
|
summary: "Manual print a label by line and printer name",
|
||||||
|
method: "post",
|
||||||
|
path: "/manualprintandfollow",
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
//const hours = c.req.query("hours");
|
||||||
|
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||||
|
c.req.json()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (bodyError) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "You are missing data",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: createLabel, error: labelError } = await tryCatch(
|
||||||
|
labelingProcess({ line: bodyData.line })
|
||||||
|
);
|
||||||
|
|
||||||
|
if (labelError) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "There was an error creating the label.",
|
||||||
|
data: labelError,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const newLabel: any = createLabel;
|
||||||
|
return c.json({
|
||||||
|
success: newLabel.success,
|
||||||
|
message: newLabel.message,
|
||||||
|
data: newLabel.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
// an external way to creating logs
|
// an external way to creating logs
|
||||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import type { User } from "../../../types/users.js";
|
import type { User } from "../../../../types/users.js";
|
||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import { manualPrint } from "../controller/manualLabelLog.js";
|
import { manualPrint } from "../../controller/labeling/manualLabelLog.js";
|
||||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const CreateLog = z.object({
|
const CreateLog = z.object({
|
||||||
@@ -32,7 +33,17 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const body = await c.req.json();
|
const { data: body, error } = await tryCatch(c.req.json());
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Missing Data.",
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
|
}
|
||||||
apiHit(c, { endpoint: `api/logger/logs/id` });
|
apiHit(c, { endpoint: `api/logger/logs/id` });
|
||||||
try {
|
try {
|
||||||
//const data = {...body, add_user: user.username};
|
//const data = {...body, add_user: user.username};
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
// an external way to creating logs
|
|
||||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
|
||||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
|
||||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
|
||||||
|
|
||||||
const app = new OpenAPIHono({strict: false});
|
|
||||||
const CreateLog = z.object({
|
|
||||||
line: z.string().openapi({example: "info"}),
|
|
||||||
initials: z.string().openapi({example: "server"}),
|
|
||||||
printReason: z.string().openapi({example: "This is a new log posted"}),
|
|
||||||
additionalComments: z.string().optional().openapi({example: "Some reason why we did this."}),
|
|
||||||
});
|
|
||||||
|
|
||||||
app.openapi(
|
|
||||||
createRoute({
|
|
||||||
tags: ["ocp"],
|
|
||||||
summary: "Prints a label.",
|
|
||||||
method: "post",
|
|
||||||
path: "/printlabel",
|
|
||||||
//middleware: authMiddleware,
|
|
||||||
//description: "This might be a temp soltuin during the transtion between versions",
|
|
||||||
request: {
|
|
||||||
body: {content: {"application/json": {schema: CreateLog}}},
|
|
||||||
},
|
|
||||||
responses: responses(),
|
|
||||||
}),
|
|
||||||
async (c) => {
|
|
||||||
const body = await c.req.json();
|
|
||||||
apiHit(c, {endpoint: `api/logger/logs/id`});
|
|
||||||
// const authHeader = c.req.header("Authorization");
|
|
||||||
|
|
||||||
// const token = authHeader?.split("Bearer ")[1] || "";
|
|
||||||
// let user: User;
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// const payload = await verify(token, process.env.JWT_SECRET!);
|
|
||||||
// user = payload.user as User;
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log(error);
|
|
||||||
// return c.json({message: "Unauthorized"}, 401);
|
|
||||||
// }
|
|
||||||
|
|
||||||
try {
|
|
||||||
//const data = {...body, add_user: user.username};
|
|
||||||
|
|
||||||
return c.json({success: true, message: "Label was printed.", data: []}, 200);
|
|
||||||
} catch (error) {
|
|
||||||
return c.json({success: false, message: "There was an error printing a label.", data: error}, 400);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
export default app;
|
|
||||||
@@ -168,6 +168,13 @@ const newSettings = [
|
|||||||
roles: "admin",
|
roles: "admin",
|
||||||
module: "ocp",
|
module: "ocp",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "strapperCheck",
|
||||||
|
value: "1",
|
||||||
|
description: "Are we monitoring the strapper for faults?",
|
||||||
|
roles: "admin",
|
||||||
|
module: "ocp",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
export const areSettingsIn = async () => {
|
export const areSettingsIn = async () => {
|
||||||
// get the roles
|
// get the roles
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ left join
|
|||||||
alplaprod_test1.dbo.T_Maschine as m on
|
alplaprod_test1.dbo.T_Maschine as m on
|
||||||
e.IdMaschine = m.IdMaschine
|
e.IdMaschine = m.IdMaschine
|
||||||
|
|
||||||
where x.lfdnr = [rn] and x.IdWarenlager not in(6)
|
where x.lfdnr = [rn]
|
||||||
|
--and x.IdWarenlager not in(6)
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ select IdMaschinen_ProdPlanung as LabelOnlineID,
|
|||||||
IdMaschine as machineID,
|
IdMaschine as machineID,
|
||||||
MaschinenStandort as MachineLocation,
|
MaschinenStandort as MachineLocation,
|
||||||
MaschinenBez as MachineDescription,
|
MaschinenBez as MachineDescription,
|
||||||
IdProdPlanung as LOT,
|
IdProdPlanung as lot,
|
||||||
prolink.lot as ProlinkLot,
|
prolink.lot as ProlinkLot,
|
||||||
IdArtikelvarianten as AV,
|
IdArtikelvarianten as AV,
|
||||||
ArtikelVariantenBez as Alias,
|
ArtikelVariantenBez as Alias,
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ let tcpServer: net.Server;
|
|||||||
let tcpSockets: Set<net.Socket> = new Set();
|
let tcpSockets: Set<net.Socket> = new Set();
|
||||||
let isServerRunning = false;
|
let isServerRunning = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add in proper logging
|
||||||
|
*/
|
||||||
const tcpPort = await db
|
const tcpPort = await db
|
||||||
.select()
|
.select()
|
||||||
.from(settings)
|
.from(settings)
|
||||||
@@ -25,14 +28,19 @@ export const startTCPServer = () => {
|
|||||||
return { success: false, message: "Server is already running" };
|
return { success: false, message: "Server is already running" };
|
||||||
|
|
||||||
tcpServer = net.createServer((socket) => {
|
tcpServer = net.createServer((socket) => {
|
||||||
console.log("Client connected");
|
createLog("info", "tcp", "tcp", "Client connected");
|
||||||
|
|
||||||
tcpSockets.add(socket);
|
tcpSockets.add(socket);
|
||||||
socket.on("data", (data: Buffer) => {
|
socket.on("data", (data: Buffer) => {
|
||||||
console.log("Received:", data.toString());
|
|
||||||
const parseData = data.toString("utf-8").trimEnd().split(" ");
|
const parseData = data.toString("utf-8").trimEnd().split(" ");
|
||||||
// hb from the scanners
|
// hb from the scanners
|
||||||
if (parseData[0] === "HB") {
|
if (parseData[0] === "HB") {
|
||||||
|
createLog(
|
||||||
|
"debug",
|
||||||
|
"tcp",
|
||||||
|
"tcp",
|
||||||
|
`Received:", ${data.toString()}`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,12 +54,12 @@ export const startTCPServer = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("end", () => {
|
socket.on("end", () => {
|
||||||
console.log("Client disconnected");
|
createLog("info", "tcp", "tcp", "Client disconnected");
|
||||||
tcpSockets.delete(socket);
|
tcpSockets.delete(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("error", (err: Error) => {
|
socket.on("error", (err: Error) => {
|
||||||
console.error("Socket error:", err);
|
createLog("info", "tcp", "tcp", `Socket error:", ${err}`);
|
||||||
tcpSockets.delete(socket);
|
tcpSockets.delete(socket);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -78,7 +86,7 @@ export const stopTCPServer = () => {
|
|||||||
}
|
}
|
||||||
tcpSockets.clear();
|
tcpSockets.clear();
|
||||||
tcpServer.close(() => {
|
tcpServer.close(() => {
|
||||||
console.log("TCP Server stopped");
|
createLog("info", "tcp", "tcp", "TCP Server stopped");
|
||||||
});
|
});
|
||||||
isServerRunning = false;
|
isServerRunning = false;
|
||||||
return { success: true, message: "TCP Server stopped" };
|
return { success: true, message: "TCP Server stopped" };
|
||||||
|
|||||||
Reference in New Issue
Block a user