byte data to string not display decimal number

Viewed 36

I am reading the weighbridge data using the serial port in node JS. Everything worked fine when I read weight without the decimal, But when I read decimal data like 138.40 then I am getting a dot at the end of the string.

byteData>>> <Buffer 2b 2d 31 33 38 34 30 2e>
byteData.toString()>>> +-13840.

Can you please guide me on how to convert decimal data into the proper numeric format?

Full code :

const { SerialPort } = require('serialport');
const apiServer = require('./api');
const logger = require('./log_config');

const port = new SerialPort({ 
    path: '/dev/ttyS0', 
    baudRate: 2400

}, function (err) {
  if (err) {
    logger.error(err.message);
    logger.error('Test Error');
    return console.log('Error: ', err.message)
  }
})

port.on('readable', function () {
     var truckWeight=port.read().toString();
 
     
     console.log('Data:', port.read().toString())
})



port.write('main screen turn on', function(err) {
  if (err) {
    return console.log('Error on write: ', err.message)
  }
  console.log('message written')
})
0 Answers
Related