Search in sources :

Example 11 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class Config method createConfigWorkingBackup.

private synchronized void createConfigWorkingBackup() {
    try {
        log.info("Create 'Working Backup' [" + configWorkingBackupFile.toString() + "]");
        Files.copy(configFile, configWorkingBackupFile, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        ConfigException ex = new ConfigException("Unable to create 'Working Backup' [" + configWorkingBackupFile.toString() + "]");
        log.error(ex.getMessage(), ex);
    }
}
Also used : ConfigException(io.openems.api.exception.ConfigException) IOException(java.io.IOException)

Example 12 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class Config method createConfigLatestBackup.

private synchronized void createConfigLatestBackup() {
    try {
        log.info("Create 'Latest Backup' [" + configLatestBackupFile.toString() + "]");
        Files.copy(configFile, configLatestBackupFile, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        ConfigException ex = new ConfigException("Unable to create 'Latest Backup' [" + configLatestBackupFile.toString() + "]");
        log.error(ex.getMessage(), ex);
    }
}
Also used : ConfigException(io.openems.api.exception.ConfigException) IOException(java.io.IOException)

Example 13 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class WagoFB method getConfig.

public static HashMap<String, List<String>> getConfig(Inet4Address ip) throws ConfigException {
    if (configCache.containsKey(ip)) {
        return configCache.get(ip);
    } else {
        HashMap<String, List<String>> channels = new HashMap<>();
        String username = "admin";
        String password = "wago";
        int ftpPort = 21;
        URL url;
        Document doc;
        try {
            url = new URL("ftp://" + username + ":" + password + "@" + ip.getHostAddress() + ":" + ftpPort + "/etc/EA-config.xml;type=i");
            URLConnection urlc = url.openConnection();
            InputStream is = urlc.getInputStream();
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            doc = dBuilder.parse(is);
            doc.getDocumentElement().normalize();
        } catch (IOException | SAXException | ParserConfigurationException e) {
            throw new ConfigException(e.getMessage());
        }
        Node wagoNode = doc.getElementsByTagName("WAGO").item(0);
        if (wagoNode != null) {
            HashMap<String, Integer> moduleCounter = new HashMap<String, Integer>();
            Node moduleNode = wagoNode.getFirstChild();
            while (moduleNode != null) {
                if (moduleNode.getNodeType() == Node.ELEMENT_NODE) {
                    NamedNodeMap moduleAttrs = moduleNode.getAttributes();
                    // String article = moduleAttrs.getNamedItem("ARTIKELNR").getNodeValue();
                    String moduletype = moduleAttrs.getNamedItem("MODULETYPE").getNodeValue();
                    if (!moduleCounter.containsKey(moduletype)) {
                        moduleCounter.put(moduletype, 0);
                    }
                    moduleCounter.replace(moduletype, moduleCounter.get(moduletype) + 1);
                    int index = 1;
                    Node channelNode = moduleNode.getFirstChild();
                    while (channelNode != null) {
                        if (channelNode.getNodeType() == Node.ELEMENT_NODE) {
                            NamedNodeMap channelAttrs = channelNode.getAttributes();
                            String channelType = channelAttrs.getNamedItem("CHANNELTYPE").getNodeValue();
                            if (!channels.containsKey(channelType)) {
                                channels.put(channelType, new ArrayList<String>());
                            }
                            String channelName = "";
                            switch(channelType) {
                                case "DO":
                                    channelName = "DigitalOutput_" + moduleCounter.get(channelType) + "_" + index;
                                    break;
                                case "DI":
                                    channelName = "DigitalInput_" + moduleCounter.get(channelType) + "_" + index;
                                    break;
                                default:
                                    LoggerFactory.getLogger(WagoFB.class).debug("ChannelType: " + channelName + " nicht erkannt");
                                    break;
                            }
                            channels.get(channelType).add(channelName);
                            index++;
                        }
                        channelNode = channelNode.getNextSibling();
                    }
                }
                moduleNode = moduleNode.getNextSibling();
            }
        }
        configCache.put(ip, channels);
        return channels;
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) ConfigException(io.openems.api.exception.ConfigException) IOException(java.io.IOException) Document(org.w3c.dom.Document) URL(java.net.URL) URLConnection(java.net.URLConnection) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class FeneconPersistence method dispose.

@Override
protected void dispose() {
    this.reconnectingWebsocket.dispose();
    try {
        Config config = Config.getInstance();
        config.removeOnConfigUpdateListener(this.onConfigUpdate);
    } catch (ConfigException e) {
        log.error(e.getMessage());
    }
}
Also used : Config(io.openems.core.Config) ConfigException(io.openems.api.exception.ConfigException)

Example 15 with ConfigException

use of io.openems.api.exception.ConfigException in project openems by OpenEMS.

the class KebaDevice method send.

/**
 * Send UDP message to Keba EVCS
 *
 * @param s
 * @throws IOException
 * @throws ConfigException
 * @throws InterruptedException
 */
protected void send(String s) throws OpenemsException {
    Optional<Inet4Address> ipOpt = this.ip.valueOptional();
    if (!ipOpt.isPresent()) {
        throw new ConfigException("No IP address configured for Device[" + this.id() + "]");
    } else {
        Inet4Address ip = ipOpt.get();
        byte[] raw = s.getBytes();
        DatagramPacket packet = new DatagramPacket(raw, raw.length, ip, PORT);
        DatagramSocket dSocket = null;
        try {
            dSocket = new DatagramSocket();
            log.info("Sending message to KEBA [" + s + "]");
            dSocket.send(packet);
        } catch (SocketException e) {
            throw new OpenemsException("Unable to open UDP socket for sending [" + s + "] to [" + ip.getHostAddress() + "]: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new OpenemsException("Unable to send [" + s + "] UDP message to [" + ip.getHostAddress() + "]: " + e.getMessage());
        } finally {
            if (dSocket != null) {
                dSocket.close();
            }
        }
    }
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) ConfigException(io.openems.api.exception.ConfigException) OpenemsException(io.openems.common.exceptions.OpenemsException) IOException(java.io.IOException)

Aggregations

ConfigException (io.openems.api.exception.ConfigException)16 InvalidValueException (io.openems.api.exception.InvalidValueException)6 JsonObject (com.google.gson.JsonObject)4 ConfigChannel (io.openems.api.channel.ConfigChannel)4 FunctionalReadChannel (io.openems.api.channel.FunctionalReadChannel)4 ReadChannel (io.openems.api.channel.ReadChannel)4 ThingStateChannels (io.openems.api.channel.thingstate.ThingStateChannels)4 Device (io.openems.api.device.Device)4 ThingInfo (io.openems.api.doc.ThingInfo)4 ModbusDeviceNature (io.openems.impl.protocol.modbus.ModbusDeviceNature)4 ModbusReadLongChannel (io.openems.impl.protocol.modbus.ModbusReadLongChannel)4 DummyElement (io.openems.impl.protocol.modbus.internal.DummyElement)4 ModbusProtocol (io.openems.impl.protocol.modbus.internal.ModbusProtocol)4 UnsignedDoublewordElement (io.openems.impl.protocol.modbus.internal.UnsignedDoublewordElement)4 UnsignedWordElement (io.openems.impl.protocol.modbus.internal.UnsignedWordElement)4 ModbusRegisterRange (io.openems.impl.protocol.modbus.internal.range.ModbusRegisterRange)4 IOException (java.io.IOException)4 LocalTime (java.time.LocalTime)4 JsonArray (com.google.gson.JsonArray)3 JsonElement (com.google.gson.JsonElement)3