iop_comedi.hGo to the documentation of this file.00001 /** @file iop_comedi.h Hardware access via comedi */ 00002 00003 /* 00004 FAU Discrete Event Systems Library (libfaudes) 00005 00006 Copyright (C) 2008, Thomas Moor, Sebastian Perk 00007 Exclusive copyright is granted to Klaus Schmidt 00008 00009 */ 00010 00011 00012 00013 #ifndef FAUDES_COMEDI_H 00014 #define FAUDES_COMEDI_H 00015 00016 #include "corefaudes.h" 00017 #include "iop_sdevice.h" 00018 00019 00020 // comedi support 00021 #ifdef FAUDES_IODEVICE_COMEDI 00022 00023 #include <comedilib.h> 00024 00025 namespace faudes { 00026 00027 00028 /** 00029 * A cDevice implements signal based io via the comedi framework. 00030 * 00031 * The comedi framework provides an abstract interface to all sorts of 00032 * IO devices in a control and data sampling context. It includes digital 00033 * IO which faudes uses for physical signals. To use the cDevice class, 00034 * you need to install the comedi library and load the comedi kernel modul. 00035 * See www.comedi.org for further details. 00036 * 00037 * Note: the current implementation of cDevice is tailored to the lrt 00038 * lab experiment. it expects the following configuration: 00039 * - advantech 1754 device on /dev/comedi0 (64 input signals) 00040 * - advantech 1752 device on /dev/comedi1 (64 output signals) 00041 * You may adapt/use the provided "comedi_configure" script to set up the 00042 * comedi framework. Future versions of cDevice will provide a more general support 00043 * of comedi devices. 00044 * 00045 * @ingroup IODevicePlugin 00046 */ 00047 00048 class cDevice : public sDevice { 00049 00050 FAUDES_TYPE_DECLARATION(ComediDevice,cDevice,sDevice) 00051 00052 public: 00053 /** 00054 * Default constructor 00055 */ 00056 cDevice(void); 00057 00058 /** 00059 * Copy constructor (TODO!) 00060 */ 00061 cDevice(const cDevice&) : sDevice() {}; 00062 00063 /** 00064 * Explicit destructor. 00065 */ 00066 virtual ~cDevice(void); 00067 00068 00069 /** 00070 * Activate the device. This function opens relevant comedi devices and enables 00071 * output execution and input reading. 00072 * It starts the background thread for edge detection and input event buffer. 00073 * 00074 * @exception Exception 00075 * - not yet configured (id 551) 00076 * - failed to open comedi devices (id 552) 00077 */ 00078 virtual void Start(void); 00079 00080 /** 00081 * Deactivate the device. This function closes the comedi devices 00082 * and disables output execution and input reading. 00083 * It stops the background thread and resets all output signals to 0. 00084 */ 00085 virtual void Stop(void); 00086 00087 protected: 00088 00089 /** Reads non-event-configuration data from tokenreader 00090 * 00091 * This function is part of the non-event-configuration data input-system. Device data 00092 * will be read w.r.t the class-hierarchy. Therefore first thing to do is to call the base 00093 * class. See sDevice::DoReadPreface for further information. 00094 * 00095 * After base-class function returned the device-system-file will be read. This file 00096 * is needed to establish the communication-interface to IO-card provided by the comedi- 00097 * framework. See www.comedi.org for more information 00098 * 00099 * Note: in order to keep the inputfile-layout as easy as possible no label will be used to separate 00100 * this data-section. Never the less a default-label ("ComediDevice") is specified. 00101 * 00102 * @param rTr 00103 * TokenReader to read from 00104 * @param rLabel 00105 * Section to read 00106 * @param pContext 00107 * Read context to provide contextual information 00108 * 00109 * */ 00110 void DoReadPreface(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0); 00111 00112 /** Writes non-event-configuration data from tokenreader 00113 * 00114 * This function is part of the non-event-configuration data output-system. Device data 00115 * will be written w.r.t the class-hierarchy. Therefore first thing to do is to the base 00116 * class. See sDevice::DoWritePreface for further information. 00117 * 00118 * After base-class function returned the device-system-file will be written to tokenwriter. 00119 * 00120 * Note: in order to keep the outputfile-layout as easy as possible no label will be used to separate 00121 * this data-section. Never the less a default-label ("ComediDevice") is specified. 00122 * 00123 * @param rTw 00124 * TokenWriter to write 00125 * @param rLabel 00126 * Section to write 00127 * @param pContext 00128 * Context to provide contextual information 00129 * 00130 * */ 00131 void DoWritePreface(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const ; 00132 00133 00134 /** 00135 * IO Hook, outputs 00136 * 00137 * Note: the current implementation uses bit write. 00138 * 00139 * @return 00140 * True on success, false on KBUS error 00141 * 00142 */ 00143 virtual bool DoWriteSignalsPre(void); 00144 00145 /** 00146 * IO Hook, outputs 00147 * 00148 * Note: the current implementation uses bit write. 00149 * 00150 */ 00151 virtual void DoWriteSignalsPost(void); 00152 00153 /** 00154 * Set output signal. 00155 * 00156 * Hardware output via comedi. 00157 * 00158 * @param bitaddr 00159 * Abstract bit address 00160 * @param value 00161 * True for logic level high; 00162 * 00163 */ 00164 virtual void DoWriteSignal(int bitaddr, bool value); 00165 00166 /** 00167 * IO Hook, inputs 00168 * 00169 * The comedi device uses a bit image as buffer 00170 * 00171 * @return 00172 * True on success, false on KBUS error 00173 * 00174 */ 00175 virtual bool DoReadSignalsPre(void); 00176 00177 /** 00178 * IO Hook, inputs 00179 * 00180 * The comedi device uses a bit image as buffer 00181 * 00182 */ 00183 virtual void DoReadSignalsPost(void); 00184 00185 /** 00186 * Get input signal. 00187 * 00188 * Hardware input via comedi. 00189 * 00190 * @param bitaddr 00191 * Abstract bit address 00192 * @return 00193 * True for logic level high; 00194 */ 00195 virtual bool DoReadSignal(int bitaddr); 00196 00197 00198 /** System file needed for device-initialization */ 00199 std::string mSystemFile; 00200 00201 /** ComediDevice-handle */ 00202 comedi_t* mDev; 00203 00204 /** Bit image (must be 32bit datatype) */ 00205 typedef unsigned int ComediInt32; 00206 int mComediSubdevs; 00207 ComediInt32 mComediMask[32]; 00208 ComediInt32* mpInputImage; 00209 ComediInt32* mpOutputImage; 00210 00211 }; 00212 00213 } // namespace 00214 00215 #endif // configure 00216 00217 #endif // include libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |