Index: trunk/FACT++/src/biasctrl.cc
===================================================================
--- trunk/FACT++/src/biasctrl.cc	(revision 12278)
+++ trunk/FACT++/src/biasctrl.cc	(revision 12279)
@@ -60,5 +60,5 @@
     bool fIsInitializing;
     bool fIsRamping;
-    bool fWaitingForAnswer;
+    int  fWaitingForAnswer;
 
     vector<uint64_t> fCounter;
@@ -505,5 +505,5 @@
         case kCmdRead:
             HandleReceivedData(fBuffer, bytes_received, command, send_counter);
-            fWaitingForAnswer = false;
+            fWaitingForAnswer = -1;
             return;
 
@@ -578,4 +578,15 @@
     void ConnectionEstablished()
     {
+        // We connect for the first time or haven't received
+        // a valid warp counter yet... this procedure also sets
+        // our volatges to 0 if we have connected but never received
+        // any answer.
+        if (fWrapCounter<0)
+        {
+            fVolt.assign(   kNumChannels, 0);
+            fVoltRef.assign(kNumChannels, 0);
+            fVoltCmd.assign(kNumChannels, 0);
+        }
+
         // Reset everything....
         fSendCounter    = -1;
@@ -583,8 +594,5 @@
         fGlobalVoltCmd  = -1;
         fIsInitializing = true;
-
-        fVolt.assign(   kNumChannels, 0);
-        fVoltRef.assign(kNumChannels, 0);
-        fVoltCmd.assign(kNumChannels, 0);
+        fIsRamping      = false;
 
         // Send a single 0 (and possible two consecutive 0's
@@ -592,5 +600,5 @@
         PostMessage("\0", 1);
         AsyncRead(ba::buffer(fBuffer, 3), kSynchronize, 0);//++fSendCounter);
-        fWaitingForAnswer = true;
+        fWaitingForAnswer = kSynchronize;
 
         // Wait for some time before sending the next 0
@@ -660,5 +668,5 @@
 
         if (special)
-            fWaitingForAnswer = true;
+            fWaitingForAnswer = special ? kResetChannels : kCmdChannelSet;
     }
 
@@ -764,4 +772,5 @@
         //fRefCurrent(kNumChannels),
         fPresent(kNumBoards),
+        fWrapCounter(-1),
         fRampStep(-1),
         fRampTime(-1),
@@ -769,5 +778,5 @@
         fSyncTime(333),
         fIsRamping(false),
-        fWaitingForAnswer(false),
+        fWaitingForAnswer(-1),
         fCounter(8),
         fVolt(kNumChannels),
@@ -781,7 +790,9 @@
     void OverCurrentReset()
     {
-        if (fWaitingForAnswer)
-        {
-            Error("Answer on last command not yet received.");
+        if (fWaitingForAnswer>=0)
+        {
+            ostringstream msg;
+            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
+            Error(msg);
             return;
         }
@@ -803,7 +814,9 @@
     void ReadAllChannels(bool special = false)
     {
-        if (!special && fWaitingForAnswer)
-        {
-            Error("Answer on last command not yet received.");
+        if (!special && fWaitingForAnswer>=0)
+        {
+            ostringstream msg;
+            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
+            Error(msg);
             return;
         }
@@ -825,5 +838,5 @@
 
         if (!special)
-            fWaitingForAnswer = true;
+            fWaitingForAnswer = special ? kUpdate : kCmdRead;
     }
 
@@ -1107,7 +1120,9 @@
     void ExpertReset(bool expert_mode=true)
     {
-        if (fWaitingForAnswer)
-        {
-            Error("Answer on last command not yet received.");
+        if (fWaitingForAnswer>=0)
+        {
+            ostringstream msg;
+            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
+            Error(msg);
             return;
         }
@@ -1118,5 +1133,5 @@
         PostMessage(GetCmd(kCmdReset));
         AsyncRead(ba::buffer(fBuffer, 3), kCmdReset, ++fSendCounter);
-        fWaitingForAnswer = true;
+        fWaitingForAnswer = kCmdReset;
     }
 
@@ -1124,7 +1139,9 @@
     bool ExpertChannelSetDac(uint16_t ch, uint16_t dac)
     {
-        if (fWaitingForAnswer)
-        {
-            Error("Answer on last command not yet received.");
+        if (fWaitingForAnswer>=0)
+        {
+            ostringstream msg;
+            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
+            Error(msg);
             return false;
         }
@@ -1142,5 +1159,5 @@
         PostMessage(GetCmd(kCmdChannelSet, ch, dac));
         AsyncRead(ba::buffer(fBuffer, 3), kExpertChannelSet|(ch<<8), ++fSendCounter);
-        fWaitingForAnswer = true;
+        fWaitingForAnswer = kExpertChannelSet|(ch<<8);
 
         return true;
@@ -1154,7 +1171,9 @@
     bool ExpertGlobalSetDac(uint16_t dac)
     {
-        if (fWaitingForAnswer)
-        {
-            Error("Answer on last command not yet received.");
+        if (fWaitingForAnswer>=0)
+        {
+            ostringstream msg;
+            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
+            Error(msg);
             return false;
         }
@@ -1177,5 +1196,5 @@
         PostMessage(GetCmd(kCmdGlobalSet, 0, dac));
         AsyncRead(ba::buffer(fBuffer, 3), kCmdGlobalSet, ++fSendCounter);
-        fWaitingForAnswer = true;
+        fWaitingForAnswer = kCmdGlobalSet;
 
         return true;
