私はmodbusとシリアル通信の概念全体に慣れていないので、これが本当に初心者の質問であっても、我慢してください!
さて、modbusプロトコルとRS 232ポートを使用して、レジスタに保存されている値を読み取ろうとしています。このコードを書きましたが、シリアルポートが見つかりません"COM 4"
。私は何が間違っているのですか?
String wantedPortName = "COM 4" ;
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null;
while (portIdentifiers.hasMoreElements()) {
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL
&& pid.getName().equals(wantedPortName)) {
portId = pid;
break;
}
}
if (portId == null) {
System.err.println("Could not find serial port " + wantedPortName);
System.exit(1);
}