Search in sources :

Example 1 with ChannelValueContainer

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;
}
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) UnknownHostException(java.net.UnknownHostException) 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 2 with ChannelValueContainer

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;
}
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 3 with ChannelValueContainer

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;
}
Also used : KNXException(tuwien.auto.calimero.exception.KNXException) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 4 with ChannelValueContainer

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;
}
Also used : TypeConversionException(org.openmuc.framework.data.TypeConversionException) ChannelAddress(org.openmuc.framework.driver.iec60870.settings.ChannelAddress) Record(org.openmuc.framework.data.Record) IOException(java.io.IOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 5 with ChannelValueContainer

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;
}
Also used : Type(org.openmuc.jdlms.datatypes.DataObject.Type) DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ChannelAddress(org.openmuc.framework.driver.dlms.settings.ChannelAddress) SetParameter(org.openmuc.jdlms.SetParameter) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ChannelValueContainer(org.openmuc.framework.driver.spi.ChannelValueContainer) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Aggregations

ChannelValueContainer (org.openmuc.framework.driver.spi.ChannelValueContainer)12 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)6 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)6 ModbusException (com.ghgande.j2mod.modbus.ModbusException)3 ModbusIOException (com.ghgande.j2mod.modbus.ModbusIOException)3 ArrayList (java.util.ArrayList)3 ScanException (org.openmuc.framework.config.ScanException)3 Record (org.openmuc.framework.data.Record)3 ModbusChannel (org.openmuc.framework.driver.modbus.ModbusChannel)3 IOException (java.io.IOException)2 SerializationException (org.openmuc.framework.parser.spi.SerializationException)2 BasicDataAttribute (com.beanit.iec61850bean.BasicDataAttribute)1 BdaBitString (com.beanit.iec61850bean.BdaBitString)1 BdaOctetString (com.beanit.iec61850bean.BdaOctetString)1 BdaUnicodeString (com.beanit.iec61850bean.BdaUnicodeString)1 BdaVisibleString (com.beanit.iec61850bean.BdaVisibleString)1 FcModelNode (com.beanit.iec61850bean.FcModelNode)1 ModelNode (com.beanit.iec61850bean.ModelNode)1 ServerModel (com.beanit.iec61850bean.ServerModel)1 ServiceError (com.beanit.iec61850bean.ServiceError)1