0
我正在为我们的生产设施制作QC-softare。我不是机械工程专业的编程专家,但我在这里戴了很多帽子,我喜欢挑战。 无论如何,我一直在阅读很多关于RXTX和示例的教程,并最终做出了一个很好的工作程序。有一些问题需要研究,但总的来说它很有用。 这些问题之一是在哪里我列出“可用端口”,它发现串行通信COMM组合框: 注:main.ports是一个枚举JavaFX上的RxTx - 清除组合框
// SCAN METHOD
public void doScan(ActionEvent event) {
System.out.println("You clicked Scan");
doClearCBox();
main.ports = CommPortIdentifier.getPortIdentifiers();
//CLEAR COMBO BOX EVERY TIME YOU SCAN
while (main.ports.hasMoreElements())
{
CommPortIdentifier curPort = (CommPortIdentifier)main.ports.nextElement();
//get only serial ports
if (curPort.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
main.portMap.put(curPort.getName(), curPort);
portList.getItems().add(curPort.getName());
}
}
}
public void doClearCBox()
{
System.out.println("Clearing combo box and Enumeration");
main.ports = null;
//JUST CLEAR RANDOM VALUES OR SOMETHING?
portList.getSelectionModel().clearSelection(0);
portList.getSelectionModel().clearSelection(1);
portList.getSelectionModel().clearSelection(2);
portList.getSelectionModel().clearSelection();
}
我遇到的问题是,如果按“扫描”按钮不止一次,它基本上重复所有的事情(例如,你会看到一个列表,说COM3,COM3),如果你点击5次,你会看到(COM3,COM3,COM3,COM3,COM3)。 我的doClearCbox方法显然没有做任何事情,我想让它去填充组合框,我无法让它工作。任何帮助非常感谢
非常感谢。我知道我错过了一些简单的事情! –