Exemplo n.º 1
0
  /**
   * Posts update event to OpenHAB bus for "holding" type slaves
   *
   * @param binding ModbusBinding to get item configuration from BindingProviding
   * @param registers data received from slave device in the last pollInterval
   * @param itemName item to update
   */
  protected void internalUpdateItem(String slaveName, InputRegister[] registers, String itemName) {
    for (ModbusBindingProvider provider : providers) {
      if (!provider.providesBindingFor(itemName)) {
        continue;
      }
      ModbusBindingConfig config = provider.getConfig(itemName);
      if (!config.slaveName.equals(slaveName)) {
        continue;
      }

      String slaveValueType = modbusSlaves.get(slaveName).getValueType();
      double rawDataMultiplier = modbusSlaves.get(slaveName).getRawDataMultiplier();

      State newState = extractStateFromRegisters(registers, config.readRegister, slaveValueType);
      /* receive data manipulation */
      State newStateBoolean =
          provider.getConfig(itemName).translateBoolean2State(!newState.equals(DecimalType.ZERO));
      if (!UnDefType.UNDEF.equals(newStateBoolean)) {
        newState = newStateBoolean;
      } else if ((rawDataMultiplier != 1) && (config.getItem() instanceof NumberItem)) {
        double tmpValue = ((DecimalType) newState).doubleValue() * rawDataMultiplier;
        newState = new DecimalType(String.valueOf(tmpValue));
      }

      State currentState = config.getItemState();
      if (!newState.equals(currentState)) {
        eventPublisher.postUpdate(itemName, newState);
      }
    }
  }
Exemplo n.º 2
0
 /** Parses configuration creating Modbus slave instances defined in cfg file {@inheritDoc} */
 @Override
 protected void internalReceiveCommand(String itemName, Command command) {
   for (ModbusBindingProvider provider : providers) {
     if (provider.providesBindingFor(itemName)) {
       ModbusBindingConfig config = provider.getConfig(itemName);
       ModbusSlave slave = modbusSlaves.get(config.slaveName);
       slave.executeCommand(command, config.readRegister, config.writeRegister);
     }
   }
 }
Exemplo n.º 3
0
 /**
  * Posts update event to OpenHAB bus for "coil" type slaves
  *
  * @param binding ModbusBinding to get item configuration from BindingProviding
  * @param registers data received from slave device in the last pollInterval
  * @param item item to update
  */
 protected void internalUpdateItem(String slaveName, BitVector coils, String itemName) {
   for (ModbusBindingProvider provider : providers) {
     if (provider.providesBindingFor(itemName)) {
       ModbusBindingConfig config = provider.getConfig(itemName);
       if (config.slaveName.equals(slaveName)) {
         boolean state = coils.getBit(config.readRegister);
         State currentState = provider.getConfig(itemName).getItemState();
         State newState = provider.getConfig(itemName).translateBoolean2State(state);
         if (!newState.equals(currentState)) {
           eventPublisher.postUpdate(itemName, newState);
         }
       }
     }
   }
 }