Search in sources :

Example 6 with EpsonProjectorException

use of org.openhab.binding.epsonprojector.internal.EpsonProjectorException in project openhab1-addons by openhab.

the class EpsonProjectorTcpConnector method sendMessage.

/**
     * {@inheritDoc}
     */
@Override
public String sendMessage(String data, int timeout) throws EpsonProjectorException {
    if (in == null || out == null) {
        connect();
    }
    try {
        // flush input stream
        if (in.markSupported()) {
            in.reset();
        } else {
            while (in.available() > 0) {
                int availableBytes = in.available();
                if (availableBytes > 0) {
                    byte[] tmpData = new byte[availableBytes];
                    in.read(tmpData, 0, availableBytes);
                }
            }
        }
        return sendMmsg(data, timeout);
    } catch (IOException e) {
        logger.debug("IO error occured...reconnect and resend ones");
        disconnect();
        connect();
        try {
            return sendMmsg(data, timeout);
        } catch (IOException e1) {
            throw new EpsonProjectorException(e);
        }
    } catch (Exception e) {
        throw new EpsonProjectorException(e);
    }
}
Also used : IOException(java.io.IOException) EpsonProjectorException(org.openhab.binding.epsonprojector.internal.EpsonProjectorException) IOException(java.io.IOException) EpsonProjectorException(org.openhab.binding.epsonprojector.internal.EpsonProjectorException)

Aggregations

EpsonProjectorException (org.openhab.binding.epsonprojector.internal.EpsonProjectorException)6 IOException (java.io.IOException)4 Date (java.util.Date)2 CommPort (gnu.io.CommPort)1 CommPortIdentifier (gnu.io.CommPortIdentifier)1 Socket (java.net.Socket)1