import net from "net"; /** * This uses a kinda fake scanner to mimic the scanning process to a server and creates the bol. */ const scannerID = "98@"; const scannerCommand = "Alplaprodcmd112"; // to consume all the pallets const lot = "AlplaPRODchg#11601"; // to consume to the lot make sure its showing in 2.0 to be able to consume to it const labels = [ "1000000000000000000000000000000004551860", "1000000000000000000000000000000004551640", "1000000000000000000000000000000004551840", "1000000000000000000000000000000004551610", "1000000000000000000000000000000004551720", "1000000000000000000000000000000004551680", "1000000000000000000000000000000004551740", "1000000000000000000000000000000004551660", "1000000000000000000000000000000004551570", "1000000000000000000000000000000004551480", "1000000000000000000000000000000004551510", "1000000000000000000000000000000004551460", "1000000000000000000000000000000004551600", "1000000000000000000000000000000004551340", "1000000000000000000000000000000004551580", "1000000000000000000000000000000004551330", "1000000000000000000000000000000004551290", "1000000000000000000000000000000004551180", "1000000000000000000000000000000004551260", "1000000000000000000000000000000004551150", "1000000000000000000000000000000004551390", "1000000000000000000000000000000004551440", "1000000000000000000000000000000004551360", "1000000000000000000000000000000004551400", "1000000000000000000000000000000004544780", "1000000000000000000000000000000004551230", "1000000000000000000000000000000004544770", "1000000000000000000000000000000004551200", "1000000000000000000000000000000004544850", "1000000000000000000000000000000004548370", "1000000000000000000000000000000004544840", "1000000000000000000000000000000004548470", "1000000000000000000000000000000004611380", "1000000000000000000000000000000004611470", "1000000000000000000000000000000004611440", ]; const STX = "\x02"; const ETX = "\x03"; const scanner = new net.Socket(); scanner.connect(50001, "10.80.0.26", async () => { console.log("Connected to scanner"); // change the scanner to the to 112 let message = Buffer.from( `${STX}${scannerID}${scannerCommand}${ETX}`, "ascii", ); console.log("Sending:", message.toString("ascii")); scanner.write(message); await new Promise((resolve) => setTimeout(resolve, 2000)); // consume all the pallets in the array await new Promise((resolve) => setTimeout(resolve, 2000)); for (let i = 0; i < labels.length; i++) { const l = labels[i]; // trigger the lot let message = Buffer.from(`${STX}${scannerID}${lot}${ETX}`, "ascii"); console.log("Sending:", message.toString("ascii")); scanner.write(message); message = Buffer.from(`${STX}${scannerID}${l}${ETX}`, "ascii"); console.log("Sending:", message.toString("ascii")); scanner.write(message); await new Promise((resolve) => setTimeout(resolve, 1200)); } await new Promise((resolve) => setTimeout(resolve, 1500)); scanner.destroy(); }); scanner.on("data", async (data) => { console.log( "Response:", data .toString("ascii") .replace(/\x00/g, "") // remove null bytes .replace(/\x1B\[[0-9;?]*[A-Za-z]/g, "") // remove ANSI escape codes .trim(), ); }); scanner.on("close", () => { console.log("Connection closed"); }); scanner.on("error", (err) => { console.error("Scanner error:", err); });