node.js path to serialport

匆匆过客 提交于 2020-04-13 09:18:09

问题


For this part of code for my node.js server

var SerialPort = require("serialport");
var port = new SerialPort("/dev/tty-usbserial1", {});

wich use the https://github.com/EmergingTechnologyAdvisors/node-serialport library how I can know this path to my serial port?


回答1:


To find the paths of available COM ports on the system, you can use the list method.

I'd advise omitting any that have an undefined manufacturer property as these normally seem to be things like built-in bluetooth etc.

Example:

const SerialPort = require('serialport') 
SerialPort.list((err, ports) => {
    console.log(ports)                
})

Documentation: https://node-serialport.github.io/node-serialport/SerialPort.html#.list



来源:https://stackoverflow.com/questions/38607979/node-js-path-to-serialport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!