Beaglebone Black bonescript ain问题

时间:2018-03-06 18:27:37

标签: javascript beagleboneblack

我有一个在Beaglebone Black上运行的脚本,它根据热电偶的输入切换电机。在将所有内容放入一个盒子之前,这个脚本工作得很好,但现在它弹出以下错误:

4:4:91-ti-r133
/usr/local/lib/node_modules/bonescript/src/index.js:234
    if(typeof pin.ain != 'undefined') {
                 ^

TypeError: Cannot read property 'ain' of undefined
  at Object.f.digitalRead (/usr/local/lib/node_modules/bonescript/src/index.js:234:18)
  at Object.<anonymous> (/var/lib/cloud9/Relays/Relays.js:9:16)
  at Module._compile (module.js:570:32)
  at Object.Module._extensions..js (module.js:579:10)
  at Module.load (module.js:487:32)
  at tryModuleLoad (module.js:446:12)
  at Function.Module._load (module.js:438:3)
  at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
  at ontimeout (timers.js:386:11)
  at tryOnTimeout (timers.js:250:5)
  at Timer.listOnTimeout (timers.js:214:5)

我检查了所有连接,电阻和电压,一切似乎都正确连接。如果我能解释这个错误,它将帮助我诊断问题。这是代码:

var b = require('bonescript');
var c = require('bonescript');
var d = require('bonescript');
var e = require('bonescript');
var f = require('bonescript');

var state1 = b.low;
var state2 = c.low;
var state3 = e.digitalRead('P9.23', e.INPUT)
var state4 = f.digitalRead('P9.25', f.INPUT)

var temp = d.analogRead('P9_37');

d.analogRead('P9_37', printStatus);
function printStatus(x) {
    console.log('temp = ' + x.value);
}

b.pinMode("P9_15", b.OUTPUT);
b.digitalWrite("P9_15", b.LOW);
c.pinMode("P9_12", b.OUTPUT);
c.digitalWrite("P9_12", b.LOW);
e.pinMode("P8_7", b.OUTPUT);
e.digitalWrite("P8_7", b.LOW);

setInterval(toggle1, 10000);
setInterval(toggle2, 200);
setInterval(toggle3, 1000);

function toggle3() {
    temp = d.analogRead('P9_37');
    d.analogRead('P9_37', printStatus);
}

function toggle1() {
    if(temp<0.74 && temp>0.01 && state3 == c.HIGH) {
        state1 = b.HIGH;
        state2 = c.LOW; //If temp is LT 1190 C
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(temp>0.76 && state3 == c.HIGH) {//If temp is GT 1210 C
        state1 = b.LOW;
        state2 = c.HIGH;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(temp<0.74 && temp>0.01 && state4 == c.HIGH) {
        state1 = b.LOW;
        state2 = c.HIGH; //If temp is LT 1190 C
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(temp>0.76 && state4 == c.HIGH) {//If temp is GT 1210 C
        state1 = b.HIGH;
        state2 = c.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else {//Else do nothing
        state2 = c.LOW;
        b.digitalWrite("P9_15", state2);
    }

}

function toggle2() {
    if(state1 == b.HIGH) { //If Temp was LT 1190 C
        state1 = b.LOW;
        state2 = c.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else if(state1 == b.LOW) { //If temp was GT 1210 C
        state2 = c.LOW;
        state1 = b.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);
    }
    else { //Else do nothing
        state1 = b.LOW;
        state2 = c.LOW;
        b.digitalWrite("P9_15", state1);
        b.digitalWrite("P9_12", state2);

    }

}

return 0;

任何建议都表示赞赏。我无法在其他任何地方找到这个确切的错误,类似的错误似乎是无关的。谢谢!

1 个答案:

答案 0 :(得分:0)

这结果是一个语法问题。这是正确的语法:

var state1 = b.low;
var state2 = c.low;

setInterval(check,1000);

function check(){
GPIO1.digitalRead('P8_13');
GPIO2.digitalRead('P8_19');
}

var temp = d.analogRead('P9_37');

d.analogRead('P9_37', printStatus);
function printStatus(x) {
    console.log('temp = ' + x.value);
}

b.pinMode("P9_15", b.OUTPUT);
b.digitalWrite("P9_15", b.LOW);
c.pinMode("P9_12", b.OUTPUT);
c.digitalWrite("P9_12", b.LOW);
e.pinMode("P8_7", b.OUTPUT);
e.digitalWrite("P8_7", b.LOW);