0
我写了一个名为ArduinoSerial
的类来实现SerialPortEventListener
。覆盖serialEvent两次
我使用这个类作为一个库,我导入到另一个名为ArduinoGUI
的程序中,该程序创建一个带有一系列复选框的swing GUI。
当我想写入串口我有一个私人成员变量ArduinoGUI
类私人ArduinoSerial
arduino;
我打电话给arduino.output.write(byte b);
函数,它工作正常。
问题是内部ArduinoSerial
类覆盖了读取函数,并且当前将输出吐出到system.out。
@Override
public synchronized void serialEvent(SerialPortEvent oEvent) {
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
String inputLine=input.readLine();
System.out.println(inputLine);
} catch (Exception e) {
System.err.println(e.toString());
System.out.println("But nothing much to worry about.");
}
}
// Ignore all the other eventTypes, but you should consider the other ones.
}
这不是然而,我想要什么,我想阅读的串行数据转换为ArduinoGUI
类中的字节数组,但我不知道如何重写此方法的第二时间和/或写一个事件监听器,用于获取串口上的数据,同时让ArduinoSerial
类不首先读取并放弃缓冲区。
的一个问题是:公共类ArduinoGUI已经扩展了javax.swing.JFrame,它是否可以扩展ArduinoSerial? – Zac 2013-03-19 15:26:45
您不能扩展2个类,只有1个可用。 – 2013-03-19 15:32:09
如何解决这个问题,我创建了ArduinoSerial作为实现SerialPortEventListener的抽象类,但不是serialEvent方法。我的子类已经扩展了jFrame,它需要创建GUI,我怎样才能让它扩展ArduinoSerial,以便它可以实现缺少的SerialPortEventListener? – Zac 2013-03-20 10:11:55