libFAUDES

Sections

Index

iop_wago.h

Go to the documentation of this file.
00001 /** @file iop_wago.h Hardware access via comedi */
00002 
00003 /*
00004    FAU Discrete Event Systems Library (libfaudes)
00005 
00006    Copyright (C) 2009, Thomas Wittmann, Thomas Moor.
00007    Copyright (C) 2010, Thomas Moor.
00008 
00009 */
00010 
00011 
00012 
00013 #ifndef FAUDES_IOW_WAGO_H
00014 #define FAUDES_IOW_WAGO_H
00015 
00016 // Include core-libary and iodevice
00017 #include "corefaudes.h"
00018 #include "iop_include.h"
00019 
00020 
00021 // Wago-hardware 
00022 #ifdef FAUDES_IODEVICE_WAGO
00023 
00024 // Include wago-headers
00025 extern "C"{
00026 #include "kbus.h"
00027 #include "libUIO.h"
00028 }
00029 
00030 namespace faudes {
00031 
00032 
00033 
00034 /**
00035  * Signal-based I/O for WAGO IPC with kBus interface.
00036  *
00037  * The wDevice provides access to the kBus (Klemmenbus) used by WAGO to read and write
00038  * the process-image of the respective IPC configuration. 
00039  * 
00040  * Note: the current implementation of wDevice uses the bit addressing in the
00041  * IEC process image according to WAGO specifications. For the LRT lab experient,
00042  * digital inputs and outputs range from bitaddress 0 to 15, respectively. You may use
00043  * the <tt>iomonitor</tt> to identify the address scheme of your kbus configuration.
00044  *
00045  * Note: this device compiles under Linux only. Compilation requires WAGO supplied
00046  * libraries that can be obtained from WAGO; see also the tutorial README.
00047  * This device must be explicitely anabled 
00048  * Makefile.plugin.
00049  * 
00050  * @ingroup  IODevicePlugin
00051  */
00052 
00053 class wDevice : public sDevice {
00054 
00055  public:
00056 
00057   /**
00058    * Default constructor
00059    */
00060   wDevice(void);
00061 
00062   /**
00063    * Explicit destructor.
00064    */
00065   virtual ~wDevice(void);
00066 
00067 
00068   /**
00069    * Activate the device. This function opens/initializes the kbus support libraries and 
00070    * sets up the internal kbus-thread. Furthermore it invalidates the io-images. 
00071    * During the actual read- and write-process this will be reversed if admissable. 
00072    *
00073    * In oder to enable signal-edge detection the faudes-background thread will be started
00074    *
00075    * @exception Exception
00076    *   - not yet configured (id not configured)
00077    *   - failed to open kbus (id not configured)
00078    */
00079   virtual void Start(void);
00080 
00081   /**
00082    * Deactivate the device. This function shuts the kbus and related mechanisms down 
00083    * and disables actuator execution and sensor reading.
00084    * It stops the background thread and resets all actuator signals to 0.
00085    */
00086   virtual void Stop(void);
00087 
00088 protected:
00089   
00090   /**
00091    * wago API access
00092    *
00093    **/
00094 
00095   // Initialze kbus
00096   int kbusInit(void);
00097   // Shutdown kbus
00098   void kbusShutdown(void);
00099   // Get pointer to the kbus-info structure
00100   struct kbus_info* kbusGetInfo(void);
00101 
00102   
00103  
00104 
00105   /**
00106    * IO Hook, sensors
00107    *
00108    * The Wago device uses the pre hook to lock the process image.
00109    *
00110    * @return 
00111    *  True on success, false on KBUS error
00112    *
00113    */
00114   virtual bool DoReadSignalsPre(void);
00115 
00116   /**
00117    * IO Hook, sensors
00118    *
00119    * The Wago device uses the post hook to release the process image.
00120    *
00121    *
00122    */
00123   virtual void DoReadSignalsPost(void);
00124 
00125   /**
00126    * Get input signal.
00127    *
00128    * Extract bit value from image.
00129    *
00130    * @param bitaddr
00131    *   Abstract bit address
00132    * @return
00133    *  True for logic level high;
00134    */
00135   virtual bool DoReadSignal(int bitaddr);
00136   
00137   /**
00138    * IO Hook, actuators
00139    *
00140    * The Wago device uses the pre hook to lock the process image.
00141    *
00142    * @return 
00143    *  True on success, false on KBUS error
00144    *
00145    */
00146   virtual bool DoWriteSignalsPre(void);
00147 
00148   /**
00149    * IO Hook, actuators
00150    *
00151    * The Wago device uses the post hook to release the process image.
00152    *
00153    *
00154    */
00155   virtual void DoWriteSignalsPost(void);
00156 
00157   /**
00158    * Set output signal.
00159    *
00160    * Set value of bit in process image.
00161    *
00162    * @param bitaddr
00163    *   Abstract bit address
00164    * @param value
00165    *  True for logic level high;
00166    *
00167    */
00168   virtual void DoWriteSignal(int bitaddr, bool value);
00169 
00170   /** Read non-event-related configuration data from tokenreader
00171    *
00172    *
00173    * @param rTr
00174    *   TokenReader to read from
00175    * @param rLabel
00176    *   Section to read
00177    * @param pContext
00178    *   Read context to provide contextual information
00179    *
00180    * */
00181   void DoReadPreface(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
00182 
00183   /**  Write non-event-related configuration data to tokenreader
00184      *
00185      *
00186      * @param rTw
00187      *   TokenWriter to write
00188      * @param rLabel
00189      *   Section to write
00190      * @param pContext
00191      *   Context to provide contextual information
00192      *
00193      * */
00194   void DoWritePreface(TokenWriter& rTw, const std::string& rLabel,  const Type* pContext) const ;
00195 
00196   // used to store copy of process-image; 
00197   struct kbus_iec_process_image mIECProcessImage;
00198   struct kbus_info *mpKbusInfo;
00199 
00200   // process image pointers
00201   char* pInputImage;
00202   char* pOutputImage;
00203 
00204   // kbus api error flag
00205   bool mKbusOk;
00206 
00207 }; //class wDevice
00208 
00209 } //namespace 
00210 
00211 
00212 #endif // wago support
00213 
00214 #endif // include

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