Search in sources :

Example 6 with ConnectionException

use of org.openmuc.framework.driver.spi.ConnectionException in project OpenMUC by isc-konstanz.

the class ModbusRTUTCPConnection method connect.

@Override
public void connect() throws ConnectionException {
    if (connection != null && !connection.isConnected()) {
        try {
            connection.connect();
        } catch (Exception e) {
            throw new ConnectionException(e);
        }
        transaction = new ModbusRTUTCPTransaction(connection);
        setTransaction(transaction);
        if (!connection.isConnected()) {
            throw new ConnectionException("unable to connect");
        }
    }
}
Also used : ModbusRTUTCPTransaction(org.openmuc.framework.driver.modbus.rtutcp.bonino.ModbusRTUTCPTransaction) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) ScanException(org.openmuc.framework.config.ScanException) UnknownHostException(java.net.UnknownHostException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ModbusIOException(com.ghgande.j2mod.modbus.ModbusIOException) ModbusException(com.ghgande.j2mod.modbus.ModbusException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 7 with ConnectionException

use of org.openmuc.framework.driver.spi.ConnectionException in project OpenMUC by isc-konstanz.

the class ModbusTCPConnection method write.

@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException, ConnectionException {
    for (ChannelValueContainer container : containers) {
        ModbusChannel channel = getModbusChannel(container.getChannelAddress(), EAccess.WRITE);
        try {
            writeChannel(channel, container.getValue());
            container.setFlag(Flag.VALID);
        } catch (ModbusIOException e) {
            logger.error("ModbusIOException while writing channel:" + channel.getChannelAddress(), e);
            disconnect();
            throw new ConnectionException("Try to solve issue with reconnect.");
        } catch (ModbusException e) {
            logger.error("ModbusException while writing channel: " + channel.getChannelAddress(), e);
            container.setFlag(Flag.DRIVER_ERROR_CHANNEL_NOT_ACCESSIBLE);
        } catch (Exception e) {
            logger.error("Exception while writing channel: " + channel.getChannelAddress(), e);
            container.setFlag(Flag.UNKNOWN_ERROR);
        }
    }
    return null;
}
Also used : ModbusChannel(org.openmuc.framework.driver.modbus.ModbusChannel) ModbusIOException(com.ghgande.j2mod.modbus.ModbusIOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) ScanException(org.openmuc.framework.config.ScanException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ModbusIOException(com.ghgande.j2mod.modbus.ModbusIOException) ModbusException(com.ghgande.j2mod.modbus.ModbusException) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) ModbusException(com.ghgande.j2mod.modbus.ModbusException)

Example 8 with ConnectionException

use of org.openmuc.framework.driver.spi.ConnectionException in project OpenMUC by isc-konstanz.

the class ModbusTCPConnection method read.

@Override
public Object read(List<ChannelRecordContainer> containers, Object containerListHandle, String samplingGroup) throws UnsupportedOperationException, ConnectionException {
    // reads channels one by one
    if (samplingGroup.isEmpty()) {
        for (ChannelRecordContainer container : containers) {
            // TODO consider retries in sampling timeout (e.g. one time 12000 ms or three times 4000 ms)
            // FIXME quite inconvenient/complex to get the timeout from config, since the driver doesn't know the
            // device id!
            long receiveTime = System.currentTimeMillis();
            ModbusChannel channel = getModbusChannel(container.getChannelAddress(), EAccess.READ);
            Value value;
            try {
                value = readChannel(channel);
                if (logger.isTraceEnabled()) {
                    logger.trace("Value of response: {}", value.toString());
                }
                container.setRecord(new Record(value, receiveTime));
            } catch (ModbusIOException e) {
                logger.error("ModbusIOException while reading channel:" + channel.getChannelAddress() + " used timeout: " + timeoutMs + " ms", e);
                disconnect();
                throw new ConnectionException("Try to solve issue with reconnect.");
            } catch (ModbusException e) {
                logger.error("ModbusException while reading channel: " + channel.getChannelAddress(), e);
                container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_NOT_ACCESSIBLE));
            } catch (Exception e) {
                // catch all possible exceptions and provide info about the channel
                logger.error("Exception while reading channel: " + channel.getChannelAddress(), e);
                container.setRecord(new Record(Flag.UNKNOWN_ERROR));
            }
            if (!connection.isConnected()) {
                throw new ConnectionException("Lost connection.");
            }
        }
    } else // reads whole samplingGroup at once
    {
        readChannelGroupHighLevel(containers, containerListHandle, samplingGroup);
        if (!connection.isConnected()) {
            throw new ConnectionException("Lost connection.");
        }
    }
    return null;
}
Also used : ModbusChannel(org.openmuc.framework.driver.modbus.ModbusChannel) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) Value(org.openmuc.framework.data.Value) Record(org.openmuc.framework.data.Record) ModbusIOException(com.ghgande.j2mod.modbus.ModbusIOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) ScanException(org.openmuc.framework.config.ScanException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ModbusIOException(com.ghgande.j2mod.modbus.ModbusIOException) ModbusException(com.ghgande.j2mod.modbus.ModbusException) ModbusException(com.ghgande.j2mod.modbus.ModbusException)

Example 9 with ConnectionException

use of org.openmuc.framework.driver.spi.ConnectionException in project OpenMUC by isc-konstanz.

the class RestConnection method connect.

public RestConnection connect() throws ConnectionException {
    try {
        connection = open("rest/connect/");
        connection.connect();
        verifyResponseCode(connection);
    } catch (IOException e) {
        throw new ConnectionException(e.getMessage());
    }
    return this;
}
Also used : IOException(java.io.IOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 10 with ConnectionException

use of org.openmuc.framework.driver.spi.ConnectionException in project OpenMUC by isc-konstanz.

the class RestConnection method get.

public String get(String suffix) throws ConnectionException {
    try {
        connection = open("rest/channels/" + suffix);
        verifyResponseCode(connection);
        return readResponse(connection);
    } catch (IOException e) {
        throw new ConnectionException(e.getMessage());
    }
}
Also used : IOException(java.io.IOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Aggregations

ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)55 IOException (java.io.IOException)23 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)16 ScanException (org.openmuc.framework.config.ScanException)14 Record (org.openmuc.framework.data.Record)11 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)10 ModbusException (com.ghgande.j2mod.modbus.ModbusException)9 ModbusIOException (com.ghgande.j2mod.modbus.ModbusIOException)9 ArrayList (java.util.ArrayList)9 ModbusChannel (org.openmuc.framework.driver.modbus.ModbusChannel)6 ChannelValueContainer (org.openmuc.framework.driver.spi.ChannelValueContainer)6 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)5 ServiceError (com.beanit.iec61850bean.ServiceError)4 Connect (org.openmuc.framework.driver.annotation.Connect)4 FcModelNode (com.beanit.iec61850bean.FcModelNode)3 InterruptedIOException (java.io.InterruptedIOException)3 SQLException (java.sql.SQLException)3 Value (org.openmuc.framework.data.Value)3 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)3 BasicDataAttribute (com.beanit.iec61850bean.BasicDataAttribute)2