我正在尝试编写一个程序来创建用于从 Java 中的串行端口输入中绘制数据的 gui。
我的代码如下:
public class SensorGraph {
static SerialPort chosenPort;
public static void main(String[] args) {
// create and configure the window
JFrame window = new JFrame();
window.setTitle("Sensor Graph GUI");
window.setSize(600,400);
window.setLayout(new BorderLayout());
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create a drop-down boc and connect button , then place them at the top of the window
JComboBox<String> portList = new JComboBox<String>();
JButton connectButton = new JButton("Connect");
JPanel topPanel = new JPanel();
topPanel.add(portList);
topPanel.add(connectButton);
window.add(topPanel,BorderLayout.NORTH);
// populate the drop-down box
SerialPort[] portNames = SerialPort.getCommPorts();
for (int i = 0; i < portNames.length; i++)
portList.addItem(portNames[i].getSystemPortName());
// show the window
window.setVisible(true);
}
}
问题是我想要类似的东西:
我最终得到:
jSerialComm 的库有问题吗?为什么我看不到我的 SerialPorts?
提前致谢!