/** sends a group/type/value command to a KNX/IP router via the Calimero library. */ private void sendKNX(String groupaddress, String type, String value) { if (netLinkIp != null) { try { if (type.equalsIgnoreCase("string")) { pc.write(new GroupAddress(groupaddress), value); } else if (type.equalsIgnoreCase("boolean")) { if (value.equalsIgnoreCase("1")) { pc.write(new GroupAddress(groupaddress), true); } else if (value.equalsIgnoreCase("0")) { pc.write(new GroupAddress(groupaddress), false); } } else if (type.equalsIgnoreCase("int")) { Integer i = new Integer(value); pc.write(new GroupAddress(groupaddress), i, ProcessCommunicator.UNSCALED); } else if (type.equalsIgnoreCase("float")) { Float f = new Float(value); pc.write(new GroupAddress(groupaddress), f); } Logger.getAnonymousLogger() .info("sent value: " + value + " type: " + type + " to " + groupaddress); } catch (Exception e) { Logger.getAnonymousLogger().severe(e.toString()); } } else { Logger.getAnonymousLogger().severe("KNX connection not open"); } }
private void writeToKNX(String itemName, Type value) { Iterable<Datapoint> datapoints = getDatapoints(itemName, value.getClass()); if (datapoints != null) { ProcessCommunicator pc = KNXConnection.getCommunicator(); if (pc != null) { for (Datapoint datapoint : datapoints) { try { pc.write(datapoint, toDPTValue(value, datapoint.getDPT())); logger.debug("Wrote value '{}' to datapoint '{}'", value, datapoint); } catch (KNXException e) { logger.warn( "Value '{}' could not be sent to the KNX bus using datapoint '{}' - retrying one time: {}", new Object[] {value, datapoint, e.getMessage()}); try { // do a second try, maybe the reconnection was successful pc = KNXConnection.getCommunicator(); pc.write(datapoint, toDPTValue(value, datapoint.getDPT())); logger.debug("Wrote value '{}' to datapoint '{}' on second try", value, datapoint); } catch (KNXException e1) { logger.error( "Value '{}' could not be sent to the KNX bus using datapoint '{}' - giving up after second try: {}", new Object[] {value, datapoint, e1.getMessage()}); } } } } } }