iop_wago.hGo 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 FAUDES_TYPE_DECLARATION(WagoDevice,wDevice,sDevice) 00056 00057 public: 00058 00059 /** 00060 * Default constructor 00061 */ 00062 wDevice(void); 00063 00064 /** 00065 * Copy constructor (TODO!) 00066 */ 00067 wDevice(const wDevice&) : sDevice() {}; 00068 00069 /** 00070 * Explicit destructor. 00071 */ 00072 virtual ~wDevice(void); 00073 00074 00075 /** 00076 * Activate the device. This function opens/initializes the kbus support libraries and 00077 * sets up the internal kbus-thread. Furthermore it invalidates the io-images. 00078 * During the actual read- and write-process this will be reversed if admissable. 00079 * 00080 * In oder to enable signal-edge detection the faudes-background thread will be started 00081 * 00082 * @exception Exception 00083 * - not yet configured (id not configured) 00084 * - failed to open kbus (id not configured) 00085 */ 00086 virtual void Start(void); 00087 00088 /** 00089 * Deactivate the device. This function shuts the kbus and related mechanisms down 00090 * and disables output execution and input reading. 00091 * It stops the background thread and resets all output signals to 0. 00092 */ 00093 virtual void Stop(void); 00094 00095 protected: 00096 00097 /** 00098 * wago API access 00099 * 00100 **/ 00101 00102 // Initialze kbus 00103 int kbusInit(void); 00104 // Shutdown kbus 00105 void kbusShutdown(void); 00106 // Get pointer to the kbus-info structure 00107 struct kbus_info* kbusGetInfo(void); 00108 00109 00110 00111 00112 /** 00113 * IO Hook, inputs 00114 * 00115 * The Wago device uses the pre hook to lock the process image. 00116 * 00117 * @return 00118 * True on success, false on KBUS error 00119 * 00120 */ 00121 virtual bool DoReadSignalsPre(void); 00122 00123 /** 00124 * IO Hook, inputs 00125 * 00126 * The Wago device uses the post hook to release the process image. 00127 * 00128 * 00129 */ 00130 virtual void DoReadSignalsPost(void); 00131 00132 /** 00133 * Get input signal. 00134 * 00135 * Extract bit value from image. 00136 * 00137 * @param bitaddr 00138 * Abstract bit address 00139 * @return 00140 * True for logic level high; 00141 */ 00142 virtual bool DoReadSignal(int bitaddr); 00143 00144 /** 00145 * IO Hook, outputs 00146 * 00147 * The Wago device uses the pre hook to lock the process image. 00148 * 00149 * @return 00150 * True on success, false on KBUS error 00151 * 00152 */ 00153 virtual bool DoWriteSignalsPre(void); 00154 00155 /** 00156 * IO Hook, outputs 00157 * 00158 * The Wago device uses the post hook to release the process image. 00159 * 00160 * 00161 */ 00162 virtual void DoWriteSignalsPost(void); 00163 00164 /** 00165 * Set output signal. 00166 * 00167 * Set value of bit in process image. 00168 * 00169 * @param bitaddr 00170 * Abstract bit address 00171 * @param value 00172 * True for logic level high; 00173 * 00174 */ 00175 virtual void DoWriteSignal(int bitaddr, bool value); 00176 00177 /** Read non-event-related configuration data from tokenreader 00178 * 00179 * 00180 * @param rTr 00181 * TokenReader to read from 00182 * @param rLabel 00183 * Section to read 00184 * @param pContext 00185 * Read context to provide contextual information 00186 * 00187 * */ 00188 void DoReadPreface(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0); 00189 00190 /** Write non-event-related configuration data to tokenreader 00191 * 00192 * 00193 * @param rTw 00194 * TokenWriter to write 00195 * @param rLabel 00196 * Section to write 00197 * @param pContext 00198 * Context to provide contextual information 00199 * 00200 * */ 00201 void DoWritePreface(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const ; 00202 00203 // used to store copy of process-image; 00204 struct kbus_iec_process_image mIECProcessImage; 00205 struct kbus_info *mpKbusInfo; 00206 00207 // process image pointers 00208 char* pInputImage; 00209 char* pOutputImage; 00210 00211 // kbus api error flag 00212 bool mKbusOk; 00213 00214 }; //class wDevice 00215 00216 } //namespace 00217 00218 00219 #endif // configured 00220 00221 #endif // include libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |