Processing 处理过程每隔一次跳过一次

Processing 处理过程每隔一次跳过一次,processing,xbee,Processing,Xbee,我试图将XBee输出的各个部分组合成一个变量,将它们连接起来。我习惯于编码和编译。我遇到的问题是,输出(println)每隔一个字节跳过一次(可能这是错误的术语)。因此,i=4到11的XBee输出应如下所示: 0,19162,0,64121230206(这是从十六进制转换的XBee地址) 但println显示: 19,0121206125,1,0,3(开始进入输出的其他段) 后来,我使用数组尝试了一种不同的路由。它仍然会跳过其他条目,我发现这与我检查I==126有关。有没有其他方法可以做这样的检

我试图将XBee输出的各个部分组合成一个变量,将它们连接起来。我习惯于编码和编译。我遇到的问题是,输出(println)每隔一个字节跳过一次(可能这是错误的术语)。因此,i=4到11的XBee输出应如下所示:

0,19162,0,64121230206(这是从十六进制转换的XBee地址)

但println显示:

19,0121206125,1,0,3(开始进入输出的其他段)

后来,我使用数组尝试了一种不同的路由。它仍然会跳过其他条目,我发现这与我检查I==126有关。有没有其他方法可以做这样的检查

将此绘图部分替换为以下部分。这更容易理解。这是一个具有相同结果的测试

void draw() {
    if (myPort.available() > 21) {
        int[] XBeeAddr = new int[22];
        for (int i=0; i<22; i++) {
            XBeeAddr[i] = myPort.read();
            if (myPort.read == 126) {
                i=0;
            }
        println(XBeeAddr[0] + "," + XBeeAddr[1] + "," + XBeeAddr[2]);
    }
}
void draw(){
如果(myPort.available()>21){
int[]XBeeAddr=新int[22];
对于(int i=0;i 21){
int XBeeAddr1=0;
int XBeeAddr2=0;
int XBeeAddr3=0;
int XBeeAddr4=0;
int XBeeAddr5=0;
int XBeeAddr6=0;
int XBeeAddr7=0;
int XBeeAddr8=0;

对于(int i=0;i它是通过将
myPort.read==126
更改为
如果XBeeAddr[0]!=126,则中断
。然后,如果XBeeAddr[0]==126 println,则执行
操作

import processing.serial.*;
import de.bezier.data.sql.*; // For SQLite database

SQLite db; // For SQLite database
Serial myPort;

void setup() {
    println(Serial.list());
    myPort = new Serial(this, Serial.list()[0],9600);

    // For SQLite database...
    size( 100, 100 );
    db = new SQLite( this, "test.db" );  // Open database file
    if ( db.connect() ) {
        String[] tableNames = db.getTableNames();
        db.query( "SELECT * FROM %s", tableNames[0] );
        while (db.next()) {
            TableOne t = new TableOne();
            db.setFromRow( t );
            println( t );
        }
    }
}

// For SQLite database
class TableOne {
    public String fieldOne;
    public int fieldTwo;
    public String toString () {
        return String.format("fieldOne: %s fieldTwo: %d", fieldOne, fieldTwo);
    }
}

void draw() {
    if (myPort.available() > 21) {
        int XBeeAddr1 = 0;
        int XBeeAddr2 = 0;
        int XBeeAddr3 = 0;
        int XBeeAddr4 = 0;
        int XBeeAddr5 = 0;
        int XBeeAddr6 = 0;
        int XBeeAddr7 = 0;
        int XBeeAddr8 = 0;

        for (int i=0; i<22; i++) {
            int inByte = myPort.read();
            if (inByte == 126) {
                i=0; // This resets the counter if XBee data was incomplete on the last run.
            }
            if (i == 4) {
                XBeeAddr1 = myPort.read();
            }
            if (i == 5) {
                XBeeAddr2 = myPort.read();
            }
            if (i == 6) {
                XBeeAddr3 = myPort.read();
            }
            if (i == 7) {
                XBeeAddr4 = myPort.read();
            }
            if (i == 8) {
                XBeeAddr5 = myPort.read();
            }
            if (i == 9) {
                XBeeAddr6 = myPort.read();
            }
            if (i == 10) {
                XBeeAddr7 = myPort.read();
            }
            if (i == 11) {
                XBeeAddr8 = myPort.read();
            }

            String XBeeAddrAll = XBeeAddr1 + "," + 
                                 XBeeAddr2 + "," + 
                                 XBeeAddr3 + "," + 
                                 XBeeAddr4 + "," + 
                                 XBeeAddr5 + "," + 
                                 XBeeAddr6 + "," + 
                                 XBeeAddr7 + "," + 
                                 XBeeAddr8;
            println(XBeeAddrAll);
        }
    }
}