UniSet  2.6.0
ComediInterface.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 ComediInterface_H_
18 #define ComediInterface_H_
19 // -----------------------------------------------------------------------------
20 #include <string>
21 #include <comedilib.h>
22 #include "Exceptions.h"
23 //--------------------------------------------------------------------------
24 namespace uniset
25 {
26  // -----------------------------------------------------------------------------
29  {
30  public:
31  explicit ComediInterface( const std::string& dev );
32  ~ComediInterface();
33 
34  int getAnalogChannel( int subdev, int channel, int range = 0, int aref = AREF_GROUND )
35  throw(uniset::Exception);
36 
37  void setAnalogChannel( int subdev, int channel, int data, int range = 0, int aref = AREF_GROUND )
38  throw(uniset::Exception);
39 
40  bool getDigitalChannel( int subdev, int channel )
41  throw(uniset::Exception);
42 
43  void setDigitalChannel( int subdev, int channel, bool bit )
44  throw(uniset::Exception);
45 
46 
47  // Конфигурирование входов / выходов
48  enum ChannelType
49  {
50  DI = INSN_CONFIG_DIO_INPUT,
51  DO = INSN_CONFIG_DIO_OUTPUT,
52  AI = 100, // INSN_CONFIG_AIO_INPUT,
53  AO = 101 // INSN_CONFIG_AIO_OUTPUT
54  };
55 
56  enum SubdevType
57  {
58  Unknown = 0,
59  TBI24_0 = 1,
60  TBI0_24 = 2,
61  TBI16_8 = 3,
62  GRAYHILL = 4
63  };
64 
65  static std::string type2str( SubdevType t );
66  static SubdevType str2type( const std::string& s );
67 
68  void configureSubdev( int subdev, SubdevType type ) throw(uniset::Exception);
69 
70  void configureChannel( int subdev, int channel, ChannelType type, int range = 0, int aref = 0 )
71  throw(uniset::Exception);
72 
73  inline const std::string devname()
74  {
75  return dname;
76  }
77 
78  protected:
79 
80  comedi_t* card;
81  std::string dname;
82 
83  private:
84  };
85  // --------------------------------------------------------------------------
86 } // end of namespace uniset
87 // -----------------------------------------------------------------------------
88 #endif // ComediInterface_H_
89 // -----------------------------------------------------------------------------
90