Changeset 12279 for trunk/FACT++


Ignore:
Timestamp:
10/26/11 19:42:19 (13 years ago)
Author:
tbretz
Message:
Added some more output in case the previous answer was not yet recived; reset the ramping state when a new connection was established; do not reset voltages if we were previously connected.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/biasctrl.cc

    r12270 r12279  
    6060    bool fIsInitializing;
    6161    bool fIsRamping;
    62     bool fWaitingForAnswer;
     62    int fWaitingForAnswer;
    6363
    6464    vector<uint64_t> fCounter;
     
    505505        case kCmdRead:
    506506            HandleReceivedData(fBuffer, bytes_received, command, send_counter);
    507             fWaitingForAnswer = false;
     507            fWaitingForAnswer = -1;
    508508            return;
    509509
     
    578578    void ConnectionEstablished()
    579579    {
     580        // We connect for the first time or haven't received
     581        // a valid warp counter yet... this procedure also sets
     582        // our volatges to 0 if we have connected but never received
     583        // any answer.
     584        if (fWrapCounter<0)
     585        {
     586            fVolt.assign(   kNumChannels, 0);
     587            fVoltRef.assign(kNumChannels, 0);
     588            fVoltCmd.assign(kNumChannels, 0);
     589        }
     590
    580591        // Reset everything....
    581592        fSendCounter    = -1;
     
    583594        fGlobalVoltCmd  = -1;
    584595        fIsInitializing = true;
    585 
    586         fVolt.assign(   kNumChannels, 0);
    587         fVoltRef.assign(kNumChannels, 0);
    588         fVoltCmd.assign(kNumChannels, 0);
     596        fIsRamping      = false;
    589597
    590598        // Send a single 0 (and possible two consecutive 0's
     
    592600        PostMessage("\0", 1);
    593601        AsyncRead(ba::buffer(fBuffer, 3), kSynchronize, 0);//++fSendCounter);
    594         fWaitingForAnswer = true;
     602        fWaitingForAnswer = kSynchronize;
    595603
    596604        // Wait for some time before sending the next 0
     
    660668
    661669        if (special)
    662             fWaitingForAnswer = true;
     670            fWaitingForAnswer = special ? kResetChannels : kCmdChannelSet;
    663671    }
    664672
     
    764772        //fRefCurrent(kNumChannels),
    765773        fPresent(kNumBoards),
     774        fWrapCounter(-1),
    766775        fRampStep(-1),
    767776        fRampTime(-1),
     
    769778        fSyncTime(333),
    770779        fIsRamping(false),
    771         fWaitingForAnswer(false),
     780        fWaitingForAnswer(-1),
    772781        fCounter(8),
    773782        fVolt(kNumChannels),
     
    781790    void OverCurrentReset()
    782791    {
    783         if (fWaitingForAnswer)
    784         {
    785             Error("Answer on last command not yet received.");
     792        if (fWaitingForAnswer>=0)
     793        {
     794            ostringstream msg;
     795            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
     796            Error(msg);
    786797            return;
    787798        }
     
    803814    void ReadAllChannels(bool special = false)
    804815    {
    805         if (!special && fWaitingForAnswer)
    806         {
    807             Error("Answer on last command not yet received.");
     816        if (!special && fWaitingForAnswer>=0)
     817        {
     818            ostringstream msg;
     819            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
     820            Error(msg);
    808821            return;
    809822        }
     
    825838
    826839        if (!special)
    827             fWaitingForAnswer = true;
     840            fWaitingForAnswer = special ? kUpdate : kCmdRead;
    828841    }
    829842
     
    11071120    void ExpertReset(bool expert_mode=true)
    11081121    {
    1109         if (fWaitingForAnswer)
    1110         {
    1111             Error("Answer on last command not yet received.");
     1122        if (fWaitingForAnswer>=0)
     1123        {
     1124            ostringstream msg;
     1125            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
     1126            Error(msg);
    11121127            return;
    11131128        }
     
    11181133        PostMessage(GetCmd(kCmdReset));
    11191134        AsyncRead(ba::buffer(fBuffer, 3), kCmdReset, ++fSendCounter);
    1120         fWaitingForAnswer = true;
     1135        fWaitingForAnswer = kCmdReset;
    11211136    }
    11221137
     
    11241139    bool ExpertChannelSetDac(uint16_t ch, uint16_t dac)
    11251140    {
    1126         if (fWaitingForAnswer)
    1127         {
    1128             Error("Answer on last command not yet received.");
     1141        if (fWaitingForAnswer>=0)
     1142        {
     1143            ostringstream msg;
     1144            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
     1145            Error(msg);
    11291146            return false;
    11301147        }
     
    11421159        PostMessage(GetCmd(kCmdChannelSet, ch, dac));
    11431160        AsyncRead(ba::buffer(fBuffer, 3), kExpertChannelSet|(ch<<8), ++fSendCounter);
    1144         fWaitingForAnswer = true;
     1161        fWaitingForAnswer = kExpertChannelSet|(ch<<8);
    11451162
    11461163        return true;
     
    11541171    bool ExpertGlobalSetDac(uint16_t dac)
    11551172    {
    1156         if (fWaitingForAnswer)
    1157         {
    1158             Error("Answer on last command not yet received.");
     1173        if (fWaitingForAnswer>=0)
     1174        {
     1175            ostringstream msg;
     1176            msg << "Answer on last command (id=" << fWaitingForAnswer << ") not yet received.";
     1177            Error(msg);
    11591178            return false;
    11601179        }
     
    11771196        PostMessage(GetCmd(kCmdGlobalSet, 0, dac));
    11781197        AsyncRead(ba::buffer(fBuffer, 3), kCmdGlobalSet, ++fSendCounter);
    1179         fWaitingForAnswer = true;
     1198        fWaitingForAnswer = kCmdGlobalSet;
    11801199
    11811200        return true;
Note: See TracChangeset for help on using the changeset viewer.