16 #ifdef FAUDES_IODEVICE_WAGO
21 extern int kbus_init(
void);
23 extern int kbus_shutdown(
void);
25 extern void start_kbus_thread(
void);
27 extern void kbus_update_image(
void);
29 extern int kbus_running(
void);
31 extern void *kbus_lock_input_image(
void);
33 extern void *kbus_lock_output_image(
void);
35 extern void kbus_release_io_image(
void);
45 AutoRegisterType<wDevice> gRtiRegisterWagoDevice(
"WagoDevice");
48 wDevice::wDevice(
void) : sDevice() {
49 FD_DHV(
"wDevice(" << mName <<
")::wDevice()");
51 mDefaultLabel =
"WagoDevice";
60 wDevice::~wDevice(
void) {
61 FD_DHV(
"wDevice(" << mName <<
")::~wDevice()");
66 void wDevice::Start(
void) {
70 if(mState!=Down)
return;
71 FD_DH(
"wDevice(" << mName <<
")::Start(): open devices");
73 int res = kbus_init();
76 FD_DHV(
"wDevice(" << mName <<
")::Start(): res = " << res );
79 std::stringstream errstr;
80 errstr <<
"cannot open kbus";
81 throw Exception(
"wDevice()::Start()", errstr.str(), 552);
94 void wDevice::Stop(
void) {
96 if(mState != Up && mState != StartUp)
return;
97 FD_DHV(
"wDevice(" << mName <<
")::Stop()");
106 void wDevice::DoWritePreface(TokenWriter& rTw,
const std::string& rLabel,
const Type* pContext)
const {
108 FD_DHV(
"wDevice("<<mName<<
")::DoWritePreface()");
110 sDevice::DoWritePreface(rTw,
"",pContext);
115 void wDevice::DoReadPreface(TokenReader& rTr,
const std::string& rLabel,
const Type* pContext){
117 FD_DHV(
"wDevice("<<mName<<
")::DoReadPreface()");
119 sDevice::DoReadPreface(rTr,
"",pContext);
124 bool wDevice::DoReadSignalsPre(
void) {
129 if(pInputImage)
return true;
133 if(pOutputImage)
return false;
136 pInputImage=(
char*) kbus_lock_input_image();
138 int kok= kbus_running();
142 if(mKbusOk)
FD_WARN(
"wDevice(" << mName <<
")::DoReadSignalsPre(): kbus error and friends ");
146 kbus_release_io_image();
157 FD_WARN(
"wDevice(" << mName <<
")::DoReadSignalsPre(): kbus recovered");
161 if(!mKbusOk) kbus_release_io_image();
170 void wDevice::DoReadSignalsPost(
void) {
173 if(pInputImage) kbus_release_io_image();
180 bool wDevice::DoReadSignal(
int bit){
188 return ( pInputImage[
byte] & (0x01 << (bit)) ) != 0x00;
193 bool wDevice::DoWriteSignalsPre(
void) {
195 if(pInputImage)
return false;
197 if(pOutputImage)
return true;
199 pOutputImage=(
char*) kbus_lock_output_image();
207 void wDevice::DoWriteSignalsPost(
void) {
209 if(pOutputImage) kbus_release_io_image();
216 void wDevice::DoWriteSignal(
int bit,
bool value){
220 int byte = (bit) / 8;
223 FD_DHV(
"wDevice(" << mName <<
")::DoWriteSignal(int): bit " << bit <<
" in byte " <<
byte);
227 if(value) pOutputImage[byte] |= (0x1 << (bit));
229 else pOutputImage[byte] &= ~(0x1 << (bit));
#define FD_WARN(message)
Debug: always report warnings.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Hardware access via comedi.
libFAUDES resides within the namespace faudes.