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");
}
}
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations