iop_comedi.h
Go to the documentation of this file.
1 /** @file iop_comedi.h Hardware access via comedi */
2 
3 /*
4  FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2008, Thomas Moor, Sebastian Perk
7  Exclusive copyright is granted to Klaus Schmidt
8 
9 */
10 
11 
12 
13 #ifndef FAUDES_COMEDI_H
14 #define FAUDES_COMEDI_H
15 
16 #include "corefaudes.h"
17 #include "iop_sdevice.h"
18 
19 
20 // comedi support
21 #ifdef FAUDES_IODEVICE_COMEDI
22 
23 #include <comedilib.h>
24 
25 namespace faudes {
26 
27 
28 /**
29  * A cDevice implements signal based io via the comedi framework.
30  *
31  * The comedi framework provides an abstract interface to all sorts of
32  * IO devices in a control and data sampling context. It includes digital
33  * IO which faudes uses for physical signals. To use the cDevice class,
34  * you need to install the comedi library and load the comedi kernel modul.
35  * See www.comedi.org for further details.
36  *
37  * Note: the current implementation of cDevice is tailored to the lrt
38  * lab experiment. it expects the following configuration:
39  * - advantech 1754 device on /dev/comedi0 (64 input signals)
40  * - advantech 1752 device on /dev/comedi1 (64 output signals)
41  * You may adapt/use the provided "comedi_configure" script to set up the
42  * comedi framework. Future versions of cDevice will provide a more general support
43  * of comedi devices.
44  *
45  * @ingroup IODevicePlugin
46  */
47 
48 class FAUDES_API cDevice : public sDevice {
49 
50 FAUDES_TYPE_DECLARATION(ComediDevice,cDevice,sDevice)
51 
52  public:
53  /**
54  * Default constructor
55  */
56  cDevice(void);
57 
58  /**
59  * Copy constructor (TODO!)
60  */
61  cDevice(const cDevice&) : sDevice() {};
62 
63  /**
64  * Explicit destructor.
65  */
66  virtual ~cDevice(void);
67 
68 
69  /**
70  * Activate the device. This function opens relevant comedi devices and enables
71  * output execution and input reading.
72  * It starts the background thread for edge detection and input event buffer.
73  *
74  * @exception Exception
75  * - not yet configured (id 551)
76  * - failed to open comedi devices (id 552)
77  */
78  virtual void Start(void);
79 
80  /**
81  * Deactivate the device. This function closes the comedi devices
82  * and disables output execution and input reading.
83  * It stops the background thread and resets all output signals to 0.
84  */
85  virtual void Stop(void);
86 
87  protected:
88 
89  /** Reads non-event-configuration data from tokenreader
90  *
91  * This function is part of the non-event-configuration data input-system. Device data
92  * will be read w.r.t the class-hierarchy. Therefore first thing to do is to call the base
93  * class. See sDevice::DoReadPreface for further information.
94  *
95  * After base-class function returned the device-system-file will be read. This file
96  * is needed to establish the communication-interface to IO-card provided by the comedi-
97  * framework. See www.comedi.org for more information
98  *
99  * Note: in order to keep the inputfile-layout as easy as possible no label will be used to separate
100  * this data-section. Never the less a default-label ("ComediDevice") is specified.
101  *
102  * @param rTr
103  * TokenReader to read from
104  * @param rLabel
105  * Section to read
106  * @param pContext
107  * Read context to provide contextual information
108  *
109  * */
110  void DoReadPreface(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
111 
112  /** Writes non-event-configuration data from tokenreader
113  *
114  * This function is part of the non-event-configuration data output-system. Device data
115  * will be written w.r.t the class-hierarchy. Therefore first thing to do is to the base
116  * class. See sDevice::DoWritePreface for further information.
117  *
118  * After base-class function returned the device-system-file will be written to tokenwriter.
119  *
120  * Note: in order to keep the outputfile-layout as easy as possible no label will be used to separate
121  * this data-section. Never the less a default-label ("ComediDevice") is specified.
122  *
123  * @param rTw
124  * TokenWriter to write
125  * @param rLabel
126  * Section to write
127  * @param pContext
128  * Context to provide contextual information
129  *
130  * */
131  void DoWritePreface(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const ;
132 
133 
134  /**
135  * IO Hook, outputs
136  *
137  * Note: the current implementation uses bit write.
138  *
139  * @return
140  * True on success, false on KBUS error
141  *
142  */
143  virtual bool DoWriteSignalsPre(void);
144 
145  /**
146  * IO Hook, outputs
147  *
148  * Note: the current implementation uses bit write.
149  *
150  */
151  virtual void DoWriteSignalsPost(void);
152 
153  /**
154  * Set output signal.
155  *
156  * Hardware output via comedi.
157  *
158  * @param bitaddr
159  * Abstract bit address
160  * @param value
161  * True for logic level high;
162  *
163  */
164  virtual void DoWriteSignal(int bitaddr, bool value);
165 
166  /**
167  * IO Hook, inputs
168  *
169  * The comedi device uses a bit image as buffer
170  *
171  * @return
172  * True on success, false on KBUS error
173  *
174  */
175  virtual bool DoReadSignalsPre(void);
176 
177  /**
178  * IO Hook, inputs
179  *
180  * The comedi device uses a bit image as buffer
181  *
182  */
183  virtual void DoReadSignalsPost(void);
184 
185  /**
186  * Get input signal.
187  *
188  * Hardware input via comedi.
189  *
190  * @param bitaddr
191  * Abstract bit address
192  * @return
193  * True for logic level high;
194  */
195  virtual bool DoReadSignal(int bitaddr);
196 
197 
198  /** System file needed for device-initialization */
199  std::string mSystemFile;
200 
201  /** ComediDevice-handle */
202  comedi_t* mDev;
203 
204  /** Bit image (must be 32bit datatype) */
205  typedef unsigned int ComediInt32;
206  int mComediSubdevs;
207  ComediInt32 mComediMask[32];
208  ComediInt32* mpInputImage;
209  ComediInt32* mpOutputImage;
210 
211 };
212 
213 } // namespace
214 
215 #endif // configure
216 
217 #endif // include
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:81
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
faudes type declaration macro
Definition: cfl_types.h:867
Includes all libFAUDES headers, no plugins.
Virtual device for signal based io
libFAUDES resides within the namespace faudes.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen