Class AInput7Relay2Module
Defined in File AInput7Relay2Module.hpp
Inheritance Relationships
Base Type
public Module
(Class Module)
Class Documentation
-
class AInput7Relay2Module : public Module
This class represents the Analogue Inputs and Power Relays Module connected via eMOD bus to controller module. On the one hand, this module has 7 independent analogue inputs, the value of each one can be obtained separately. Its configuration for measuring voltage or current can be set also separately. And on the other hand, has 2 independent power relays than can be activated or deactivated separately. If a polling is to be performed more than once per second, it's recommended to handle function call.
Class example 1
/* * This example uses a AInput7Relay2Module to display analog inputs and activate/deactivates relays. */ #include "AInput7Relay2Module.hpp" #include "EmodRetMng.hpp" #include "HAL.hpp" void configure(AInput7Relay2Module &module) { // Configure inputs 5, 6 and 7 as current. By default are configured as voltage module.configInput( AInput7Relay2Module::AI_INPUT05 | AInput7Relay2Module::AI_INPUT06 | AInput7Relay2Module::AI_INPUT07); sleepMs(100); module.configSampleRate(200); } void displayInputs(float data[AInput7Relay2Module::NUMBER_OF_AI_INPUTS]) { printf("AI01 = %2.2f V //", data[0]); printf("AI02 = %2.2f V //", data[1]); printf("AI03 = %2.2f V //", data[2]); printf("AI04 = %2.2f V //", data[3]); printf("AI05 = %2.2f mA //", data[4]); printf("AI06 = %2.2f mA //", data[5]); printf("AI07 = %2.2f mA //", data[6]); printf("\n"); } void testInputs(AInput7Relay2Module &module) { sleepMs(100); float aInputs[AInput7Relay2Module::NUMBER_OF_AI_INPUTS]; // Calling getAllAnalogInput() if (module.getAllAnalogInput(aInputs) == 0) { displayInputs(aInputs); } // Calling getAnalogInput() float a_input; if (module.getAnalogInput(AInput7Relay2Module::AI_INPUT01, &a_input) == 0) { printf("AI01 = %2.2f V\n", a_input); } if (module.getAnalogInput(AInput7Relay2Module::AI_INPUT02, &a_input) == 0) { printf("AI02 = %2.2f V\n", a_input); } if (module.getAnalogInput(AInput7Relay2Module::AI_INPUT03, &a_input) == 0) { printf("AI03 = %2.2f V\n", a_input); } if (module.getAnalogInput(AInput7Relay2Module::AI_INPUT04, &a_input) == 0) { printf("AI04 = %2.2f V\n", a_input); } if (module.getAnalogInput(AInput7Relay2Module::AI_INPUT05, &a_input) == 0) { printf("AI05 = %2.2f mA\n", a_input); } if (module.getAnalogInput(AInput7Relay2Module::AI_INPUT06, &a_input) == 0) { printf("AI06 = %2.2f mA\n", a_input); } if (module.getAnalogInput(AInput7Relay2Module::AI_INPUT07, &a_input) == 0) { printf("AI07 = %2.2f mA\n", a_input); } } void testRelays(AInput7Relay2Module &module) { module.activate(AInput7Relay2Module::RELAY1); sleepMs(500); module.activate(AInput7Relay2Module::RELAY2); sleepMs(500); module.deactivate(AInput7Relay2Module::RELAY1); sleepMs(500); module.deactivate(AInput7Relay2Module::RELAY2); sleepMs(500); } int main(void) { AInput7Relay2Module module; if (module.init() != 0) { printf("Module could not be initialized!\n"); return 1; } configure(module); while (1) { printf("Testing relays...\n"); testRelays(module); sleepMs(1000); printf("Testing analog inputs...\n"); testInputs(module); sleepMs(1000); } }
Public Functions
-
AInput7Relay2Module()
-
~AInput7Relay2Module()
-
EmodRet init(const AInput7Relay2ModuleCallback_Type callback_func = nullptr, void *const callback_context = nullptr, const uint8_t variant = 1)
Initialize module. It is important to emphasize that this method is mandatory to call it. 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 configSampleRate(const uint32_t ms_period)
Configure sample rate at which you want to check the analog input data.
- Parameters
ms_period -- [in] time in milliseconds, which represents the sampling time, where the ADC will sample the seven channels. Minimum value is 1 ms.
-
EmodRet configInput(const uint16_t voltage_input_mask)
Configure an input or set of inputs to select them for acquiring current (4 to 20 mA) or voltage (0 to 10 V).
- Parameters
voltage_input_mask -- [in] input or list of analog inputs, as enumerated above in the constants section, to configure them for acquiring current. The rest of inputs will be configured for acquiring voltage.
-
EmodRet getInputConfig(uint16_t *config)
Gets configured inputs mask. Each input indicates if it’s configured to acquire voltage (0) or current (1).
- Parameters
config -- [out] current input mask configuration (V/A) for each input as a mask.
-
EmodRet getAnalogInput(const uint16_t input_number, float *data)
Gets last measured value of a specified analog input.
- Parameters
input_number -- [in] analog input number to get the data, as enumerated above in the constants section.
data -- [out] returns last measured input data. If data has not been received yet, NO_NEW_DATA_READ is returned. Parameter is initialized inside the class. When input was configured as current, value is shown in mA; otherwise it’s represented in V. When an input is configured in current mode and sampled_data is 0, it means that the current loop is broken.
-
EmodRet getAllAnalogInput(float data[kNumberOfAnalogInputs])
Gets last measured values for all analog inputs.
- Parameters
data -- [out] returns last measured input number data for each analog input. If an analog input data has not been measured yet, NO_NEW_DATA_READ is returned in that input. Parameter is initialized inside the class. When input was configured as current, value is shown in mA; otherwise it’s represented in V. When an input is configured in current mode and sampled_data is 0, it means that the current loop is broken.
-
EmodRet configPulseWidth(const uint8_t relay_mask, const uint32_t width_ms)
Configure pulse width of a relay or list of relays. When pulse width is 0 a relay stays in the current state, and there is no pulse.
- Parameters
relay_mask -- [in] relay or list of relays to configure.
width_ms -- [in] pulse width in ms. Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.
-
EmodRet configAllPulseWidth(const uint32_t width_ms)
Configure pulse width of al relays When pulse width is 0 a relay stays in the current state, and there is no pulse.
- Parameters
width_ms -- [in] pulse width in ms. Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.
-
EmodRet activate(const uint8_t relay_mask)
Activates a relay or set of relays.
- Parameters
relay_mask -- [in] relay or list of relays to activate.
-
EmodRet deactivate(const uint8_t relay_mask)
Deactivates a relay or set of relays.
- Parameters
relay_mask -- [in] relay or list of relays to deactivate.
-
EmodRet getRelayStatus(const uint8_t relay_mask, uint8_t *status)
Gets a relay status.
- Parameters
relay_mask -- [in] relay mask number to get the status.
status -- [out] every bit represents a relay order status. Status is 1 when is activate and 0 when deactivate.
-
EmodRet getAllRelayStatus(uint8_t *status)
Gets all relay status.
- Parameters
status -- [out] every bit represents a relay order status. Status is 1 when is activate and 0 when deactivate.
-
EmodRet configEventAtTimeInterval(const uint32_t time_interval, const uint32_t event_mask = AInput7Relay2Module::kAnalogInputAll)
Configures module for calling init callback_func at specified period.
- Parameters
time_interval -- [in] period in milliseconds. Minimum value is 500ms.
event_mask -- [in] bit mask representing inputs that must trigger the event.
-
EmodRet configEventOnValueChange(const uint32_t threshold, const uint32_t event_mask = AInput7Relay2Module::kAnalogInputAll)
Configures module for calling init callback_func when input changes its value by a specified amount.
- Parameters
threshold -- [in] amount of samples that triggers the event (use voltageToSample() for conversion).
event_mask -- [in] bit mask representing inputs that must trigger the event.
-
EmodRet configEventWithinRange(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = AInput7Relay2Module::kAnalogInputAll)
Configures module for calling init callback_func when input value enters the specified range.
- Parameters
low_limit -- [in] low limit of the range in samples (use voltageToSample() for conversion).
high_limit -- [in] high limit of the range in samples (use voltageToSample() for conversion).
event_mask -- [in] bit mask representing inputs that must trigger the event.
-
EmodRet configEventOutOfRange(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = AInput7Relay2Module::kAnalogInputAll)
Configures module for calling init callback_func when input value gets out of the specified range.
- Parameters
low_limit -- [in] low limit of the range in samples (use voltageToSample() for conversion).
high_limit -- [in] high limit of the range in samples (use voltageToSample() for conversion).
event_mask -- [in] bit mask representing inputs that must trigger the event.
-
uint16_t voltageToSamples(const float voltage)
Converts voltage to discrete samples.
- Parameters
voltage -- [in] voltage in V, from 0 to 10.
-
uint16_t currentToSamples(const float current)
Converts current to discrete samples.
- Parameters
current -- [in] current in mA, from 4 to 20.
-
float samplesToVoltage(const uint16_t samples)
Converts discrete samples to voltage.
- Parameters
samples -- [in] discrete samples from 0 to 10000.
-
float samplesToCurrent(const uint16_t samples)
Converts discrete samples to current.
- Parameters
samples -- [in] discrete samples from 0 to 10000.
Public Static Attributes
-
static constexpr uint16_t kAnalogInput1 = AInput7Relay2Module_INPUT01
-
static constexpr uint16_t kAnalogInput2 = AInput7Relay2Module_INPUT02
-
static constexpr uint16_t kAnalogInput3 = AInput7Relay2Module_INPUT03
-
static constexpr uint16_t kAnalogInput4 = AInput7Relay2Module_INPUT04
-
static constexpr uint16_t kAnalogInput5 = AInput7Relay2Module_INPUT05
-
static constexpr uint16_t kAnalogInput6 = AInput7Relay2Module_INPUT06
-
static constexpr uint16_t kAnalogInput7 = AInput7Relay2Module_INPUT07
-
static constexpr uint16_t kAnalogInputAll = AInput7Relay2Module_ALL_INPUT
-
static constexpr uint8_t kRelay1 = AInput7Relay2Module_RELAY1
-
static constexpr uint8_t kRelay2 = AInput7Relay2Module_RELAY2
-
static constexpr uint8_t kRelayAll = AInput7Relay2Module_ALL_RELAY
-
static constexpr uint8_t kNumberOfAnalogInputs = AInput7Relay2Module_NUMBER_OF_AI_INPUTS
-
static constexpr uint8_t kNumberOfRelays = AInput7Relay2Module_NUMBER_OF_RELAYS
-
static constexpr uint8_t kIdFunctionInput1 = AInput7Relay2Module_idFunctionINPUT01
-
static constexpr uint8_t kIdFunctionInput2 = AInput7Relay2Module_idFunctionINPUT02
-
static constexpr uint8_t kIdFunctionInput3 = AInput7Relay2Module_idFunctionINPUT03
-
static constexpr uint8_t kIdFunctionInput4 = AInput7Relay2Module_idFunctionINPUT04
-
static constexpr uint8_t kIdFunctionInput5 = AInput7Relay2Module_idFunctionINPUT05
-
static constexpr uint8_t kIdFunctionInput6 = AInput7Relay2Module_idFunctionINPUT06
-
static constexpr uint8_t kIdFunctionInput7 = AInput7Relay2Module_idFunctionINPUT07
-
static constexpr uint16_t kMaxADC = AInput7Relay2Module_MAX_ADC
-
static constexpr uint8_t kCfgVoltage = AInput7Relay2Module_CFG_VOLTAGE
-
static constexpr uint8_t kCfgCurrent = AInput7Relay2Module_CFG_CURRENT
-
static constexpr float kMaxVoltage = AInput7Relay2Module_MAX_VOLTAGE
-
static constexpr float kMaxCurrent = AInput7Relay2Module_MAX_CURRENT
-
AInput7Relay2Module()