本文整理匯總了Java中gnu.io.CommPort.close方法的典型用法代碼示例。如果您正苦於以下問題:Java CommPort.close方法的具體用法?Java CommPort.close怎麽用?Java CommPort.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gnu.io.CommPort
的用法示例。
在下文中一共展示了CommPort.close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleEvent
import gnu.io.CommPort; //導入方法依賴的package包/類
public void handleEvent() {
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(SerialConf.WINDOWS_PORT);
if (portId.isCurrentlyOwned()) {
System.out.println("Port busy!");
} else {
CommPort commPort = portId.open("whatever it's name", SerialConf.TIME_OUT);
if (commPort instanceof SerialPort) {
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(SerialConf.BAUD,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_EVEN);
in = serialPort.getInputStream();
serialPort.notifyOnDataAvailable(true);
serialPort.addEventListener(this);
} else {
commPort.close();
System.out.println("the port is not serial!");
}
}
} catch (Exception e) {
serialPort.close();
System.out.println("Error: SerialOpen!!!");
e.printStackTrace();
}
}
示例2: closeImpl
import gnu.io.CommPort; //導入方法依賴的package包/類
/**
* Closes the connection.
*/
@Override
protected void closeImpl()
{
//remove reference
CommPort port=this.commPort;
this.commPort=null;
//close connection
port.close();
}
示例3: main
import gnu.io.CommPort; //導入方法依賴的package包/類
public static void main(String... args) {
System.out.println(System.getProperty("java.io.tmpdir"));
System.out.println(System.getProperty("sun.arch.data.model"));
System.out.println(System.getProperty("os.arch"));
System.out.println(System.getProperty("os.name"));
System.out.println(System.getProperty("os.version"));
String[] portList = getPortList();
System.out.print(portList.length);
System.out.print(" port(ow):");
for (int i = 0; i < portList.length; i++) {
System.out.print(portList[i] + " ");
}
System.out.println();
System.out.println("*************************************************");
portList = getSerialPortList();
System.out.print(portList.length);
System.out.println(" port(ow) szeregowych:");
for (int i = 0; i < portList.length; i++) {
System.out.print(portList[i] + " otwieram ");
try {
CommPort p = getSerialPort(portList[i]);
p.close();
System.out.print("OK");
} catch (IOException e) {
System.out.print("nie udało się: " + e.getMessage());
}
System.out.println();
}
System.out.println();
portList = getParallelPortList();
System.out.print(portList.length);
System.out.println(" port(ow) rownoleglych:");
for (int i = 0; i < portList.length; i++) {
System.out.print(" " + portList[i]);
}
System.out.println();
}