public void connectionclose() { try { is.close(); os.close(); dis.close(); dos.close(); sPort.close(); } catch (Exception e) { System.out.println("close" + e); } }
public void connection() { try { portId = CommPortIdentifier.getPortIdentifier("COM10"); sPort = (SerialPort) portId.open("COM10", 1000); sPort.setSerialPortParams(9600, 8, 1, sPort.PARITY_NONE); is = sPort.getInputStream(); os = sPort.getOutputStream(); dis = new DataInputStream(is); dos = new DataOutputStream(os); } catch (NoSuchPortException e) { System.out.println("No Port\n" + e); } catch (PortInUseException e) { System.out.println("Port\n" + e); } catch (UnsupportedCommOperationException e) { System.out.println("Unsupported Problem\n" + e); } catch (IOException e) { System.out.println("IO Problem" + e); } catch (Exception e) { System.out.println("Unknown Problem" + e); } }