使用Javax.comm进行Java串行通信并将变量保存到数组中
好的,我想在java中使用串行通信,使用javax.comm。我要做的就是通过串行通信读取一行数据,并将其保存在一个数组中 例如,每次我按下外部设备上的一个按钮,它都会发送一行像12345这样的随机数字,如果我再次按下它,它会发送另一行数字。我希望我的java程序读取该行,将其保存到一个数组中,然后准备接收另一行数字,并将其保存到另一个数组中以供以后使用 如果有任何提示或有人至少可以帮助我与串行连接将是伟大的。非常感谢。到目前为止,我有以下内容,可以找到端口使用Javax.comm进行Java串行通信并将变量保存到数组中,java,arrays,serial-port,javax.comm,Java,Arrays,Serial Port,Javax.comm,好的,我想在java中使用串行通信,使用javax.comm。我要做的就是通过串行通信读取一行数据,并将其保存在一个数组中 例如,每次我按下外部设备上的一个按钮,它都会发送一行像12345这样的随机数字,如果我再次按下它,它会发送另一行数字。我希望我的java程序读取该行,将其保存到一个数组中,然后准备接收另一行数字,并将其保存到另一个数组中以供以后使用 如果有任何提示或有人至少可以帮助我与串行连接将是伟大的。非常感谢。到目前为止,我有以下内容,可以找到端口 import java.util.E
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
public class PortAccess {
CommPortIdentifier commPortIdentifier;
Enumeration enumeration;
public void fnListPorts() {
try {
enumeration = CommPortIdentifier.getPortIdentifiers();
} catch (Exception e) {
e.printStackTrace();
}
while (enumeration.hasMoreElements()) {
commPortIdentifier = (CommPortIdentifier) enumeration.nextElement();
System.out.println(commPortIdentifier.getName());
}
}
public static void main(String[] args) {
PortAccess portAccess = new PortAccess();
portAccess.fnListPorts();
}
}