0

我想创建一个包含串行端口列表的“列表框”(使用 controlP5 GUI 库):目标是创建一个使用处理与 Arduino Uno 通信的独立应用程序,独立于我要使用的操作系统( win、mac 或 linux),并选择(使用“列表框”)正确的串行端口以与 Arduino 通信。可能吗??

4

1 回答 1

2
ControlP5 cp5 = new ControlP5(this);
ListBox listBox = cp5.addListBox("serialPorts");
Serial serial;
String[] ports = Serial.list();
for (int i=0; i<ports.length; i++) {
    listBox.addItem(ports[i]);
}

void controlEvent(ControlEvent theEvent) {
    if(theEvent.isGroup() && theEvent.name().equals("myList")){
        int val = (int)theEvent.group().value();
        serial = new Serial(this, ports[val], 9600);
    }
}

未经测试,但这是基本思想......

于 2012-10-06T05:28:44.100 回答