Examples of CULDeviceException


Examples of org.openhab.io.transport.cul.CULDeviceException

  protected void openHardware() throws CULDeviceException {
    log.debug("Opening serial CUL connection for " + deviceName);
    try {
      CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(deviceName);
      if (portIdentifier.isCurrentlyOwned()) {
        throw new CULDeviceException("The port " + deviceName + " is currenty used by "
            + portIdentifier.getCurrentOwner());
      }
      CommPort port = portIdentifier.open(this.getClass().getName(), 2000);
      if (!(port instanceof SerialPort)) {
        throw new CULDeviceException("The device " + deviceName + " is not a serial port");
      }
      serialPort = (SerialPort) port;
      serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, parityMode);
      is = serialPort.getInputStream();
      os = serialPort.getOutputStream();
      br = new BufferedReader(new InputStreamReader(is));
      bw = new BufferedWriter(new OutputStreamWriter(os));

      serialPort.notifyOnDataAvailable(true);
      log.debug("Adding serial port event listener");
      serialPort.addEventListener(this);
    } catch (NoSuchPortException e) {
      throw new CULDeviceException(e);
    } catch (PortInUseException e) {
      throw new CULDeviceException(e);
    } catch (UnsupportedCommOperationException e) {
      throw new CULDeviceException(e);
    } catch (IOException e) {
      throw new CULDeviceException(e);
    } catch (TooManyListenersException e) {
      throw new CULDeviceException(e);
    }

  }
View Full Code Here

Examples of org.openhab.io.transport.cul.CULDeviceException

       URI uri = new URI("cul://" + deviceName);
        String host = uri.getHost();
        int port = uri.getPort()==-1?CUN_DEFAULT_PORT:uri.getPort();

        if (uri.getHost() == null || uri.getPort() == -1) {
          throw new CULDeviceException("Could not parse host:port from "+deviceName);
        }
      log.debug("Opening network CUL connection to " + host+":"+port);
      socket=new Socket(host, port);
      log.info("Connected network CUL connection to " + host+":"+port);
      is = socket.getInputStream();
      os = socket.getOutputStream();
      br = new BufferedReader(new InputStreamReader(is));
      bw = new BufferedWriter(new OutputStreamWriter(os));

      log.debug("Starting network listener Thread");
      receiveThread=new ReceiveThread();
      receiveThread.start();
    } catch (IOException e) {
      throw new CULDeviceException(e);
    } catch (URISyntaxException e) {
      throw new CULDeviceException("Could not parse host:port from "+deviceName, e);
    }

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.