Class LevelMeter6_3Module

Inheritance Relationships

Base Type

Class Documentation

class LevelMeter6_3Module : public Module

This class represents the 6 Level Meters Module connected via eMOD bus to controller module. This module is a three capacitive, Namur and PNP probes plus six resistive probes. Also it has an 4-20mA input.

Class example 1

/*
 * This example uses a LevelMeter6_3Module to display all digital inputs status.
 */
#include "LevelMeter6_3Module.hpp"
#include "EmodRetMng.hpp"
#include "HAL.hpp"

int main() {
    LevelMeter6_3Module module;
    if (module.init() != 0) {
        printf("Module could not be initialized!\n");
        return 1;
    }

    // Configures all resistance sensor thresholds
    module.setAllResistiveSensorThreshold(DetectResistance::kDR23, RefillResistance::kRR46);
    HAL::sleepMs(100);

    // Configures resistance thresholds individually for sensors 1 & 2
    module.setResistiveSensorThreshold(1, DetectResistance::kDR1, RefillResistance::kRR2);
    module.setResistiveSensorThreshold(2, DetectResistance::kDR1, RefillResistance::kRR2);
    HAL::sleepMs(100);

    // Configures resistance thresholds individually for sensors 5 & 6
    module.setResistiveSensorThreshold(5, DetectResistance::kDR50, RefillResistance::kRR100);
    module.setResistiveSensorThreshold(6, DetectResistance::kDR50, RefillResistance::kRR100);
    HAL::sleepMs(100);

    //Configures all current sensor types
    module.setAllCurrentSensorType(LevelMeterType::kNamur);
    HAL::sleepMs(100);

    // Configures type individually for sensor 7
    module.setCurrentSensorType(7, LevelMeterType::kCapacitive);
    HAL::sleepMs(100);

    //--------------- Configuring module
    // Configures type individually for sensor 9
    module.setCurrentSensorType(9, LevelMeterType::kPNP);
    HAL::sleepMs(100);

    // Testing get status individually
    uint8_t status[LevelMeter6_3Module::kNumResistiveSensors + LevelMeter6_3Module::kNumCurrentSensors + 1] = {0};
    for(int i = 1; i <= (LevelMeter6_3Module::kNumResistiveSensors + LevelMeter6_3Module::kNumCurrentSensors); i++){
        module.getLevelStatus(i, &status[0]);
        printf("\tVALUE for INPUT %.2d: %d\n", i, status[0]);
    }
    HAL::sleepMs(100);

    float value = 0;
    while (1) {
        if(module.getAllLevelStatus(status) == EmodRetOk){
            for(int i = 1; i <= (LevelMeter6_3Module::kNumResistiveSensors + LevelMeter6_3Module::kNumCurrentSensors); i++){
                module.getLevelStatus(i, &status[0]);
                printf("\tVALUE for INPUT %.2d: %d\n", i, status[0]);
            }
        }
        printf("\n");

        HAL::sleepMs(100);

        if(module.getAnalogInputCurrent(&value) == EmodRetOk){
            printf("\tANALOG VALUE %f\n\n", value);
        }

        HAL::sleepMs(1000);
    }
}

Public Functions

LevelMeter6_3Module()
~LevelMeter6_3Module()
EmodRet init(const LevelMeter6_3ModuleCallback_Type callback_func = nullptr, void *const callback_context = nullptr, const uint8_t variant = 1)

Initialize module. It is important to emphasize that init() method is mandatory to call it and must be called always after instantiating the module. It can be called several times, each of which the module is initialized again.

Parameters
  • callback_func(optional) -- [in] function that will be called when a configured event occurs.

  • callback_context(optional) -- [in] context that will be passed to the callback function.

  • variant(optional) -- [in] identifies the module in case more than one module of the same type are present.

EmodRet init(const uint8_t variant)

Initialize module. It is important to emphasize that init() method is mandatory to call it and must be called always after instantiating the module. It can be called several times, each of which the module is initialized again.

Parameters

variant -- [in] identifies the module in case more than one module of the same type are present.

EmodRet setResistiveSensorThreshold(const uint8_t meter_num, const DetectResistance detect_resistance, const RefillResistance refill_resistance)

Configs the detection and refill resistance threshold for the meter_num input sensor.

Parameters
  • meter_num -- [in] mumber of the input resistance sensor from 1 to 6.

  • detect_resistance -- [in] below this low limit value, sensor is detecting the liquid presence.

  • refill_resistance -- [in] below this low limit value, sensor is detecting the liquid absence, that is, tank should be refilled.

EmodRet setAllResistiveSensorThreshold(const DetectResistance detect_resistance, const RefillResistance refill_resistance)

Configs the detection and refill resistance threshold for all resistive input sensor.

Parameters
  • detect_resistance -- [in] below this low limit value, sensor is detecting the liquid presence.

  • refill_resistance -- [in] below this low limit value, sensor is detecting the liquid absence, that is, tank should be refilled.

EmodRet setCurrentSensorType(const uint8_t meter_num, const LevelMeterType type)

Configs the type of current sensor.

Parameters
  • meter_num -- [in] mumber of the input resistance sensor from 7 to 9.

  • type -- [in] can be Namur, Capacitive or PNP.

EmodRet setAllCurrentSensorType(const LevelMeterType type)

Configs the type of all current sensor.

Parameters

type -- [in] can be Namur, Capacitive or PNP.

EmodRet getLevelStatus(const uint16_t meter_num, uint8_t *status)

Gets the status of the meter_num input sensor.

Parameters
  • meter_num -- [in] mumber of the input sensor from 1 to 9.

  • status -- [out] 0 = sensor is not detecting and tank should be refilled, 1 = sensor is detecting liquid or solid presence.

EmodRet getAllLevelStatus(uint8_t status[kNumResistiveSensors + kNumCurrentSensors + 1])

Gets the status of all meter_num input sensor.

Parameters

status -- [out] an array from 1 to 9, indicating: 0 = sensor is not detecting; or 1 = sensor detection.

EmodRet getAnalogInputCurrent(float *data)

Gets the current value of the 4-20 mA input.

Parameters

data -- [out] value ranging from 0 to 20 mA. Below 4 mA, one can consider a short-circuit current loop

EmodRet configEventOnNewData()

Configures module for calling init callback_func when new data arrives on any of its sensor inputs (1 to 9).

EmodRet resetEventConfig(void)

Resets all previously configured events.

Public Static Attributes

static constexpr int kNumResistiveSensors = 6
static constexpr int kNumCurrentSensors = 3
static constexpr int kNumAnalogInputs = 1

Protected Functions

EmodRet initFunctions()

Protected Attributes

LevelMeterFunctions *levelMeters
LevelMeter6_3ModuleCallback_Type callback
std::vector<int> callback_input_status

Protected Static Functions

static void rawControllerCallback(const uint8_t *data, const uint16_t data_len, const uint8_t id_function, void *const ctx)