【发布时间】:2018-01-14 08:03:37
【问题描述】:
我的 RXTX 库和 Arduino 有问题,我正在尝试将从 Arduino 串行输出获得的变量存储到它在我的 Java 代码中声明的变量中,然后使用它来执行一些操作。这是我用来从 Arduino 读取串行输出的代码的一部分。
现在的问题是,如何从这段代码开始存储这些数据?
我需要存储从超声波传感器获得的数据并让它显示在我的 Java GUI 中。
public void serialEvent(SerialPortEvent evt) {
if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
byte singleData = (byte)input.read();
if (singleData != NEW_LINE_ASCII) {
logText = new String(new byte[] { singleData });
finestra.logArea.append(logText);
} else {
finestra.logArea.append("\n");
}
}
catch (Exception e) {
logText = "Failed to read data. (" + e.toString() + ")";
finestra.logArea.setForeground(Color.red);
finestra.logArea.append(logText + "\n");
}
}
这部分代码只是为了读取来自串行的所有内容。
【问题讨论】:
标签: java serialization arduino rxtx