65

I want to send a raw buffer using bluetooth connection. The content is a hex number. Currently I split the number manually to an byte array. Is there any function that can help me convert the number to byte array?

//var data = 0x250001000192CD0000002F6D6E742F72;
var data = new Buffer([0x25,0x00,0x01,0x00,0x01,0x92,0xCD,0x00,0x00,0x00,0x2F,0x6D,0x6E,0x74,0x2F,0x72]);
serialPort.write(data);
4

2 回答 2

136

在新版本的节点(6+)中,该new Buffer()接口已被弃用。利用:

Buffer.from("250001000192CD0000002F6D6E742F72", "hex")

反而。

使用以下链接查找更多信息 https://nodejs.org/api/buffer.html#buffer_static_method_buffer_from_string_encoding

于 2016-12-10T20:45:50.790 回答
72
new Buffer("250001000192CD0000002F6D6E742F72", "hex")
于 2013-09-18T19:09:56.800 回答