Created
June 21, 2014 22:09
-
-
Save mindoftea/ac6ca90687e0f1c10d0f to your computer and use it in GitHub Desktop.
Node-bluetooth-serial-port writing lag test case. Writing consistently takes 250ms to complete on OSX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var bluetooth=require('bluetooth-serial-port'); | |
bluetooth=new bluetooth.BluetoothSerialPort(); | |
var write=function() | |
{ | |
var timeStamp; | |
console.log("sending..."); | |
timeStamp=Date.now(); | |
bluetooth.write( | |
new Buffer("some data","utf-8"), | |
function(err,bytesWritten) | |
{ | |
console.log("sent."); | |
console.log("lag time: "+(Date.now()-timeStamp)); | |
write(); | |
} | |
); | |
}; | |
var fail=function() | |
{ | |
console.log('cannot connect'); | |
} | |
bluetooth.on( | |
'found', | |
function(address,name) | |
{ | |
bluetooth.findSerialPortChannel( | |
address, | |
function(channel) | |
{ | |
bluetooth.connect( | |
address, | |
channel, | |
write, | |
fail | |
); | |
} | |
); | |
} | |
); | |
bluetooth.inquire(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment