UniSet  2.6.0
RTUExchange.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // -----------------------------------------------------------------------------
17 #ifndef _RTUEXCHANGE_H_
18 #define _RTUEXCHANGE_H_
19 // -----------------------------------------------------------------------------
20 #include <ostream>
21 #include <string>
22 #include <map>
23 #include <vector>
24 #include "MBExchange.h"
25 #include "modbus/ModbusRTUMaster.h"
26 #include "RTUStorage.h"
27 // --------------------------------------------------------------------------
28 namespace uniset
29 {
30  // -----------------------------------------------------------------------------
31  class RTUExchange:
32  public MBExchange
33  {
34  public:
36  const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "rs" );
37  virtual ~RTUExchange();
38 
40  static std::shared_ptr<RTUExchange> init_rtuexchange( int argc, const char* const* argv,
41  uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
42  const std::string& prefix = "rs" );
43 
45  static void help_print( int argc, const char* const* argv );
46 
47  protected:
48  std::shared_ptr<ModbusRTUMaster> mbrtu;
49  std::mutex mbMutex;
50  std::string devname;
51  ComPort::Speed defSpeed;
52  bool use485F;
53  bool transmitCtl;
54 
55  virtual void step() override;
56  virtual bool poll() override;
57 
58  virtual std::shared_ptr<ModbusClient> initMB( bool reopen = false ) override;
59  virtual bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniXML::iterator& it ) override;
60 
61  private:
62  RTUExchange();
63 
64  bool rs_pre_clean;
65  };
66  // --------------------------------------------------------------------------
67 } // end of namespace uniset
68 // -----------------------------------------------------------------------------
69 #endif // _RS_EXCHANGE_H_
70 // -----------------------------------------------------------------------------
Definition: MBExchange.h:55
Definition: CallbackTimer.h:29
static void help_print(int argc, const char *const *argv)
Definition: RTUExchange.cc:100
Definition: UniXML.h:43
Definition: RTUExchange.h:31
static std::shared_ptr< RTUExchange > init_rtuexchange(int argc, const char *const *argv, uniset::ObjectId shmID, const std::shared_ptr< SharedMemory > &ic=nullptr, const std::string &prefix="rs")
Definition: RTUExchange.cc:338
long ObjectId
Definition: UniSetTypes_i.idl:30