Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!