libFAUDES

Sections

Index

iop_comedi.h

Go 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; see end of file for dummy
00021 #ifdef FAUDES_IODEVICE_COMEDI
00022 
00023 #include <comedilib.h>
00024 
00025 
00026 namespace faudes {
00027 
00028 
00029 
00030 /**
00031  * A cDevice implements signal based io via the comedi framework.
00032  *
00033  * The comedi framework provides an abstract interface to all sorts of
00034  * IO devices in a control and data sampling context. It includes digital
00035  * IO which faudes uses for physical signals. To use the cDevice class,
00036  * you need to install the comedi library and load the comedi kernel modul.
00037  * See www.comedi.org for further details.
00038  *
00039  * Note: the current implementation of cDevice is tailored to the lrt
00040  * lab experiment. it expects the following configuration:
00041  *  - advantech 1754 device on /dev/comedi0 (64 input signals)
00042  *  - advantech 1752 device on /dev/comedi1 (64 output signals)
00043  * You may adapt/use the provided  "comedi_configure" script to set up the
00044  * comedi framework. Future versions of cDevice will provide a more general support
00045  * of comedi devices.
00046  *
00047  * @ingroup IODevicePlugin
00048  */
00049 
00050 class cDevice : public sDevice {
00051 
00052  public:
00053   /**
00054    * Default constructor
00055    */
00056   cDevice(void);
00057 
00058   /**
00059    * Explicit destructor.
00060    */
00061   virtual ~cDevice(void);
00062 
00063 
00064   /**
00065    * Activate the device. This function opens relevant comedi devices and enables
00066    * actuator execution and sensor reading.
00067    * It starts the background thread for edge detection and sensor event buffer.
00068    *
00069    * @exception Exception
00070    *   - not yet configured (id 551)
00071    *   - failed to open comedi devices (id 552)
00072    */
00073   virtual void Start(void);
00074 
00075   /**
00076    * Deactivate the device. This function closes the comedi devices
00077    * and disables actuator execution and sensor reading.
00078    * It stops the background thread and resets all actuator signals to 0.
00079    */
00080   virtual void Stop(void);
00081 
00082 protected:
00083 
00084   /** Reads non-event-configuration data from tokenreader
00085    *
00086    * This function is part of the non-event-configuration data input-system. Device data
00087    * will be read w.r.t the class-hierarchy. Therefore first thing to do is to call the base
00088    * class. See sDevice::DoReadPreface for further information.
00089    *
00090    * After base-class function returned the device-system-file will be read. This file
00091    * is needed to establish the communication-interface to IO-card provided by the comedi-
00092    * framework. See www.comedi.org for more information
00093    *
00094    * Note: in order to keep the inputfile-layout as easy as possible no label will be used to separate
00095    *     this data-section. Never the less a default-label ("ComediDevice") is specified.
00096    *
00097    * @param rTr
00098    *   TokenReader to read from
00099    * @param rLabel
00100    *   Section to read
00101    * @param pContext
00102    *   Read context to provide contextual information
00103    *
00104    * */
00105   void DoReadPreface(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
00106 
00107   /**  Writes non-event-configuration data from tokenreader
00108      *
00109      * This function is part of the non-event-configuration data output-system. Device data
00110      * will be written w.r.t the class-hierarchy. Therefore first thing to do is to the base
00111      * class. See sDevice::DoWritePreface for further information.
00112      *
00113      * After base-class function returned the device-system-file will be written to tokenwriter.
00114      *
00115      * Note: in order to keep the outputfile-layout as easy as possible no label will be used to separate
00116      *       this data-section. Never the less a default-label ("ComediDevice") is specified.
00117      *
00118      * @param rTw
00119      *   TokenWriter to write
00120      * @param rLabel
00121      *   Section to write
00122      * @param pContext
00123      *   Context to provide contextual information
00124      *
00125      * */
00126   void DoWritePreface(TokenWriter& rTw, const std::string& rLabel,  const Type* pContext) const ;
00127 
00128   /**
00129    * Set output signal.
00130    *
00131    * Hardware output via comedi.
00132    *
00133    * @param bitaddr
00134    *   Abstract bit address
00135    * @param value
00136    *  True for logic level high;
00137    *
00138    */
00139   virtual void DoWriteSignal(int bitaddr, bool value);
00140 
00141   /**
00142    * Get input signal.
00143    *
00144    * Hardware input via comedi.
00145    *
00146    * @param bitaddr
00147    *   Abstract bit address
00148    * @return
00149    *  True for logic level high;
00150    */
00151   virtual bool DoReadSignal(int bitaddr);
00152 
00153 
00154   /** System file needed for device-initialization */
00155   std::string mSystemFile;
00156 
00157   /** ComediDevice-handle */
00158   comedi_t* mDev;
00159 
00160 };
00161 
00162 } //namespace faudes
00163 
00164 
00165 
00166 #endif
00167 
00168 
00169 #endif // include

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3