From 6be34a91244980657df5a6a8138cd44185ba6eeb Mon Sep 17 00:00:00 2001 From: kavehjamshidi Date: Sat, 19 Oct 2024 15:13:39 +0330 Subject: [PATCH] update serialPortService.js --- services/serialPortService.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/services/serialPortService.js b/services/serialPortService.js index c9eb386..e56683a 100644 --- a/services/serialPortService.js +++ b/services/serialPortService.js @@ -21,7 +21,19 @@ async function serialPortList(req, res) { const buff = Buffer.allocUnsafe(4); buff.write(`#0${req.params.id}$`); - serialPort.write(buff) + serialPort.on('open', () => { + console.log('Serial port opened'); + serialPort.write(buff) + }); + + serialPort.on('data', (data) => { + console.log('Received data:', data); + // Process the response to check if the box was opened successfully + }); + + serialPort.on('error', (error) => { + console.error('Error:', error); + }); } }) .catch((error) => {