当我执行 i2c.read(7) 时,结果将存储为字符串。如果我没记错的话,我认为var d = i2c.read(7)
应该将其存储为对象?我仍然不清楚 mraa Javasript i2c API 是什么。i2c.read() 是否应该将结果存储为对象或字符串?如果反对,那我做错了什么?
console.log 输出:
JSON.stringify: "\u00012.974\u0000"
typeof: string
结果: 2.974
代码:
var m = require('mraa');
var i2c = new m.I2c(1);
i2c.address(0x63);
i2c.write("R");
console.log("Reading I2C..");
function readPH() {
var d = i2c.read(7);
console.log("JSON.stringify: " + JSON.stringify(d));
console.log("typeof: " + typeof d);
console.log("Result: " + d);
}
setTimeout(function (e) { readPH(); }, 1000);