2013-04-25 8 views
0

가공 소프트웨어를 사용하여 Arduino의 직렬 포트에서 그래프를 그릴 때 가장 간단한 작업을 수행하고 싶습니다. 나는 일식을 사용한다.완충 대 (' n)는 일식으로 serialevent를 실행하지 않을 것입니다.

자습서에서 플러그인에 대해 말한대로했습니다. 또한 내가 사본이있는 아두 이노 사이트에서 코드 :

import processing.serial.*; 

Serial myPort;  // The serial port 
int xPos = 1;   // horizontal position of the graph 

void setup() { 

    // set the window size: 
    size(400, 300);   

    // List all the available serial ports 
    println(Serial.list()); 

    // I know that the first port in the serial list on my mac 
    // is always my Arduino, so I open Serial.list()[0]. 
    // Open whatever port is the one you're using. 
    myPort = new Serial(this, Serial.list()[0], 9600); 

    // don't generate a serialEvent() unless you get a newline character: 
    myPort.bufferUntil('\n'); 

    // set inital background: 
    background(0); 

} 

void draw() { 
    // everything happens in the serialEvent() 
} 

void serialEvent (Serial myPort) { 

    // get the ASCII string: 
    String inString = myPort.readStringUntil('\n'); 

    if (inString != null) { 

    // trim off any whitespace: 
    inString = trim(inString); 

    // convert to an int and map to the screen height: 
    float inByte = float(inString); 
    inByte = map(inByte, 0, 1023, 0, height); 

    // draw the line: 
    stroke(127,34,255); 
    line(xPos, height, xPos, height - inByte); 

    // at the edge of the screen, go back to the beginning: 
    if (xPos >= width) { 

     xPos = 0; 
     background(0); 

    } 
    else { 

     // increment the horizontal position: 
     xPos++; 

    } 

    } 

} 

가 bufferUntil ('\ n을이')를 serialevent 실행되지 않는 문제가 있습니다.

나는 8 비트 int를 32 비트 int로 설정하려고하는 버그가 있음을 알고있다. 지옥으로 간다.

프로세싱 ide는 위대한 작품입니다. 이클립스는 전혀 작동하지 않습니다. 해결책이 있습니까?

답변

0

bufferUntil ('\ n')은 정수 값을 취합니다. 당신은 그것을 차별 대우하고 있습니다. 적어도 약간의 기이함이 있는지 알아보기 위해 bufferUntil (10)을 시도해보십시오. 그러나 단순히 값을 인쇄하여 myPort에 들어오는 것을 보면서 개행 문자를 보낼 때 어떤 결과가 나오는지보아야합니다.

+0

글쎄, 나는 또한 캐스팅을 시도했는데 아무것도주지 않았고 또한 10 번이나 아무것도주지 않았다. 문제는 직렬 이벤트가 트리거를 실행하지 않는다는 것이다. 이것은 arduino 모니터 양식 arduino ide 값을 인쇄 할 때 새로운 라인을 전송한다. 물론 내가 말한대로 가공 ide도 잘 작동합니다. – kyrpav

+0

println (myPort.readStringUntil ('\ n'))); 또한 버퍼 until() 후에 null – kyrpav

+0

을 인쇄하지만 로그 할 때보고있는 데이터는 무엇입니까? –