如何在Node.js中将输出十六进制转换为十进制?

时间:2017-12-21 04:15:51

标签: javascript node.js bluetooth bluetooth-lowenergy

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

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();

输出:

North Vision病人监护仪 发送数据 接收数据 缓冲区1b a1 00 00 00 00 00 00 00 00 00 00 55 55 51 4c 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00

1 个答案:

答案 0 :(得分:0)

#Data
##Then rearrange your data frame
library(reshape2)
dd = melt(dd_sub, id=c("date_decision_made"))
dd$date_decision_made <- as.Date(as.character(dd$date_decision_made),'%Y/%m/%d')
#Plot
ggplot(dd) +
  geom_line(aes(x=date_decision_made, y=value, colour=variable, group=1))+
  scale_x_date(date_breaks = "months" ,breaks = '12 months', date_labels = "%b %d %a")+
  scale_colour_manual(values=c("red","green","blue"))+
  theme(axis.text.x = element_text(angle=90))