1.0.1 • Published 8 years ago

serialport-watch v1.0.1

Weekly downloads
4
License
ISC
Repository
-
Last release
8 years ago

Serialport-watch, detect connect/disconnect

This module will watch computer SerialPorts, and will fire connect/disconnect events.

Installing

You can install this package via npm:

npm install serialport-watch --save

Important: This package tested with serialport @ 3.1.2 on ubuntu 16.

Basic usage

You can find latest examples in test.js file. Here is simple usage:

var $watch = require("serialport-watch");

$watch.watch();
$watch.events.on("connect" , function (port , x) {
    console.log("port connected: " , port , x);
});

$watch.events.on("disconnect" , function (port , x) {
    console.log("port disconnected: " , port , x);
});

It will result:

port connected:  /dev/ttyUSB0 { comName: '/dev/ttyUSB0',
  manufacturer: 'FTDI',
  serialNumber: 'FTDI_FT232R_USB_UART_AJ03JBD7',
  pnpId: 'usb-FTDI_FT232R_USB_UART_AJ03JBD7-if00-port0',
  vendorId: '0x0403',
  productId: '0x6001' }
port connected:  /dev/ttyUSB1 { comName: '/dev/ttyUSB1',
  manufacturer: 'FTDI',
  serialNumber: 'FTDI_FT232R_USB_UART_AJ03JBD3',
  pnpId: 'usb-FTDI_FT232R_USB_UART_AJ03JBD3-if00-port0',
  vendorId: '0x0403',
  productId: '0x6001' }

Methods reference

There are some functions to work more with this module, here we list them. If something is missing, you can open index.js to see if something is missed here.

void watch()

Starts watching ports. Before calling this function connect/disconnect events won't be triggered

void stop()

Will stop watching ports. Can be called after watch() is called

EventEmitter events

The event emitter object that component works with. Can be used for setting handlers

boolean watching()

Returns if ports are watching or not.

Promise getPorts()

Gets the all ports, event if nothing is connected.