Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
Get weight scale data from serial port using Node JS

I am new in node js, i want to get weight data from serial port, i have installed nodejs(v14.19.0) and npm(6.14.16), and i want to get weight data using localhost:8080/get_weight, but script is not working, anyone can help me ?

Here is my code:

const http = require('http');
const hostname = 'localhost';
const { SerialPort, ReadlineParser } = require('serialport')
const { io } = require('socket.io')(3000);
const serialport = new SerialPort({ 
    path: '/dev/ttyS4',
    baudRate: 7500000 ,
})
const parser = new ReadlineParser()
serialport.pipe(parser)
/*serialport.on('data', console.log)  */

let express = require('express')
let app = express();

var port = 8080;

const server = http.createServer(app);

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
app.get('/get_weight', function(req, res) {
    serialport.on('open',function(){
        serialport.on('data', function(data){
            console.log('DATA:::::', data)
            const buf2 = Buffer.from(data)
            let wArray = buf2.toString('utf8');
            let wSlice = wArray.slice(3, wArray.length);
            let rawWeight = wSlice.slice(0, -3);
            let fWeight = rawWeight.trim();
            let weight = parseInt(fWeight);
            console.log(weight);
        });
    });
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda