Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda