import net from "net"; /** * This uses a kinda fake scanner to mimic the scanning process to a server and creates the bol. */ const prodIP = "10.204.0.26"; const prodPort = 50000; const scannerID = "98@"; const scannerCommand = "AlplaPRODcmd00000042#000028643"; // top of the picksheet const scannerCommand2 = ""; // bottom of the pick sheet const labels = [ "1000000000000000000000000000000005572620", "1000000000000000000000000000000005572630", "1000000000000000000000000000000005572640", "1000000000000000000000000000000005572650", "1000000000000000000000000000000005572660", "1000000000000000000000000000000005572670", "1000000000000000000000000000000005572680", "1000000000000000000000000000000005572690", "1000000000000000000000000000000005572700", "1000000000000000000000000000000005572710", "1000000000000000000000000000000005572720", "1000000000000000000000000000000005572730", "1000000000000000000000000000000005572740", "1000000000000000000000000000000005572750", "1000000000000000000000000000000005572760", "1000000000000000000000000000000005572770", "1000000000000000000000000000000005572780", "1000000000000000000000000000000005572790", "1000000000000000000000000000000005572800", "1000000000000000000000000000000005572810", "1000000000000000000000000000000005572820", "1000000000000000000000000000000005572830", "1000000000000000000000000000000005572840", "1000000000000000000000000000000005572850", "1000000000000000000000000000000005572860", "1000000000000000000000000000000005572870", "1000000000000000000000000000000005572880", "1000000000000000000000000000000005572890", "1000000000000000000000000000000005572900", "1000000000000000000000000000000005572910", "1000000000000000000000000000000005573226", "1000000000000000000000000000000005573236", "1000000000000000000000000000000005573246", "1000000000000000000000000000000005573256", "1000000000000000000000000000000005573266", "1000000000000000000000000000000005573276", "1000000000000000000000000000000005573286", "1000000000000000000000000000000005573296", "1000000000000000000000000000000005573306", "1000000000000000000000000000000005573316", "1000000000000000000000000000000005573326", "1000000000000000000000000000000005573336", "1000000000000000000000000000000005573346", "1000000000000000000000000000000005573356", "1000000000000000000000000000000005573366", "1000000000000000000000000000000005573376", "1000000000000000000000000000000005573386", "1000000000000000000000000000000005573396", "1000000000000000000000000000000005573406", "1000000000000000000000000000000005573416", "1000000000000000000000000000000005573426", "1000000000000000000000000000000005573436", "1000000000000000000000000000000005573446", "1000000000000000000000000000000005573456", "1000000000000000000000000000000005573466", "1000000000000000000000000000000005573476", "1000000000000000000000000000000005573486", "1000000000000000000000000000000005573496", "1000000000000000000000000000000005573506", "1000000000000000000000000000000005573516", "1000000000000000000000000000000005581616", "1000000000000000000000000000000005581626", "1000000000000000000000000000000005581636", "1000000000000000000000000000000005581646", "1000000000000000000000000000000005581656", "1000000000000000000000000000000005581666", "1000000000000000000000000000000005581676", "1000000000000000000000000000000005581686", "1000000000000000000000000000000005581696", "1000000000000000000000000000000005581706", "1000000000000000000000000000000005581716", "1000000000000000000000000000000005581726", "1000000000000000000000000000000005581736", "1000000000000000000000000000000005581746", "1000000000000000000000000000000005581756", "1000000000000000000000000000000005581766", "1000000000000000000000000000000005581776", "1000000000000000000000000000000005581786", "1000000000000000000000000000000005581796", "1000000000000000000000000000000005581806", "1000000000000000000000000000000005581816", "1000000000000000000000000000000005581826", "1000000000000000000000000000000005581836", "1000000000000000000000000000000005581846", "1000000000000000000000000000000005581856", "1000000000000000000000000000000005582760", "1000000000000000000000000000000005581866", "1000000000000000000000000000000005581876", "1000000000000000000000000000000005581886", "1000000000000000000000000000000005581896", "1000000000000000000000000000000005581906", "1000000000000000000000000000000005581310", "1000000000000000000000000000000005581320", "1000000000000000000000000000000005581330", "1000000000000000000000000000000005581340", "1000000000000000000000000000000005581350", "1000000000000000000000000000000005581360", "1000000000000000000000000000000005581370", "1000000000000000000000000000000005581380", "1000000000000000000000000000000005581390", "1000000000000000000000000000000005581400", "1000000000000000000000000000000005581410", "1000000000000000000000000000000005581420", "1000000000000000000000000000000005581430", "1000000000000000000000000000000005581440", "1000000000000000000000000000000005581450", "1000000000000000000000000000000005581460", "1000000000000000000000000000000005581470", "1000000000000000000000000000000005581480", "1000000000000000000000000000000005581490", "1000000000000000000000000000000005581500", "1000000000000000000000000000000005581510", "1000000000000000000000000000000005581520", "1000000000000000000000000000000005581530", "1000000000000000000000000000000005581540", "1000000000000000000000000000000005581550", "1000000000000000000000000000000005581560", "1000000000000000000000000000000005581570", "1000000000000000000000000000000005581580", "1000000000000000000000000000000005581590", "1000000000000000000000000000000005581600", ]; const STX = "\x02"; const ETX = "\x03"; const scanner = new net.Socket(); scanner.connect(prodPort, prodIP, async () => { console.log("Connected to scanner"); const message = Buffer.from( `${STX}${scannerID}${scannerCommand}${ETX}`, "ascii", ); console.log("Sending:", message.toString("ascii")); scanner.write(message); await new Promise((resolve) => setTimeout(resolve, 2000)); for (let i = 0; i < labels.length; i++) { const l = labels[i]; const message = Buffer.from(`${STX}${scannerID}${l}${ETX}`, "ascii"); console.log("Sending:", message.toString("ascii")); scanner.write(message); await new Promise((resolve) => setTimeout(resolve, 1200)); } // //close the incoming // await new Promise(resolve => setTimeout(resolve, 1500)); // const message2 = Buffer.from(`${STX}${scannerID}${scannerCommand2}${ETX}`, "ascii"); // console.log("Sending:", message2.toString("ascii")); // scanner.write(message2); 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); });