我正在使用RXTX与串口通信。
在open方法中,我给出一个appname,它是" Test"
public void connect(String portName) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if (portIdentifier.isCurrentlyOwned()) {
System.out.println("port in use");
} else {
SerialPort serialPort = (SerialPort) portIdentifier.open("Test", 2000);
serialPort.setSerialPortParams( 9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_ODD);
CommPortSender.setWriterStream(serialPort.getOutputStream());
new CommPortReceiver(serialPort.getInputStream()).start();
// System.out.println(serialPort.get);
}
}
这是参数的细节:
public CommPort open(java.lang.String appname,int timeout)
throws PortInUseException
appname - 拨打此电话的应用程序的名称。该名称将成为该端口的所有者。在解决所有权争用时很有用。
timeout - 阻止等待端口打开的时间(以毫秒为单位)。
如何获取我在open方法中提供的appname 以下功能:
private void onMessage() {
if (tail!=0) {
String message = getMessage(buffer, tail);
System.out.println("received message: " + message);
tail = 0;
}
}
我搜索谷歌,但不知道如何描述这个问题。请帮忙。 在此先感谢,请原谅我可怜的英语。