Vivek Mohan
Vivek Mohan

Reputation: 8366

node.js to read usb port signals

I have installed serialport module for node.js using npm.(npm install serialport). Now I would like to send some messages from my android phone to node application via usb port of my computer(assuming node can read serial port signals). Has anyone done this before?

Thanks in advance.

Upvotes: 12

Views: 26307

Answers (2)

raina77ow
raina77ow

Reputation: 106385

Why, yes, it's certainly doable. There's a plenty of examples listed at the serialport package homepage itself.

Your node.js application will start with...

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty-usbserial1");

serialPort.on('data', function(data) { /* processing data */ });

Upvotes: 11

hubertk
hubertk

Reputation: 91

For testing your ports on Windows (you may have to install sf "npm install sf"):

var serialport = require('serialport');
var sf = require('sf');

serialport.list(function (err, results) {
  if (err) {
    throw err;
  }

  for (var i = 0; i < results.length; i++) {
    var item = results[i];
    console.log(sf('{comName,-15} {pnpId,-20} {manufacturer}', item));
  }
});

Output should be something like:

COM8 FTDIBUS\VID_0403+PID_6001+A100DKP7A\0000 FTDI
COM1 ACPI\PNP0501\4&2E24A907&0 (Standardanschlusstypen)

Now use the port your device is connected to, in my case COM8:

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("COM8");

regards

Upvotes: 9

Related Questions