iop_wago.h
Go to the documentation of this file.
1 /** @file iop_wago.h Hardware access via comedi */
2 
3 /*
4  FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2009, Thomas Wittmann, Thomas Moor.
7  Copyright (C) 2010, Thomas Moor.
8 
9 */
10 
11 
12 
13 #ifndef FAUDES_IOW_WAGO_H
14 #define FAUDES_IOW_WAGO_H
15 
16 // Include core-libary and iodevice
17 #include "corefaudes.h"
18 #include "iop_include.h"
19 
20 
21 // Wago-hardware
22 #ifdef FAUDES_IODEVICE_WAGO
23 
24 // Include wago-headers
25 extern "C"{
26 #include "kbus.h"
27 #include "libUIO.h"
28 }
29 
30 namespace faudes {
31 
32 
33 
34 /**
35  * Signal-based I/O for WAGO IPC with kBus interface.
36  *
37  * The wDevice provides access to the kBus (Klemmenbus) used by WAGO to read and write
38  * the process-image of the respective IPC configuration.
39  *
40  * Note: the current implementation of wDevice uses the bit addressing in the
41  * IEC process image according to WAGO specifications. For the LRT lab experient,
42  * digital inputs and outputs range from bitaddress 0 to 15, respectively. You may use
43  * the <tt>iomonitor</tt> to identify the address scheme of your kbus configuration.
44  *
45  * Note: this device compiles under Linux only. Compilation requires WAGO supplied
46  * libraries that can be obtained from WAGO; see also the tutorial README.
47  * This device must be explicitely anabled
48  * Makefile.plugin.
49  *
50  * @ingroup IODevicePlugin
51  */
52 
53 class wDevice : public sDevice {
54 
55 FAUDES_TYPE_DECLARATION(WagoDevice,wDevice,sDevice)
56 
57  public:
58 
59  /**
60  * Default constructor
61  */
62  wDevice(void);
63 
64  /**
65  * Copy constructor (TODO!)
66  */
67  wDevice(const wDevice&) : sDevice() {};
68 
69  /**
70  * Explicit destructor.
71  */
72  virtual ~wDevice(void);
73 
74 
75  /**
76  * Activate the device. This function opens/initializes the kbus support libraries and
77  * sets up the internal kbus-thread. Furthermore it invalidates the io-images.
78  * During the actual read- and write-process this will be reversed if admissable.
79  *
80  * In oder to enable signal-edge detection the faudes-background thread will be started
81  *
82  * @exception Exception
83  * - not yet configured (id not configured)
84  * - failed to open kbus (id not configured)
85  */
86  virtual void Start(void);
87 
88  /**
89  * Deactivate the device. This function shuts the kbus and related mechanisms down
90  * and disables output execution and input reading.
91  * It stops the background thread and resets all output signals to 0.
92  */
93  virtual void Stop(void);
94 
95 protected:
96 
97  /**
98  * wago API access
99  *
100  **/
101 
102  // Initialze kbus
103  int kbusInit(void);
104  // Shutdown kbus
105  void kbusShutdown(void);
106  // Get pointer to the kbus-info structure
107  struct kbus_info* kbusGetInfo(void);
108 
109 
110 
111 
112  /**
113  * IO Hook, inputs
114  *
115  * The Wago device uses the pre hook to lock the process image.
116  *
117  * @return
118  * True on success, false on KBUS error
119  *
120  */
121  virtual bool DoReadSignalsPre(void);
122 
123  /**
124  * IO Hook, inputs
125  *
126  * The Wago device uses the post hook to release the process image.
127  *
128  *
129  */
130  virtual void DoReadSignalsPost(void);
131 
132  /**
133  * Get input signal.
134  *
135  * Extract bit value from image.
136  *
137  * @param bitaddr
138  * Abstract bit address
139  * @return
140  * True for logic level high;
141  */
142  virtual bool DoReadSignal(int bitaddr);
143 
144  /**
145  * IO Hook, outputs
146  *
147  * The Wago device uses the pre hook to lock the process image.
148  *
149  * @return
150  * True on success, false on KBUS error
151  *
152  */
153  virtual bool DoWriteSignalsPre(void);
154 
155  /**
156  * IO Hook, outputs
157  *
158  * The Wago device uses the post hook to release the process image.
159  *
160  *
161  */
162  virtual void DoWriteSignalsPost(void);
163 
164  /**
165  * Set output signal.
166  *
167  * Set value of bit in process image.
168  *
169  * @param bitaddr
170  * Abstract bit address
171  * @param value
172  * True for logic level high;
173  *
174  */
175  virtual void DoWriteSignal(int bitaddr, bool value);
176 
177  /** Read non-event-related configuration data from tokenreader
178  *
179  *
180  * @param rTr
181  * TokenReader to read from
182  * @param rLabel
183  * Section to read
184  * @param pContext
185  * Read context to provide contextual information
186  *
187  * */
188  void DoReadPreface(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
189 
190  /** Write non-event-related configuration data to tokenreader
191  *
192  *
193  * @param rTw
194  * TokenWriter to write
195  * @param rLabel
196  * Section to write
197  * @param pContext
198  * Context to provide contextual information
199  *
200  * */
201  void DoWritePreface(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const ;
202 
203  // used to store copy of process-image;
204  struct kbus_iec_process_image mIECProcessImage;
205  struct kbus_info *mpKbusInfo;
206 
207  // process image pointers
208  char* pInputImage;
209  char* pOutputImage;
210 
211  // kbus api error flag
212  bool mKbusOk;
213 
214 }; //class wDevice
215 
216 } //namespace
217 
218 
219 #endif // configured
220 
221 #endif // include

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen