如何将输出十六进制转换为Node.js中的小数



我正在尝试从蓝牙设备(心率监视器)获取数据,在那里它将显示心率,脉搏率的值。当我在终端运行该程序时,输出中的输出会出现在十六进制中,因此任何想法如何以十进制显示输出。谢谢..

const bluetooth = require('node-bluetooth');
// create bluetooth device instance
const device = new bluetooth.DeviceINQ();
var num = 0;
device
.on('finished',  console.log.bind(console, 'finished'))
.on('found', function found(address, name){
console.log('Found: ' + address + ' with name ' + name);
device.findSerialPortChannel(address, function(channel){
console.log('Found RFCOMM channel for serial port on %s: ', name,     'channel:',channel);
// // make bluetooth connect to remote device
bluetooth.connect(address, channel, function(err, connection){
console.log('North Vision Patient Monitor')
if(err) return console.error(err);
connection.write(new Buffer([0x55,0xAA,0x00], 'utf-8'), () => {
console.log('Send Data')

connection.write(new Buffer([
  0x0b,
  0x40,
  0x85,
  0xB6,
  0xFB,
  0x10,
  0x3C,
  0xC8,
  0xFF,
  0xB4,
  0x28,
  0x28,
  0x0A,
  0x64,
  0x5A,
  0xB4,
  0x3C,
  0x78,
  0x32,
  0xA0,
  0x32,
  0x6E,
  0x46,
  0xB4,
  0x28,
  0x04,
  0x07,
  0x46,
  0x0A,
  0x0A,
  0x00,
  0x00], 'utf-8'), () => {
    console.log('Receive Data')

    });
});

 connection.on('data', (buffer) => {
 console.log('received message:', buffer,'====',num);
 num++;
 });

});
console.log('finished')
});
 // // make bluetooth connect to remote device
// bluetooth.connect(address, channel, function(err, connection){
// if(err) return console.error(err);
// connection.on('data', (buffer) => {
// console.log('received message:', buffer.toString());
// });
// connection.write(new Buffer('Hello!', 'utf-8'));
// });
}).inquire();

输出:

北部视力患者监视器发送数据接收数据缓冲区1B A1 00 00 00 00 00 00 00 00 00 00 00 57 55 51 4C 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

cons bufferInHex = Buffer.from('some string') // init a buffer
console.log(new Uint8Array(bufferInHex)) // display buffer in decimal format

最新更新