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 // have a dummy if comedi is not supported
00021 #ifndef FAUDES_IODEVICE_COMEDI
00022 namespace faudes {
00023 class cDevice : public sDevice {};
00024 }
00025 #else
00026 
00027 
00028 #include <comedilib.h>
00029 
00030 
00031 namespace faudes {
00032 
00033 
00034 
00035 /**
00036  * A cDevice implements signal based io via the comedi framework.
00037  *
00038  * The comedi framework provides an abstract interface to all sorts of
00039  * IO devices in a control and data sampling context. It includes digital
00040  * IO which faudes uses for physical signals. To use the cDevice class,
00041  * you need to install the comedi library and load the comedi kernel modul.
00042  * See www.comedi.org for further details.
00043  *
00044  * Note: the current implementation of cDevice is tailored to the lrt
00045  * lab experiment. it expects the following configuration:
00046  *  - advantech 1754 device on /dev/comedi0 (64 input signals)
00047  *  - advantech 1752 device on /dev/comedi1 (64 output signals)
00048  * You may adapt/use the provided  "comedi_configure" script to set up the
00049  * comedi framework. Future versions of cDevice will provide a more general support
00050  * of comedi devices.
00051  *
00052  * @ingroup IODevicePlugin
00053  */
00054 
00055 class cDevice : public sDevice {
00056 
00057  public:
00058   /**
00059    * Default constructor
00060    */
00061   cDevice(void);
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    * actuator execution and sensor reading.
00072    * It starts the background thread for edge detection and sensor 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 actuator execution and sensor reading.
00083    * It stops the background thread and resets all actuator 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    * Set output signal.
00135    *
00136    * Hardware output via comedi.
00137    *
00138    * @param bitaddr
00139    *   Abstract bit address
00140    * @param value
00141    *  True for logic level high;
00142    *
00143    */
00144   virtual void DoWriteSignal(int bitaddr, bool value);
00145 
00146   /**
00147    * Get input signal.
00148    *
00149    * Hardware input via comedi.
00150    *
00151    * @param bitaddr
00152    *   Abstract bit address
00153    * @return
00154    *  True for logic level high;
00155    */
00156   virtual bool DoReadSignal(int bitaddr);
00157 
00158 
00159   /** System file needed for device-initialization */
00160   std::string mSystemFile;
00161 
00162   /** ComediDevice-handle */
00163   comedi_t* mDev;
00164 
00165 }; //class cDevice
00166 
00167 } //namespace faudes
00168 
00169 #endif // comedi support
00170 
00171 
00172 #endif // include

libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6