use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class ModbusRTUTCPConnection 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.ChannelValueContainer 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.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class KnxConnection method write.
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException, ConnectionException {
for (ChannelValueContainer container : containers) {
KnxGroupDP groupDP = null;
try {
if (container.getChannelHandle() == null) {
groupDP = createKnxGroupDP(container.getChannelAddress());
logger.debug("New datapoint: " + groupDP);
container.setChannelHandle(groupDP);
} else {
groupDP = (KnxGroupDP) container.getChannelHandle();
}
groupDP.getKnxValue().setOpenMucValue(container.getValue());
boolean state = write(groupDP, KnxDriver.timeout);
if (state) {
container.setFlag(Flag.VALID);
} else {
container.setFlag(Flag.UNKNOWN_ERROR);
}
} catch (ArgumentSyntaxException e) {
container.setFlag(Flag.DRIVER_ERROR_CHANNEL_ADDRESS_SYNTAX_INVALID);
logger.error(e.getMessage());
} catch (KNXException e) {
logger.warn(e.getMessage());
}
}
return null;
}
use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class Iec60870Connection method write.
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws ConnectionException {
for (ChannelValueContainer channelValueContainer : containers) {
ChannelAddress channelAddress;
try {
channelAddress = new ChannelAddress(channelValueContainer.getChannelAddress());
Record record = new Record(channelValueContainer.getValue(), System.currentTimeMillis(), Flag.VALID);
Iec60870DataHandling.writeSingleCommand(record, channelAddress, clientConnection);
channelValueContainer.setFlag(Flag.VALID);
} catch (ArgumentSyntaxException e) {
channelValueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_ADDRESS_SYNTAX_INVALID);
logger.error(e.getMessage());
throw new UnsupportedOperationException(e);
} catch (IOException e) {
channelValueContainer.setFlag(Flag.CONNECTION_EXCEPTION);
throw new ConnectionException(e);
} catch (TypeConversionException e) {
channelValueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_VALUE_TYPE_CONVERSION_EXCEPTION);
logger.error(e.getMessage());
} catch (UnsupportedOperationException e) {
channelValueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_ADDRESS_SYNTAX_INVALID);
logger.error(e.getMessage());
throw e;
}
}
return null;
}
use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class WriteHandle method createSetParamsFor.
private static List<SetParameter> createSetParamsFor(List<ChannelValueContainer> writeList) throws ConnectionException {
List<SetParameter> setParams = new ArrayList<>(writeList.size());
for (ChannelValueContainer channelContainer : writeList) {
try {
ChannelAddress channelAddress = new ChannelAddress(channelContainer.getChannelAddress());
Type type = channelAddress.getType();
if (type == null) {
String msg = MessageFormat.format("Can not set attribute with address {0} where the type is unknown.", channelAddress);
throw new ConnectionException(msg);
}
DataObject newValue = createDoFor(channelContainer, type);
AttributeAddress address = channelAddress.getAttributeAddress();
SetParameter setParameter = new SetParameter(address, newValue);
setParams.add(setParameter);
} catch (ArgumentSyntaxException e) {
throw new ConnectionException(e);
}
}
return setParams;
}
Aggregations