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 know if the connection is always open ? #30

Open
cyberal82 opened this issue Mar 18, 2019 · 2 comments
Open

How can I know if the connection is always open ? #30

cyberal82 opened this issue Mar 18, 2019 · 2 comments

Comments

@cyberal82
Copy link

Hi,

For beginning thank you for this node module :).

I have an electron program that open a bluetooth connection and listening the event "data".

How can I know if the connection is always open ?

Before write data I check if the connection is open with connection.isOpen() but this method return true if the connection has been open and lost.

I have try to listen the events "closed", "close", "failure" without any success.

If the connection has been open and lost, when I write data I have an uncatched exception:
Error : Error reading from connection.

The calls to the write method is in try/catch block

Node version : v8.12.0
node-bluetooth: v1.2.5

Thank you for your help.

@ThomasLaforge
Copy link

@cyberal82 Have you any news on it ?

@nipoonp
Copy link

nipoonp commented Sep 13, 2020

This seemed to work for me:

let bluetoothPrinter;

connection.on("error", (err: any) => {
  console.log("Error: " + err);

  connection.close(() => {
    console.log("Connection closed manually");
  });

  bluetoothPrinter = null;
});

I listen to the connection.on "error" and if that is triggered I manually close the connection and set me global variable for bluetoothPrinter to null.

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

No branches or pull requests

3 participants