diff --git a/src/Fug.cpp b/src/Fug.cpp index 4ca0721804a30229e63b01831c71a45ac86a3bd1..a7784265a140918423362ae75cbd8438757b910c 100644 --- a/src/Fug.cpp +++ b/src/Fug.cpp @@ -127,6 +127,22 @@ void Fug::delete_device() { delete mutex; } +/* + * timestamp() + * send a timestamp to standard output + */ +void Fug::msg2err(const char *msg) +{ + struct tm *mytime; + char timeLong[80]; + time_t myTime_t; + myTime_t = time(NULL); + mytime = localtime(&myTime_t); + // memset(mytime, 0, sizeof(tmTemp)); + strftime(timeLong, 79, "%Y-%m-%d %H:%M:%S ", mytime); + // strftime(timeShort, 79, "%H:%M:%S ", mytime); + cerr << timeLong << msg << endl; +} //+---------------------------------------------------------------------------- // @@ -829,6 +845,11 @@ void Fug::write_Fug(string input) { e, static_cast<const char *>(rsn), out_stream.str(), static_cast<const char *>("SerialDeviceServer error"), Tango::ERR); } + catch (...) { + std::exception_ptr p = std::current_exception(); + std::cerr <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl; + msg2err("DevSerWriteString write_Fug"); + } /*printf("write %s: %s\n",device_name.c_str(),input.c_str());*/ @@ -879,6 +900,11 @@ string Fug::read_Fug() { e, static_cast<const char *>(rsn), out_stream.str(), static_cast<const char *>("SerialDeviceServer error"), Tango::ERR); } + catch (...) { + std::exception_ptr p = std::current_exception(); + std::cerr <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl; + msg2err("read_Fug DevSerWriteString"); + } omni_thread::sleep( 0, sleeptime * 1000000); // convert millisecond to microsecond @@ -894,6 +920,11 @@ string Fug::read_Fug() { e, static_cast<const char *>(rsn), out_stream.str(), static_cast<const char *>("SerialDeviceServer error"), Tango::ERR); } + catch (...) { + std::exception_ptr p = std::current_exception(); + std::cerr <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl; + msg2err("read_Fug DevSerReadRaw"); + } Dout >> strout; if (strout.length() == 0) { @@ -910,13 +941,20 @@ string Fug::read_Fug() { omni_thread::sleep(0, FUG_SER_SLEEP * 1000000); - i = 0; - while (strout[i] == 'E') { - if (strout[i+3] == '\n' || strout[i+3] == '\r' || strout[i+3] == '\0') i++; - i += 3; + try { + i = 0; + while (strout[i] == 'E') { + if (strout[i+3] == '\n' || strout[i+3] == '\r' || strout[i+3] == '\0') i++; + i += 3; + } + strout_filt.resize(strout.length() - i); + strncpy((char *)strout_filt.c_str(), (char *)strout.c_str() + i, strout.length() - i); + } + catch (...) { + std::exception_ptr p = std::current_exception(); + std::cerr <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl; + msg2err("read_Fug misc"); } - strout_filt.resize(strout.length() - i); - strncpy((char *)strout_filt.c_str(), (char *)strout.c_str() + i, strout.length() - i); /*printf("read %s: %s\n",device_name.c_str(),strout_filt.c_str());*/ diff --git a/src/Fug.h b/src/Fug.h index ca2293d9477e269d4f503676968ffc86bcb3ecb5..6ad16ac58eb870b49b239941f1782eaaef18f669 100644 --- a/src/Fug.h +++ b/src/Fug.h @@ -321,6 +321,7 @@ public : friend class fugthread; private : + void msg2err(const char *msg); Tango::DeviceProxy *devserial; int abortflag; // flag used to abort loops (On,Off,Standby) bool FugStat[5];