RTXI  3.0.0
The Real-Time eXperiment Interface Reference Manual
daq.hpp
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,
4  Will Cornell Medical College
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #ifndef DAQ_DEVICE_H
22 #define DAQ_DEVICE_H
23 
24 #include <cmath>
25 #include <cstddef>
26 #include <map>
27 
28 #include "io.hpp"
29 #include "rt.hpp"
30 
32 
36 namespace DAQ
37 {
38 
39 using analog_range_t = std::pair<double, double>;
40 
41 namespace ChannelType
42 {
46 enum type_t : size_t
47 {
48  AI = 0,
49  AO,
50  DI,
51  DO,
52  UNKNOWN
53 };
54 
55 inline std::string type2string(type_t type)
56 {
57  std::string result;
58  switch (type) {
59  case AI:
60  result = "Analog Input";
61  break;
62  case AO:
63  result = "Analog Output";
64  break;
65  case DI:
66  result = "Digital Input";
67  break;
68  case DO:
69  result = "Digital Output";
70  break;
71  default:
72  ERROR_MSG("DAQ::ChannelType::type2string : Unknown type used");
73  break;
74  }
75  return result;
76 }
77 } // namespace ChannelType
78 
82 typedef uint64_t index_t;
83 
87 static const index_t INVALID = static_cast<index_t>(-1);
88 
93 {
96 };
97 
98 namespace Reference
99 {
100 enum reference_t : size_t
101 {
102  GROUND = 0,
106  UNKNOWN
107 };
108 } // namespace Reference
109 
110 inline std::array<analog_range_t, 7> get_default_ranges()
111 {
112  return {
113  std::pair(-10.0, 10.0),
114  std::pair(-5.0, 5.0),
115  std::pair(-1.0, 1.0),
116  std::pair(-0.5, 0.5),
117  std::pair(-0.2, 0.2),
118  std::pair(-0.1, 0.1),
119  };
120 }
121 
122 inline std::array<std::string, 2> get_default_units()
123 {
124  return {"volts", "amps"};
125 }
126 
130 class Device : public RT::Device
131 {
132 public:
139  Device(const std::string& dev_name,
140  const std::vector<IO::channel_t>& channels)
141  : RT::Device(dev_name, channels)
142  {
143  }
144 
151  virtual size_t getChannelCount(ChannelType::type_t type) const = 0;
152 
161  index_t index) const = 0;
162 
171  index_t index,
172  bool state) = 0;
173 
180  virtual size_t getAnalogRangeCount(index_t index) const = 0;
181 
188  virtual size_t getAnalogReferenceCount(index_t index) const = 0;
189 
196  virtual size_t getAnalogUnitsCount(index_t index) const = 0;
198  index_t index) const = 0;
199 
208  virtual std::string getAnalogRangeString(ChannelType::type_t type,
209  index_t index,
210  index_t range) const = 0;
211 
221  index_t index,
222  index_t reference) const = 0;
223 
232  virtual std::string getAnalogUnitsString(ChannelType::type_t type,
233  index_t index,
234  index_t units) const = 0;
235 
243  virtual double getAnalogGain(ChannelType::type_t type,
244  index_t index) const = 0;
245 
254  index_t index) const = 0;
255 
264  index_t index) const = 0;
265 
274  index_t index) const = 0;
275 
284  index_t index) const = 0;
285 
294  index_t index) const = 0;
295 
305  index_t index,
306  double gain) = 0;
307 
317  index_t index,
318  index_t range) = 0;
319 
329  index_t index,
330  double offset) = 0;
331 
341  index_t index,
342  index_t reference) = 0;
343 
353  index_t index,
354  index_t units) = 0;
355 
365  index_t index,
366  index_t units) = 0;
368  index_t index,
369  size_t downsample) = 0;
370  virtual int setAnalogCounter(ChannelType::type_t type, index_t index) = 0;
371 
381  index_t index,
382  double value) = 0;
383 
392  index_t index) const = 0;
393 
402  index_t index,
403  bool state) = 0;
404 
413  index_t index) const = 0;
414 
423  index_t index) const = 0;
424 
432  virtual int setDigitalDirection(index_t index, direction_t direction) = 0;
433 
434 }; // class Device
435 
441 class Driver
442 {
443 public:
449  explicit Driver(std::string dev_name)
450  : name(std::move(dev_name))
451  {
452  }
453  Driver(const Driver&) = default; // copy constructor
454  Driver& operator=(const Driver&) = default; // copy assignment operator
455  Driver(Driver&&) = default; // move constructor
456  Driver& operator=(Driver&&) = default; // move assignment operator
457  virtual ~Driver() = default;
458 
459  virtual void loadDevices() = 0;
460  virtual void unloadDevices() = 0;
461 
462  virtual std::vector<DAQ::Device*> getDevices() = 0;
463  std::string getDriverName() { return this->name; }
464 
465 private:
466  std::string name;
467 }; // class Driver
468 
469 } // namespace DAQ
470 
471 #endif // DAQ_DEVICE_H
virtual size_t getAnalogDownsample(ChannelType::type_t type, index_t index) const =0
virtual int setAnalogCalibrationActive(ChannelType::type_t type, index_t index, bool state)=0
virtual index_t getAnalogOffsetUnits(ChannelType::type_t type, index_t index) const =0
virtual index_t getAnalogRange(ChannelType::type_t type, index_t index) const =0
virtual size_t getAnalogUnitsCount(index_t index) const =0
virtual int setAnalogOffsetUnits(ChannelType::type_t type, index_t index, index_t units)=0
virtual double getAnalogZeroOffset(ChannelType::type_t type, index_t index) const =0
virtual bool getChannelActive(ChannelType::type_t type, index_t index) const =0
virtual bool getAnalogCalibrationActive(ChannelType::type_t type, index_t index) const =0
virtual int setAnalogZeroOffset(ChannelType::type_t type, index_t index, double offset)=0
virtual std::string getAnalogReferenceString(ChannelType::type_t type, index_t index, index_t reference) const =0
virtual int setDigitalDirection(index_t index, direction_t direction)=0
virtual size_t getAnalogReferenceCount(index_t index) const =0
virtual double getAnalogCalibrationValue(ChannelType::type_t type, index_t index) const =0
virtual double getAnalogGain(ChannelType::type_t type, index_t index) const =0
virtual bool getAnalogCalibrationState(ChannelType::type_t type, index_t index) const =0
Device(const std::string &dev_name, const std::vector< IO::channel_t > &channels)
Definition: daq.hpp:139
virtual int setAnalogCalibrationValue(ChannelType::type_t type, index_t index, double value)=0
virtual size_t getChannelCount(ChannelType::type_t type) const =0
virtual index_t getAnalogReference(ChannelType::type_t type, index_t index) const =0
virtual int setChannelActive(ChannelType::type_t type, index_t index, bool state)=0
virtual int setAnalogRange(ChannelType::type_t type, index_t index, index_t range)=0
virtual int setAnalogGain(ChannelType::type_t type, index_t index, double gain)=0
virtual int setAnalogCounter(ChannelType::type_t type, index_t index)=0
virtual int setAnalogReference(ChannelType::type_t type, index_t index, index_t reference)=0
virtual int setAnalogUnits(ChannelType::type_t type, index_t index, index_t units)=0
virtual int setAnalogDownsample(ChannelType::type_t type, index_t index, size_t downsample)=0
virtual std::string getAnalogUnitsString(ChannelType::type_t type, index_t index, index_t units) const =0
virtual size_t getAnalogRangeCount(index_t index) const =0
virtual std::string getAnalogRangeString(ChannelType::type_t type, index_t index, index_t range) const =0
virtual index_t getAnalogUnits(ChannelType::type_t type, index_t index) const =0
virtual std::vector< DAQ::Device * > getDevices()=0
Driver(Driver &&)=default
virtual ~Driver()=default
Driver & operator=(Driver &&)=default
virtual void unloadDevices()=0
Driver & operator=(const Driver &)=default
Driver(const Driver &)=default
Driver(std::string dev_name)
Definition: daq.hpp:449
virtual void loadDevices()=0
std::string getDriverName()
Definition: daq.hpp:463
void ERROR_MSG(const std::string &errmsg, Args... args)
Definition: debug.hpp:36
std::string type2string(type_t type)
Definition: daq.hpp:55
@ DIFFERENTIAL
Definition: daq.hpp:104
DAQ Oriented Classes.
Definition: daq.hpp:37
uint64_t index_t
Definition: daq.hpp:82
std::array< std::string, 2 > get_default_units()
Definition: daq.hpp:122
std::array< analog_range_t, 7 > get_default_ranges()
Definition: daq.hpp:110
std::pair< double, double > analog_range_t
Definition: daq.hpp:39
direction_t
Definition: daq.hpp:93
@ INPUT
Definition: daq.hpp:94
@ OUTPUT
Definition: daq.hpp:95
Definition: fifo.cpp:31