Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法打开文件"/开发/ttyO2“;尝试使用Beaglebone Black上的串行端口时_Javascript_Beagleboneblack_Uart - Fatal编程技术网

Javascript 无法打开文件"/开发/ttyO2“;尝试使用Beaglebone Black上的串行端口时

Javascript 无法打开文件"/开发/ttyO2“;尝试使用Beaglebone Black上的串行端口时,javascript,beagleboneblack,uart,Javascript,Beagleboneblack,Uart,我正在尝试使用以下代码打开beagle bone上的串行端口2: var b = require('bonescript'); var x = '/dev/ttyO2'; var SerialPort = require("serialport").SerialPort; var serialPort = new SerialPort('/dev/ttyO2', { baudrate: 115200, parser: b.serialParsers.readline("\n")

我正在尝试使用以下代码打开beagle bone上的串行端口2:

    var b = require('bonescript');
var x = '/dev/ttyO2';
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort('/dev/ttyO2', {
  baudrate: 115200,

  parser: b.serialParsers.readline("\n")

});
完整代码:

var b = require('bonescript');
var x = '/dev/ttyO2';
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort('/dev/ttyO2', {
  baudrate: 115200,

  parser: b.serialParsers.readline("\n")

});

b.pinMode("P9_17", b.OUTPUT);

var countTry =2;
var i = 0; // to loop over the array
var waiting_interval = 3000; // waiting for every slave to reply
var deli;

var slaves = ["S1", "S2" , "S3", "S4", "S5", "S6"];
var counter=[0 , 0 , 0 , 0 ,0 ,0];
var slave_exists = false;

serialPort.on('open',function onSerialOpen(){
    console.log("opened");
    serialPort.on('data', function listenToSlaves(data){
        i--;
            if(data.search("END" + slaves[i]) ==0){
            console.log("ENDED");
            slave_exists = true;
            counter[i]=0;
        }
        else{
      //  if(data!="END" + slaves[i]){
        if(data.search("END" + slaves[i])!==0){
            deli = data.indexOf(":");
            var parameter = data.substring(0, deli);
            var value = data.substring(deli +1);
            console.log("parameter is: " + parameter + " - Value is: " + value);
        }
        }

        if(slave_exists){
            counter[i] =0;
        }
        i++;
        });
    writeToSlaves();
});

function writeToSlaves(){
   //If the previous slave (the slave before the one I am sending to 
   //in the next step doesnt exist, add the counter or consideer 
   //it not existing)
    if(!slave_exists){
        counter[i-1]+=1;
        if(counter[i-1]>=countTry){
            console.log("--------counter[" + i + "]: " + counter[i]);
            // in case that the slave returned no data after trying
           //to send him several times
            console.log(slaves[i-1] + " doesn't exist");
        }
    }
    //sending to the following slave
    b.digitalWrite("P9_17", b.HIGH);    
    serialPort.write(slaves[i], function(){ slave_exists = false;});
    b.digitalWrite("P9_17", b.LOW);
    console.log("I wrote to slave: " + i);
    if(i<slaves.length - 1) i++;
    else i=0;
    setTimeout(writeToSlaves, waiting_interval);
}
问题解决了。 在/boot/uboot/uEnv.txt中,更新行:“#cape_enable=capemgr.enable_partno=”to be: “cape\U enable=capemgr.enable\U partno=BB-UART1、BB-UART2、BB-UART4、BB-UART5” 或者将最后一行添加到提到的文件中。在某些情况下,您需要尝试这一行,而不是前面提到的: “optargs=capemgr.enable_partno=BB-UART1、BB-UART2、BB-UART4、BB-UART5”(这是我的情况,但它禁用了我的BBB的HDMI接口)

您可以指定要启用的UART。

    var b = require('bonescript');
    var rxport = '/dev/ttyO2';
    var txport = '/dev/ttyO2';
    var options = { baudrate: 115200, parity: 'even', parser: b.serialParsers.readline('\n') };
    var teststring = "This is the string I'm sending out as a test";

    b.serialOpen(rxport, options, onRxSerial);

    function onRxSerial(x) {

        console.log('rx.eventrx= ' + x.event);
        if(x.err) throw('***FAIL*** ' + JSON.stringify(x));
        if(x.event == 'open') {
            //readReapeatedly();
             b.serialOpen(txport, options, onTxSerial);

        }
        if(x.event == 'data') {
            console.log("I am receiving on rxport");
            console.log('rx (' + x.data.length +
                        ') = ' + x.data.toString('ascii'));

        }
    }

    function onTxSerial(x) {
        console.log('tx.event = ' + x.event);
        if(x.err) throw('***FAIL*** ' + JSON.stringify(x));
        if(x.event == 'open') {
            writeRepeatedly();
        }
        if(x.event == 'data') {

            // console.log('tx (' + x.data.length +
            //             ') = ' + x.data.toString('ascii'));
            console.log(x.data);
        }
    }

    function printJSON(x) {
        console.log(JSON.stringify(x));
    }

    function writeRepeatedly() {
        console.log("write to serial");
        b.serialWrite(txport, teststring, onSerialWrite);
        console.log("I have sent data");
    }


    function onSerialWrite(x) {
        console.log("Iam in the onSerialWrite function");
        if(x.err) console.log('onSerialWrite err = ' + x.err);
        if(x.event == 'callback') {setTimeout(writeRepeatedly, 5000);
        console.log("HERE");
        }
    }