Closed andy6804tw closed 5 years ago
I also have the same problem :/
What's version of module and node ?
@song940 v9.11.1
@andy6804tw node v10.13.0
Upgrade node-bluetooth to latest version.
@song940 same problem. @daksen and you?
@andy6804tw pls copy your "lib/connection.js" file and paste here .
cat /Users/ca/Desktop/bluetooth/node_modules/node-bluetooth/lib/connection.js | pbcopy
@song940
const EventEmitter = require('events');
/**
* [function description]
* @return {[type]} [description]
*/
class Connection extends EventEmitter {
constructor(port, address) {
const self = this;
this.port = port;
this.address = address;
this.buffer = Buffer.alloc(0);
const read = function () {
process.nextTick(function () {
if (self.isOpen()) {
self.port.read(function (err, chunk) {
if (err) return self.emit('error', err);
if (self.delimiter) {
let data = Buffer.concat([self.buffer, chunk]);
let position;
while ((position = data.indexOf(self.delimiter)) !== -1) {
self.emit('data', data.slice(0, position));
data = data.slice(position + self.delimiter.length);
}
self.buffer = data;
} else {
self.emit('data', chunk);
}
read();
});
}
});
}
read();
}
/**
* [write description]
* @param {[type]} data [description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
write(data, callback){
this.port.write(data, this.address, callback);
return this;
}
/**
* [close description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
close(){
try {
this.port.close(this.address);
this.port = undefined;
callback && callback();
} catch (e) {
callback && callback(e);
}
return this;
}
isOpen(){
return this.port !== undefined;
}
}
module.exports = Connection;
fixed, pls install latest version
npm i node-bluetooth@1.2.4
@song940 Thank you for your help! But the device is not with me. I am testing the day after tomorrow.
Any questions?
Hi this is my error message. how can I solve it? thx!