Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I disconnect from modus.tcp.connect #46

Open
khuang-citylift opened this issue Sep 6, 2019 · 1 comment
Open

How can I disconnect from modus.tcp.connect #46

khuang-citylift opened this issue Sep 6, 2019 · 1 comment

Comments

@khuang-citylift
Copy link

My PLC has 4 threads that I can connect to. Once I connect the 4 times, it will crash on the 5th attempt. Is there any documentation on disconnecting from an existing connection?

I've tried connection.close(), connection.off() without any luck.

@MarcusHuns
Copy link

MarcusHuns commented Mar 26, 2020

I think connection.close() needs to be inside the connection. block. This worked for me:

modbus.tcp.connect(502, req.ip, { debug: "automaton-2454" }, (err, connection) => {

    connection.writeSingleRegister({ address: req.register, value: Buffer.from([ 0x00, 0x01 ]) }, (err, res) => {
        if (err) throw err;

        console.log(res); // response
        connection.close();
    })
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants