1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*      File: EL3104.h
 *       This file is part of the program ethercatcpp-core
 *       Program description : EtherCAT driver libraries for UNIX
 *       Copyright (C) 2017-2024 -  Robin Passama (LIRMM / CNRS) Arnaud Meline
 * (LIRMM / CNRS) Benjamin Navarro (LIRMM / CNRS). All Right reserved.
 *
 *       This software is free software: you can redistribute it and/or modify
 *       it under the terms of the CeCILL-C license as published by
 *       the CEA CNRS INRIA, either version 1
 *       of the License, or (at your option) any later version.
 *       This software is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *       CeCILL-C License for more details.
 *
 *       You should have received a copy of the CeCILL-C License
 *       along with this software. If not, it can be found on the official
 * website of the CeCILL licenses family (http://www.cecill.info/index.en.html).
 */
/**
 * @file beckhoff_terminals/EL3104.h
 * @author Robin Passama (maintainer)
 * @author Arnaud Meline (original)
 * @author Benjamin Navarro (refactoring)
 * @brief EtherCAT driver for beckhoff EL3104 device.
 * @date October 2019 06.
 * @ingroup ethercatcpp-core
 * @example example_EL3104.cpp
 */

#pragma once

#include <ethercatcpp/slave_device.h>

/*! \namespace ethercatcpp
 *
 * Root namespace for common and general purpose ethercatcpp packages
 */
namespace ethercatcpp {

/** @brief This class describe the EtherCAT driver for a beckhoff EL3104 device
 *
 * This driver permit to communicate with a "beckhoff EL3104" through an
 * EtherCAT bus. The EL3104 EtherCAT Terminal is an interface for the direct
 * connection of 4-channel analog input terminal -10 ... +10 V.
 */
class EL3104 : public SlaveDevice {
public:
    /**
     * @brief Constructor of EL3104 class
     */
    EL3104();
    virtual ~EL3104();

    //! This enum define open circuit detection pin.
    enum channel_id_t {
        channel_1, //!< Channel 1
        channel_2, //!< Channel 2
        channel_3, //!< Channel 3
        channel_4  //!< Channel 4
    };

    /**
     * @brief Get value provided by a channel
     *
     * @param [in] channel desired channel (choose in channel_id_t)
     * @return value of specified channel
     */
    int channel_value(channel_id_t channel) const;

    /**
     * @brief Check if value of channel is below measuring range
     *
     * @param [in] channel desired channel (choose in channel_id_t)
     * @return TRUE if available, FALSE otherwise
     */
    bool under_range(channel_id_t channel) const;

    /**
     * @brief Check if value of channel exceeds measuring range
     *
     * @param [in] channel desired channel (choose in channel_id_t)
     * @return TRUE if available, FALSE otherwise
     */
    bool over_range(channel_id_t channel) const;

    // /**
    // * @brief Function used to check Limit 1 monitoring
    // *
    // * @param [in] channel desired channel (choose in channel_id_t)
    // * @return 0: not active, 1: value is smaller than limit value 1, 2: value
    // is larger than limit value 1, 3: Value is equal to limit value 1
    // */
    // int check_Limit_1_Monitoring(channel_id_t channel);
    //
    // /**
    // * @brief Function used to check Limit 2 monitoring
    // *
    // * @param [in] channel desired channel (choose in channel_id_t)
    // * @return 0: not active, 1: value is smaller than limit value 1, 2: value
    // is larger than limit value 1, 3: Value is equal to limit value 1
    // */
    // int check_Limit_2_Monitoring(channel_id_t channel);
    // add fct to set limit 1 and 2 value and fct to enable limit 1 and 2 if
    // used

    /**
     * @brief Check if an error is detected (invalid data)
     *
     * @param [in] channel desired channel (choose in channel_id_t)
     * @return TRUE if error notified, FALSE otherwise
     */
    bool error(channel_id_t channel) const;

    /**
     * @brief Check if no new process data was available
     *
     * @param [in] channel desired channel (choose in channel_id_t)
     * @return TRUE if sync error notified, FALSE otherwise
     */
    bool sync_error(channel_id_t channel) const;

    /**
     * @brief Check if channel current value is valud
     *
     * @param [in] channel desired channel (choose in channel_id_t)
     * @return TRUE if valid, FALSE otherwise
     */
    bool valid(channel_id_t channel) const;

    /**
     * @brief Check if channel value has been updated since last call to updated
     *
     * @param [in] channel desired channel (choose in channel_id_t)
     * @return true if updated, FALSE otherwise
     */
    bool updated(channel_id_t channel) const;

    /**
     * @brief Print human raedable state of all available channels
     */
    void print_all_channels() const;

private:
    void unpack_status_buffer();
    int8_t last_updated_;
    bool updated_[4];
    void check_updated(channel_id_t);

    struct data_channel_t {
        uint16_t status_word;<--- struct member 'data_channel_t::status_word' is never used.
        int16_t data_value;<--- struct member 'data_channel_t::data_value' is never used.
    };

    // Status variable
    data_channel_t channel_1_; // 0x6000
    data_channel_t channel_2_; // 0x6010
    data_channel_t channel_3_; // 0x6020
    data_channel_t channel_4_; // 0x6030
};
} // namespace ethercatcpp