Index: trunk/FACT++/src/HeadersAgilent.h
===================================================================
--- trunk/FACT++/src/HeadersAgilent.h	(revision 14314)
+++ trunk/FACT++/src/HeadersAgilent.h	(revision 14315)
@@ -10,4 +10,6 @@
             kDisconnected = 1,
             kConnected    = 2,
+            kVoltage_On   = 3,
+            kVoltage_Off  = 4,
         };
     }
Index: trunk/FACT++/src/agilentctrl.cc
===================================================================
--- trunk/FACT++/src/agilentctrl.cc	(revision 14314)
+++ trunk/FACT++/src/agilentctrl.cc	(revision 14315)
@@ -17,5 +17,5 @@
 namespace ba    = boost::asio;
 namespace bs    = boost::system;
-namespace dummy = ba::placeholders;
+namespace bapla = ba::placeholders;
 
 using namespace std;
@@ -27,12 +27,9 @@
 {
     boost::asio::streambuf fBuffer;
-
     bool fIsVerbose;
     bool fDump;
-
-    int  fLineCounter;
-
-
     ofstream fDumpStream;
+    int fState;
+    
 
 protected:
@@ -59,10 +56,63 @@
         fDumpStream << str << endl;
     }
-
+    
+    boost::asio::deadline_timer fCheckStatusTimer;
+
+    void PostStatusRequest()
+    {
+        PostMessage(string("*IDN?\n"));
+        PostMessage(string("meas:volt?\n"));
+        PostMessage(string("meas:curr?\n"));
+    }
+
+    
+    void RequestStatus()
+    {
+        PostStatusRequest();
+
+        fCheckStatusTimer.expires_from_now(boost::posix_time::seconds(60));
+        fCheckStatusTimer.async_wait(boost::bind(&ConnectionWeather::HandleRequest,
+                                          this, bapla::error));
+    }
+
+    void HandleRequest(const bs::error_code &error)
+    {
+        // 125: Operation canceled (bs::error_code(125, bs::system_category))
+        if (error && error!=ba::error::basic_errors::operation_aborted)
+        {
+            ostringstream str;
+            str << "Write timeout of " << URL() << ": " << error.message() << " (" << error << ")";// << endl;
+            Error(str);
+
+            PostClose(false);
+            return;
+        }
+
+        if (!is_open())
+        {
+            // For example: Here we could schedule a new accept if we
+            // would not want to allow two connections at the same time.
+            PostClose(true);
+            return;
+        }
+
+        // Check whether the deadline has passed. We compare the deadline
+        // against the current time since a new asynchronous operation
+        // may have moved the deadline before this actor had a chance
+        // to run.
+        if (fKeepAlive.expires_at() > ba::deadline_timer::traits_type::now())
+            return;
+
+        RequestStatus();
+    }
 private:
 
-
-    void HandleReceivedData(const bs::error_code& err, size_t bytes_received, int /*type*/)
-    {
+    int  fLineCounter;
+
+    void ReceivedStatusHandler(const bs::error_code& err, size_t bytes_received, int /*type*/)
+    {
+        float measured_voltage;
+        float measured_current;
+        
         // Do not schedule a new read if the connection failed.
         if (bytes_received==0 || err)
@@ -87,5 +137,4 @@
         if (fIsVerbose)
            Out() << kBold << "Received (" << bytes_received << " bytes):" << endl;
-
         if (fDump)
         {
@@ -113,61 +162,39 @@
         {
             // this should be a float containing the measured voltage
-            float f;
-            is >> f;
-            data.push_back(f);
-            Out() << "voltage: " << f << endl;
+            is >> measured_voltage;
+            data.push_back(measured_voltage);
+            Out() << "voltage: " << measured_voltage << endl;
         }
         else if (fLineCounter >= 3)
         {
             // this should be a float containing the measured voltage
-            float f;
-            is >> f;
-            data.push_back(f);
-            Out() << "current: " << f << endl;
+            is >> measured_current;
+            data.push_back(measured_current);
+            Out() << "current: " << measured_current << endl;
             fLineCounter = 0;
             fSendRequest = true;
         }
-
-
-//        int status=-1;
-
-        string buffer;
-        while (getline(is, buffer, '\n'))
-        {
-            if (fIsVerbose)
-                Out() << buffer << endl;
-            if (fDump)
-                Dump(buffer);
-
-            buffer = Tools::Trim(buffer);
-
-            if (buffer.empty())
-                continue;
-
-/*
-            istringstream in(buffer);
-            while (1)
-            {
-                float f;
-                in >> f;
-                if (!in)
-                    break;
-
-                resist.push_back(f);
-            }
-*/
-        }
-
+        
+        if (measured_voltage > 1.0)
+        {
+            fState = State::kVoltage_On;
+        }
+        else
+        {
+            fState = State::kVoltage_Off;
+        }
 
         UpdateDim(data);
-
-        StartRead();
-    }
-
-    void StartRead()
-    {
+        
+        Start_async_read_until();
+    }
+
+    void Start_async_read_until()
+    {
+        // Bind Received Data Handler to the event: "received <enter> character"
+        //   this Handler will try to parse the incoming data
         ba::async_read_until(*this, fBuffer, "\n",
-                             boost::bind(&ConnectionAgilent::HandleReceivedData, this,
-                                         dummy::error, dummy::bytes_transferred, 0));
+                             boost::bind(&ConnectionAgilent::ReceivedStatusHandler, this,
+                                         bapla::error, bapla::bytes_transferred, 0));
 
         // FIXME: Add timeout here
@@ -177,20 +204,21 @@
     void ConnectionEstablished()
     {
+        fState = State::kConnected;
+        Start_async_read_until();
+        PostStatusRequest();
+        
         fLineCounter = 0;
-        fSendRequest = true;
         fBuffer.prepare(1000);
-        fTime = Time();
-        StartRead();
     }
 
 public:
-    Time fTime;
-    bool fSendRequest;
 
     ConnectionAgilent(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
         fIsVerbose(true),
+        fCheckStatusTimer(ioservice),
         fDump(true)
     {
         SetLogStream(&imp);
+        fState = State::kDisconnected;
     }
 
@@ -216,11 +244,11 @@
         }
     }
-
-    void Identify()
-    {
-        PostMessage(string("*IDN?\n"));
-        PostMessage(string("meas:volt?\n"));
-        PostMessage(string("meas:curr?\n"));
-    }
+    
+    int GetState() const
+    {
+        return fState;
+    }
+
+
 };
 
@@ -305,14 +333,9 @@
         // synchronously, i.e. within the call to poll_one()
         poll_one();
-        if (fAgilent.fSendRequest)
-        {
-            if (Time()-fAgilent.fTime > boost::posix_time::seconds(5))
-            {
-                fAgilent.Identify();
-                fAgilent.fTime = Time();
-                fAgilent.fSendRequest = false;
-            }
-        }
-        return fAgilent.IsConnected() ? State::kConnected : State::kDisconnected;
+        
+        if ( fAgilent.IsConnected() )
+            return fWeather.GetState();
+        else
+            return State::kDisconnected;
     }
 
@@ -382,4 +405,10 @@
         T::AddStateName(State::kConnected, "Connected",
                      "Ethernet connection to Agilent established.");
+
+        T::AddStateName(State::kVoltage_On, "Voltage_On",
+                     "The measured output voltage is higher than 1.0V");
+
+        T::AddStateName(State::kVoltage_Off, "Voltage_Off",
+                     "The measured output voltage is lower than 1.0V");
 
         // Verbosity commands
