Index: /trunk/FACT++/src/agilentctrl.cc
===================================================================
--- /trunk/FACT++/src/agilentctrl.cc	(revision 14323)
+++ /trunk/FACT++/src/agilentctrl.cc	(revision 14324)
@@ -60,4 +60,5 @@
     
     boost::asio::deadline_timer fCheckStatusTimer;
+    boost::asio::deadline_timer fAntiFloddingTimer;
 
     void PostStatusRequest()
@@ -111,4 +112,15 @@
 
     int  fLineCounter;
+
+    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::ReceivedStatusHandler, this,
+                                         bapla::error, bapla::bytes_transferred, 0));
+
+        // FIXME: Add timeout here
+    }
 
     void ReceivedStatusHandler(const bs::error_code& err, size_t bytes_received, int /*type*/)
@@ -136,5 +148,15 @@
 
         if (fIsVerbose)
+        {
            Out() << kBold << "Received (" << bytes_received << " bytes):" << endl;
+        }
+        // FIXME: the piece of code below causes a Seg Fault in case 
+        // The Agilent is not listening during program start, then after a while is 
+        // listening and after connection established.
+        // It sends: 1.) a string and 2.) and empty line (just an <Enter> pressed)
+        //
+        // then the agilent_ctrl segfaults ... was able to reproduce it.
+        // gdp just gave me the hint, that Time().GetAdStr() caused the Seg Fault in a way...
+        // Is Time threadsafe?
         /*
         if (fDump)
@@ -144,11 +166,8 @@
             Dump(msg.str());
         }
-*/
+        */
+
+
         istream is(&fBuffer);
-        // data should contain two floats:
-        //  * measured output voltage in volts
-        //  * measured ouput current in amperes
-        vector<float> data;
-
         fLineCounter++;
 
@@ -157,5 +176,5 @@
             // this is the Agilent identity string, do nothing
             string s;
-            is >> s;
+            getline(s,buffer, '\n');
             Out() << "ID string: " << s << endl;
         }
@@ -164,5 +183,4 @@
             // this should be a float containing the measured voltage
             is >> fMeasuredVoltage;
-            data.push_back(fMeasuredVoltage);
             Out() << "voltage: " << fMeasuredVoltage << endl;
         }
@@ -171,7 +189,14 @@
             // this should be a float containing the measured voltage
             is >> fMeasuredCurrent;
-            data.push_back(fMeasuredCurrent);
             Out() << "current: " << fMeasuredCurrent << endl;
             fLineCounter = 0;
+
+            // data should contain two floats:
+            //  * measured output voltage in volts
+            //  * measured ouput current in amperes
+            vector<float> data(2);
+            data[0] = fMeasuredVoltage;
+            data[1] = fMeasuredCurrent;
+            UpdateDim(data);
         }
        
@@ -195,24 +220,13 @@
             fState = State::kVoltage_Off;
         }
-
-        UpdateDim(data);
-        
         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::ReceivedStatusHandler, this,
-                                         bapla::error, bapla::bytes_transferred, 0));
-
-        // FIXME: Add timeout here
-    }
 
     // This is called when a connection was established
     void ConnectionEstablished()
     {
+        // DN 07.08.2012: The next line is imho not needed.
+        // But I'm in a train and cannot test it.
         fState = State::kConnected;
         Start_async_read_until();
@@ -228,5 +242,6 @@
         fIsVerbose(true),
         fDump(true),
-        fCheckStatusTimer(ioservice)
+        fCheckStatusTimer(ioservice),
+        fAntiFloddingTimer(ioservice)
     {
         SetLogStream(&imp);
@@ -250,15 +265,26 @@
         if (b)
         {
-            PostMessage(string("outp on\n"));
+            // check if the previous 'outp off' is some time ago
+            if (fAntiFloddingTimer.expires_at() > ba::deadline_timer::traits_type::now())
+            {
+                PostMessage(string("outp on\n"));
+            }
         }
         else
         {
             PostMessage(string("outp off\n"));
-        }
-	RequestStatus();
+            // start a Timer, which runs out in 60sec making sure, that the 
+            // camera can't be switched off&on on short time scales.
+            // sending repetetive outp off is possible
+            // sending repetivitve outp on is also posible
+            // switching off immediately after switching on is also possible.
+            fAntiFloddingTimer.expires_from_now(boost::posix_time::seconds(60));
+        }
+        RequestStatus();
     }
     
     int GetState() const
     {
+        // fState is set in ReceivedStatusHandler
         return fState;
     }
@@ -500,13 +526,18 @@
 {
     cout <<
-        "The ftmctrl controls the FSC (FACT Slow Control) board.\n"
+        "The agilentctrl controls the FACT camera power supply.\n"
+        "The powersupply is made by Agilent, so we call it 'The Agilent'. \n"
+        "Since FACT uses three Agilent Power Supplies with different output voltages\n"
+        "one might still not now which one ist controlled by this Program, so:\n"
         "\n"
-        "The default is that the program is started without user intercation. "
+        "This program controls the 48V Agilent."
+        "\n"
+        "The default is that the program is started with user intercation. "
         "All actions are supposed to arrive as DimCommands. Using the -c "
         "option, a local shell can be initialized. With h or help a short "
         "help message about the usuage can be brought to the screen.\n"
         "\n"
-        "Usage: fscctrl [-c type] [OPTIONS]\n"
-        "  or:  fscctrl [OPTIONS]\n";
+        "Usage: agilentctrl [-c type] [OPTIONS]\n"
+        "  or:  agilentctrl [OPTIONS]\n";
     cout << endl;
 }
@@ -515,21 +546,4 @@
 {
     Main::PrintHelp<StateMachineAgilent<StateMachine, ConnectionAgilent>>();
-
-    /* Additional help text which is printed after the configuration
-     options goes here */
-
-    /*
-     cout << "bla bla bla" << endl << endl;
-     cout << endl;
-     cout << "Environment:" << endl;
-     cout << "environment" << endl;
-     cout << endl;
-     cout << "Examples:" << endl;
-     cout << "test exam" << endl;
-     cout << endl;
-     cout << "Files:" << endl;
-     cout << "files" << endl;
-     cout << endl;
-     */
 }
 
