A little more on the above in hopes that Jason will see this! Here is a code sample using the i2c library from korevec that works:
var i2c = require('i2c');
var address = 0x6A;
var device = {device: '/dev/i2c-1', debug: false};
var command = 0x80;
var wire = new i2c(address, device);
wire.readBytes(0x80, 4, function(err, res) {
var voltageIn = (res[0] << 8) + res[1];
voltageIn = 5*(voltageIn / 2048);
console.log(res);
console.log(voltageIn);
});
Here is the output from the above:
<Buffer 00 01 80 80>
0.00244140625
Here is my conversion of the above to use the bonescript version:
var b = require('bonescript');
var address = 0x6A;
var port = '/dev/i2c-1';
var command = 0x80;
b.i2cOpen(port, address);
b.i2cReadBytes(port, command, 4, function(data) {
console.log(data);
console.log(data.res);
var voltageIn = (data.res[0] << 8) + data.res[1];
console.log(voltageIn);
console.log("------------");
});
Here is the output from the above:
{ err: [Error: Error reading length of bytes],
res: <Buffer 18 e6>,
event: 'callback' }
<Buffer 18 e6>
6374
------------
{ event: 'return', return: <Buffer 18 e6> }
undefined
var voltageIn = (data.res[0] << 8) + data.res[1];
^
TypeError: Cannot read property '0' of undefined
I presume that I am doing something wrong but have not been able to find an example that might help me decode the mystery.
Cheers,
Will