use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.
the class StuderHandler method connectEndpoint.
/**
* Get a reference to the modbus endpoint
*/
private void connectEndpoint() {
if (comms != null) {
return;
}
ModbusEndpointThingHandler slaveEndpointThingHandler = getEndpointThingHandler();
if (slaveEndpointThingHandler == null) {
@SuppressWarnings("null") String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Bridge '%s' is offline", label));
logger.debug("No bridge handler available -- aborting init for {}", label);
return;
}
comms = slaveEndpointThingHandler.getCommunicationInterface();
if (comms == null) {
@SuppressWarnings("null") String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Bridge '%s' not completely initialized", label));
logger.debug("Bridge not initialized fully (no endpoint) -- aborting init for {}", this);
return;
}
}
use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.
the class StuderHandler method getEndpointThingHandler.
/**
* Get the endpoint handler from the bridge this handler is connected to
* Checks that we're connected to the right type of bridge
*
* @return the endpoint handler or null if the bridge does not exist
*/
@Nullable
private ModbusEndpointThingHandler getEndpointThingHandler() {
Bridge bridge = getBridge();
if (bridge == null) {
logger.debug("Bridge is null");
return null;
}
if (bridge.getStatus() != ThingStatus.ONLINE) {
logger.debug("Bridge is not online");
return null;
}
ThingHandler handler = bridge.getHandler();
if (handler == null) {
logger.debug("Bridge handler is null");
return null;
}
if (handler instanceof ModbusEndpointThingHandler) {
ModbusEndpointThingHandler slaveEndpoint = (ModbusEndpointThingHandler) handler;
return slaveEndpoint;
} else {
logger.debug("Unexpected bridge handler: {}", handler);
return null;
}
}
use of org.openhab.binding.modbus.handler.ModbusEndpointThingHandler in project openhab-addons by openhab.
the class StiebelEltronHandler method startUp.
/*
* This method starts the operation of this handler Connect to the slave bridge
* Start the periodic polling1
*/
private void startUp() {
if (comms != null) {
return;
}
ModbusEndpointThingHandler slaveEndpointThingHandler = getEndpointThingHandler();
if (slaveEndpointThingHandler == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "Bridge is offline");
return;
}
try {
slaveId = slaveEndpointThingHandler.getSlaveId();
comms = slaveEndpointThingHandler.getCommunicationInterface();
} catch (EndpointNotInitializedException e) {
// this will be handled below as endpoint remains null
}
if (comms == null) {
@SuppressWarnings("null") String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Bridge '%s' not completely initialized", label));
return;
}
if (config == null) {
logger.debug("Invalid comms/config/manager ref for stiebel eltron handler");
return;
}
if (systemInformationPoller == null) {
AbstractBasePoller poller = new AbstractBasePoller() {
@Override
protected void handlePolledData(ModbusRegisterArray registers) {
handlePolledSystemInformationData(registers);
}
};
poller.registerPollTask(500, 36, ModbusReadFunctionCode.READ_INPUT_REGISTERS);
systemInformationPoller = poller;
}
if (energyPoller == null) {
AbstractBasePoller poller = new AbstractBasePoller() {
@Override
protected void handlePolledData(ModbusRegisterArray registers) {
handlePolledEnergyData(registers);
}
};
poller.registerPollTask(3500, 16, ModbusReadFunctionCode.READ_INPUT_REGISTERS);
energyPoller = poller;
}
if (systemStatePoller == null) {
AbstractBasePoller poller = new AbstractBasePoller() {
@Override
protected void handlePolledData(ModbusRegisterArray registers) {
handlePolledSystemStateData(registers);
}
};
poller.registerPollTask(2500, 2, ModbusReadFunctionCode.READ_INPUT_REGISTERS);
systemStatePoller = poller;
}
if (systemParameterPoller == null) {
AbstractBasePoller poller = new AbstractBasePoller() {
@Override
protected void handlePolledData(ModbusRegisterArray registers) {
handlePolledSystemParameterData(registers);
}
};
poller.registerPollTask(1500, 11, ModbusReadFunctionCode.READ_MULTIPLE_REGISTERS);
systemParameterPoller = poller;
}
updateStatus(ThingStatus.UNKNOWN);
}
Aggregations