Class Relay8Module

Inheritance Relationships

Base Type

Class Documentation

class Relay8Module : public Module

This class represents the Signal Relays Module connected via eMOD bus to the controller module. The Relays Module has 8 independent signal relays that you can activate or deactivate each one separately. Moreover, a timeout configuration parameter can be set to generate one shot relay pulse automatically. If timeout is set to 0, relay stays in the current state.

Class example 1

/*
 * This example creates a Relay8Module object and activates/deactivates every two seconds some of its relays.
 */
#include "Relay8Module.hpp"
#include "EmodRetMng.hpp"
#include "HAL.hpp"

int main() {
    // Declares an instance of Relay8Module
    Relay8Module relay_module;
    if (relay_module.init() != 0) {
        printf("Module could not be initialized!\n");
        return 1;
    }

    // Configures first two relays without pulse
    relay_module.configPulseWidth(Relay8Module::RELAY1 | Relay8Module::RELAY2, 0);

    // Example using Relay8Module
    while (1) {
        relay_module.activate(Relay8Module::RELAY1);
        relay_module.deactivate(Relay8Module::RELAY2);
        sleepMs(1000);
        relay_module.activate(Relay8Module::RELAY2);
        relay_module.deactivate(Relay8Module::RELAY1);
        sleepMs(1000);
    }
}

Public Functions

Relay8Module()
~Relay8Module()
EmodRet init(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

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

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 all 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 activateAll()

Activates all module relays.

EmodRet deactivateAll()

Deactivates all module relays.

EmodRet getRelayStatus(const uint8_t relay_mask, uint8_t *status)

Gets a relay status.

Parameters
  • relay_mask -- [in] relay 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.

Public Static Attributes

static constexpr uint8_t kRelay1 = Relay8Module_RELAY1
static constexpr uint8_t kRelay2 = Relay8Module_RELAY2
static constexpr uint8_t kRelay3 = Relay8Module_RELAY3
static constexpr uint8_t kRelay4 = Relay8Module_RELAY4
static constexpr uint8_t kRelay5 = Relay8Module_RELAY5
static constexpr uint8_t kRelay6 = Relay8Module_RELAY6
static constexpr uint8_t kRelay7 = Relay8Module_RELAY7
static constexpr uint8_t kRelay8 = Relay8Module_RELAY8
static constexpr uint8_t kRelayAll = Relay8Module_ALL_RELAY
static constexpr uint8_t kNumberOfRelays = Relay8Module_NUMBER_OF_RELAYS

Protected Functions

EmodRet initFunctions()

Protected Attributes

RelayFunctions *relays