node-modbus-serial icon indicating copy to clipboard operation
node-modbus-serial copied to clipboard

closing modbus connection using close() and it will crashing my electron app

Open Bhargav2patel opened this issue 9 months ago • 1 comments

making an electron app and using modbus serial package,

connected the modubus client and readed holding register succesfully and when i am trying to redirect to onether page using javascripts window.onbeforeunload function and closing client connection from inside this function ,

but the problem is this will crashing my electron app but the logs of rediraction will be printed succesfully when the client disconnect

const $ = require('jquery');
const ModbusRTU = require("modbus-serial");

var client = new ModbusRTU();

$(document).ready(function () {
        $("#print-menu").click(function () {
            window.location.href = 'print-menu.html';
        })
});

window.onbeforeunload = function () {
    try {
        logger.info("redirecting");
        client.close();
        logger.info("redirected");
    } catch (error) {
        logger.error(error);
    }
}

Bhargav2patel avatar May 02 '24 07:05 Bhargav2patel

can you provide full code? I intuitively think this is more likely because you are not familiar with the Electron development framework.

teddy1565 avatar Jun 01 '24 10:06 teddy1565