RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
daq.h
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #ifndef DAQ_DEVICE_H
21 #define DAQ_DEVICE_H
22 
23 #include <io.h>
24 #include <map>
25 #include <rt.h>
26 
28 
32 namespace DAQ
33 {
34 
38 enum type_t
39 {
40  AI,
41  AO,
42  DIO,
43  DI,
44  DO,
45 };
49 typedef unsigned long index_t;
53 static const index_t INVALID = (0-1);
58 {
61 };
62 
63 class Device;
64 class Driver;
65 
73 class Manager
74 {
75 
76  friend class Device;
77  friend class Driver;
78 
79 public:
80 
87  static Manager *getInstance(void);
88 
99  void foreachDevice(void (*callback)(Device *,void *),void *param);
100 
110  Device *loadDevice(const std::string &driver,const std::list<std::string> &params);
111 
112 private:
113 
114  Manager(void) : mutex(Mutex::RECURSIVE) {};
115  ~Manager(void) {};
116  Manager(const Manager &) {};
118  {
119  return *getInstance();
120  };
121 
122  static Manager *instance;
123 
124  void insertDevice(Device *);
125  void removeDevice(Device *);
126 
127  void registerDriver(Driver *,const std::string &);
128  void unregisterDriver(const std::string &);
129 
131  std::list<Device *> devices;
132  std::map<std::string,Driver *> driverMap;
133 
134 }; // class Manager
135 
139 class Device : public RT::Device, public IO::Block
140 {
141 
142 public:
143 
150  Device(std::string,IO::channel_t *,size_t);
151  virtual ~Device(void);
152 
159  virtual size_t getChannelCount(type_t type) const=0;
167  virtual bool getChannelActive(type_t type,index_t index) const=0;
175  virtual int setChannelActive(type_t type,index_t index,bool state)=0;
183  virtual size_t getAnalogRangeCount(type_t type,index_t index) const=0;
191  virtual size_t getAnalogReferenceCount(type_t type,index_t index) const=0;
199  virtual size_t getAnalogUnitsCount(type_t type,index_t index) const=0;
200  virtual size_t getAnalogDownsample(type_t type,index_t index) const=0;
209  virtual std::string getAnalogRangeString(type_t type,index_t index,index_t range) const=0;
218  virtual std::string getAnalogReferenceString(type_t type,index_t index,index_t reference) const=0;
227  virtual std::string getAnalogUnitsString(type_t type,index_t index,index_t units) const=0;
235  virtual double getAnalogGain(type_t type,index_t index) const=0;
243  virtual double getAnalogZeroOffset(type_t type,index_t index) const=0;
251  virtual index_t getAnalogRange(type_t type,index_t index) const=0;
259  virtual index_t getAnalogReference(type_t type,index_t index) const=0;
267  virtual index_t getAnalogUnits(type_t type,index_t index) const=0;
275  virtual index_t getAnalogOffsetUnits(type_t type,index_t index) const=0;
284  virtual int setAnalogGain(type_t type,index_t index,double gain)=0;
293  virtual int setAnalogRange(type_t type,index_t index,index_t range)=0;
302  virtual int setAnalogZeroOffset(type_t type,index_t index,double offset)=0;
311  virtual int setAnalogReference(type_t type,index_t index,index_t reference)=0;
320  virtual int setAnalogUnits(type_t type,index_t index,index_t units)=0;
329  virtual int setAnalogOffsetUnits(type_t type,index_t index,index_t units)=0;
330  virtual int setAnalogDownsample(type_t type, index_t index, size_t downsample)=0;
331  virtual int setAnalogCounter(type_t type, index_t index)=0;
340  virtual int setAnalogCalibrationValue(type_t type,index_t index, double value)=0;
348  virtual double getAnalogCalibrationValue(type_t type,index_t index) const=0;
356  virtual int setAnalogCalibrationActive(type_t type,index_t index, bool state)=0;
364  virtual bool getAnalogCalibrationActive(type_t type,index_t index) const=0;
372  virtual bool getAnalogCalibrationState(type_t type,index_t index) const=0;
379  virtual direction_t getDigitalDirection(index_t index) const=0;
387  virtual int setDigitalDirection(index_t index,direction_t direction)=0;
388 
389 
390 }; // class Device
391 
397 class Driver
398 {
399 
400 public:
401 
407  Driver(const std::string &name);
408  virtual ~Driver(void);
409 
418  virtual Device *createDevice(const std::list<std::string> &args)=0;
419 
420 private:
421 
422  std::string name;
423 
424 }; // class Driver
425 
426 }; // namespace DAQ
427 
428 #endif // DAQ_DEVICE_H
static Manager * instance
Definition: daq.h:120
virtual direction_t getDigitalDirection(index_t index) const =0
virtual int setChannelActive(type_t type, index_t index, bool state)=0
virtual double getAnalogZeroOffset(type_t type, index_t index) const =0
Definition: daq.h:42
unsigned long index_t
Definition: daq.h:49
Definition: io.h:187
Device(void)
Definition: rt.cpp:119
virtual index_t getAnalogUnits(type_t type, index_t index) const =0
virtual size_t getAnalogRangeCount(type_t type, index_t index) const =0
virtual int setAnalogUnits(type_t type, index_t index, index_t units)=0
void unregisterDriver(const std::string &)
Definition: daq.cpp:114
virtual size_t getAnalogDownsample(type_t type, index_t index) const =0
virtual index_t getAnalogRange(type_t type, index_t index) const =0
Driver(const std::string &name)
Definition: daq.cpp:33
virtual int setAnalogOffsetUnits(type_t type, index_t index, index_t units)=0
std::map< std::string, Driver * > driverMap
Definition: daq.h:132
Device * loadDevice(const std::string &driver, const std::list< std::string > &params)
Definition: daq.cpp:52
void insertDevice(Device *)
Definition: daq.cpp:66
Manager(const Manager &)
Definition: daq.h:116
Definition: mutex.h:28
virtual double getAnalogCalibrationValue(type_t type, index_t index) const =0
Manager(void)
Definition: daq.h:114
Manager & operator=(const Manager &)
Definition: daq.h:117
virtual size_t getAnalogUnitsCount(type_t type, index_t index) const =0
virtual int setAnalogRange(type_t type, index_t index, index_t range)=0
virtual int setAnalogCalibrationActive(type_t type, index_t index, bool state)=0
void foreachDevice(void(*callback)(Device *, void *), void *param)
Definition: daq.cpp:43
Definition: daq.h:59
direction_t
Definition: daq.h:57
Definition: daq.h:40
void registerDriver(Driver *, const std::string &)
Definition: daq.cpp:97
virtual bool getChannelActive(type_t type, index_t index) const =0
virtual bool getAnalogCalibrationState(type_t type, index_t index) const =0
Definition: daq.h:44
DAQ Oriented Classes.
Definition: daq.h:32
virtual int setAnalogZeroOffset(type_t type, index_t index, double offset)=0
Definition: daq.h:43
virtual bool getAnalogCalibrationActive(type_t type, index_t index) const =0
std::string name
Definition: daq.h:422
virtual int setAnalogCalibrationValue(type_t type, index_t index, double value)=0
virtual int setAnalogGain(type_t type, index_t index, double gain)=0
Mutex mutex
Definition: daq.h:130
virtual ~Device(void)
Definition: daq.cpp:28
virtual index_t getAnalogReference(type_t type, index_t index) const =0
static Manager * getInstance(void)
Definition: daq.cpp:129
virtual size_t getAnalogReferenceCount(type_t type, index_t index) const =0
virtual std::string getAnalogReferenceString(type_t type, index_t index, index_t reference) const =0
std::list< Device * > devices
Definition: daq.h:131
virtual int setDigitalDirection(index_t index, direction_t direction)=0
virtual std::string getAnalogRangeString(type_t type, index_t index, index_t range) const =0
void removeDevice(Device *)
Definition: daq.cpp:85
virtual Device * createDevice(const std::list< std::string > &args)=0
Definition: rt.h:498
type_t
Definition: daq.h:38
virtual int setAnalogCounter(type_t type, index_t index)=0
virtual size_t getChannelCount(type_t type) const =0
virtual double getAnalogGain(type_t type, index_t index) const =0
virtual index_t getAnalogOffsetUnits(type_t type, index_t index) const =0
virtual int setAnalogDownsample(type_t type, index_t index, size_t downsample)=0
virtual std::string getAnalogUnitsString(type_t type, index_t index, index_t units) const =0
virtual ~Driver(void)
Definition: daq.cpp:38
virtual int setAnalogReference(type_t type, index_t index, index_t reference)=0
~Manager(void)
Definition: daq.h:115
Definition: daq.h:41