firmata.js icon indicating copy to clipboard operation
firmata.js copied to clipboard

How do you close the connection?

Open digihaven opened this issue 10 years ago • 2 comments

How do you close the connection to allow Nodejs to have a clean shut down? There seems to be a missing .close() function that should be implemented for this firmata module.

The only way I could figure out, is by creating the serialPort myself. But there are (setTimeouts??) that cause crashing:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Error Bad file descriptor calling write(...)
    at Error (native)

Any better suggestions?

digihaven avatar Mar 23 '15 22:03 digihaven

I have more or less the same question, if I create the Board object like this:

var myBoard = null;
function initializeMyBoard(){
  Board.requestPort( function(err, port){
      if(err){
        console.log(err);
        return;
      }

      console.log("Acceptable Port Found");
      myPort = port.comName;
      var board = new Board(myPort);
      board.on("ready", function(){
        console.log("Board Ready!");
        myBoard = board;
      });
  });
}

// shouldn't I be able to call some function on myBoard
// down here to close the connection and gracefully
// shutdown the serial port?

// so that I can do some other stuff at this point 
// without being connected to the Serial Port and then 
// call initializeMyBoard() when I feel like it?

vicatcu avatar Apr 11 '16 23:04 vicatcu

I think you can call board.sp.close() to close the underlying serialport

dceejay avatar Jul 12 '16 22:07 dceejay