Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js path to serialport

For this part of code for my node.js server

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

which use the https://github.com/EmergingTechnologyAdvisors/node-serialport library.

How I can know this path to my serial port?

like image 808
nuser Avatar asked Jan 05 '23 15:01

nuser


1 Answers

I tried the previous answers in this question but they did not work in latest version of serial port (Sept 2020). We need to use serialport.list() function in promise approach like this:

import serialport package

const SerialPort = require('serialport')

Promise approach

SerialPort.list().then(ports => {
    ports.forEach(function(port) {
        console.log(port.path)
    })
})

I hope this will help you to solve this problem

like image 145
Azzam Jihad Ulhaq Avatar answered Jan 17 '23 01:01

Azzam Jihad Ulhaq