【问题标题】:bufferuntil('\n) wont trigger serialevent proccessing with eclipsebufferutil('\and) 不会用 eclipse 触发 serialevent 处理
【发布时间】:2013-04-25 17:56:00
【问题描述】:

我想做最简单的事情,用处理软件从 Arduino 的串行端口绘制图形。我用eclipse。

我按照教程所说的插件做了。我还复制了 arduino 网站上的代码:

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 效果很好。Eclipse 根本不触发。有什么解决方案吗?

【问题讨论】:

    标签: eclipse arduino processing processing-ide


    【解决方案1】:

    请注意,bufferUntil('\n') 采用整数值。你给它一个字符。至少尝试 bufferUntil(10) 看看那里是否发生了一些奇怪的事情,但可能值得简单地打印在 myPort 上看到的值,看看当你发送换行符时会发生什么。

    【讨论】:

    • 好吧,我知道我也尝试过投射,但我什么也没给 10 也什么都没有。问题是串行事件永远不会运行它永远不会触发。当我检查 arduinos 监视器表单时,它会发送新行arduino ide 它可以正确打印值。我所说的处理 ide 也可以正常工作。
    • println(myPort.readStringUntil('\n'));在缓冲区 until() 打印 null
    • 但是当您记录它们时,您看到的数据是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    相关资源
    最近更新 更多