node.js to read usb port signals

后端 未结 2 1461
小鲜肉
小鲜肉 2020-12-31 17:12

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

相关标签:
2条回答
  • 2020-12-31 17:31

    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 */ });
    
    0 讨论(0)
  • 2020-12-31 17:36

    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

    0 讨论(0)
提交回复
热议问题