Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 830
Vivek Mohan Avatar asked Aug 22 '12 16:08

Vivek Mohan


2 Answers

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 */ });
like image 144
raina77ow Avatar answered Nov 11 '22 12:11

raina77ow


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

like image 45
hubertk Avatar answered Nov 11 '22 11:11

hubertk