Index: trunk/FACT++/src/mcp.cc
===================================================================
--- trunk/FACT++/src/mcp.cc	(revision 16374)
+++ trunk/FACT++/src/mcp.cc	(revision 16375)
@@ -223,6 +223,21 @@
         Message(str);
 
+        // Strictly speaking, it is not necessary, but
+        // stopping the ratecontrol before we configure
+        // the FTM ensures that no threshold setting commands
+        // interfere with the configuration of the FTM.
+        if (fDimRC.state()!=RateControl::State::kConnected)
+        {
+            Dim::SendCommandNB("RATE_CONTROL/STOP");
+            Message("Stopping ratecontrol");
+        }
+
+        if (fDimLog.state()<30/*kSM_WaitForRun*/)
+        {
+            Dim::SendCommandNB("DATA_LOGGER/START_RUN_LOGGING");
+            Message("Starting datalogger");
+        }
+
         Update(MCP::State::kConfiguring1);
-
         return MCP::State::kConfiguring1;
     }
@@ -264,6 +279,6 @@
         Value *buf = GetBuffer();
 
+        Dim::SendCommandNB("FAD_CONTROL/CONFIGURE", buf, sizeof(Value)+fRunType.length()+1);
 	Message("Configuring FAD");
-        Dim::SendCommandNB("FAD_CONTROL/CONFIGURE", buf, sizeof(Value)+fRunType.length()+1);
 
         delete buf;
@@ -301,22 +316,9 @@
         if (GetCurrentState()==MCP::State::kConfiguring1)
         {
-            if (fDimLog.state()<30/*kSM_WaitForRun*/)
-            {
-                Message("Starting datalogger");
-                Dim::SendCommandNB("DATA_LOGGER/START_RUN_LOGGING");
-            }
-
+            if (fDimRC.state()!=RateControl::State::kConnected)
+                return MCP::State::kConfiguring1;
+
+            Dim::SendCommandNB("FTM_CONTROL/CONFIGURE", fRunType);
             Message("Configuring Trigger (FTM)");
-            Dim::SendCommandNB("FTM_CONTROL/CONFIGURE", fRunType);
-
-            // That's a bit stupid, but we have to stop the ratecontrol
-            // first, otherwise it might be detected to be
-            // in a state larger than Connected in Configuring3
-            // (because it still was) before the state change introduced
-            // by the Configuring2 state is even received. If instead
-            // we wait in Configuring2 for the rate control to be connected,
-            // we can be sure that it works.
-            Message("Stopping ratecontrol");
-            Dim::SendCommandNB("RATE_CONTROL/STOP");
 
             Update(MCP::State::kConfiguring2);
@@ -328,18 +330,11 @@
         if (GetCurrentState()==MCP::State::kConfiguring2)
         {
-            // FIMXE: Reset in case of error
-            if ((/*fDimFTM.state() != FTM::State::kConfiguring2 &&*/
-                 fDimFTM.state() != FTM::State::kConfigured) ||
+            if (fDimFTM.state() != FTM::State::kConfigured ||
                 fDimLog.state()<30 || fDimLog.state()>0xff ||
                 fDimRC.state()!=RateControl::State::kConnected)
                 return MCP::State::kConfiguring2;
 
-            // FIMXE: This is to make sure that the rate control
-            // has received the correct trigger setup already...
-            //usleep(1000000);
-
+            Dim::SendCommandNB("RATE_CONTROL/CALIBRATE_RUN", fRunType);
             Message("Starting Rate Control");
-            // State of RC is not reported back fast enough!
-            Dim::SendCommandNB("RATE_CONTROL/CALIBRATE_RUN", fRunType);
 
             ConfigureFAD();
@@ -375,6 +370,6 @@
                 return MCP::State::kConfiguring3;
 
+            Dim::SendCommandNB("FTM_CONTROL/START_TRIGGER");
             Message("Starting Trigger (FTM)");
-            Dim::SendCommandNB("FTM_CONTROL/START_TRIGGER");
 
             Update(MCP::State::kConfigured);
@@ -553,9 +548,9 @@
                      "Waiting for next configuration command");
         AddStateName(MCP::State::kConfiguring1, "Configuring1",
-                     "Starting configuration procedure, checking Datalogger state");
+                     "Starting configuration procedure, checking datalogger/ratecontrol state");
         AddStateName(MCP::State::kConfiguring2, "Configuring2",
-                     "Waiting for FTM and Datalogger to get ready");
+                     "Starting ratecontrol, waiting for FTM to get configured and Datalogger to get ready");
         AddStateName(MCP::State::kConfiguring3, "Configuring3",
-                     "Waiting for FADs and rate control to get ready");
+                     "Waiting for FADs and ratecontrol to get ready");
         /*
         AddStateName(MCP::State::kCrateReset0, "CrateReset0",
