yaacov / node-modbus-serial

A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS
ISC License
606 stars 233 forks source link

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

Open Bhargav2patel opened 2 months ago

Bhargav2patel commented 2 months ago

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);
    }
}
teddy1565 commented 1 month ago

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