Ignore:
Timestamp:
08/06/12 11:57:06 (12 years ago)
Author:
neise
Message:
still tidying up
File:
1 edited

Legend:

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

    r14313 r14314  
    3131    bool fDump;
    3232
     33    int  fLineCounter;
     34
     35
    3336    ofstream fDumpStream;
    3437
     
    3841    {
    3942    }
    40 
    4143
    4244    void Dump(const string &str)
     
    9395        }
    9496
    95 
    9697        istream is(&fBuffer);
    97 
     98        // data should contain two floats:
     99        //  * measured output voltage in volts
     100        //  * measured ouput current in amperes
     101        vector<float> data;
     102
     103        fLineCounter++;
     104
     105        if (fLineCounter == 1)
     106        {
     107            // this is the Agilent identity string, do nothing
     108            string s;
     109            is >> s;
     110            Out() << "ID string: " << s << endl;
     111        }
     112        else if (fLineCounter == 2)
     113        {
     114            // this should be a float containing the measured voltage
     115            float f;
     116            is >> f;
     117            data.push_back(f);
     118            Out() << "voltage: " << f << endl;
     119        }
     120        else if (fLineCounter >= 3)
     121        {
     122            // this should be a float containing the measured voltage
     123            float f;
     124            is >> f;
     125            data.push_back(f);
     126            Out() << "current: " << f << endl;
     127            fLineCounter = 0;
     128            fSendRequest = true;
     129        }
     130
     131
     132//        int status=-1;
    98133
    99134        string buffer;
     
    124159        }
    125160
    126         // vector data should have to elements:
    127         //   * the measured voltage
    128         //   * the measured current
    129         vector<float> data;
     161
    130162        UpdateDim(data);
    131163
     
    145177    void ConnectionEstablished()
    146178    {
    147         fBuffer.prepare(10000);
     179        fLineCounter = 0;
     180        fSendRequest = true;
     181        fBuffer.prepare(1000);
     182        fTime = Time();
    148183        StartRead();
    149184    }
    150185
    151186public:
     187    Time fTime;
     188    bool fSendRequest;
     189
    152190    ConnectionAgilent(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
    153191        fIsVerbose(true),
     
    171209        if (b)
    172210        {
    173             PostMessage("outp on\n");
     211            PostMessage(string("outp on\n"));
    174212        }
    175213        else
    176214        {
    177             PostMessage("outp off\n");
     215            PostMessage(string("outp off\n"));
    178216        }
    179217    }
     
    181219    void Identify()
    182220    {
    183         PostMessage("*IDN?\n",6);
    184         PostMessage("meas:volt?\n",11);
    185         PostMessage("meas:curr?\n",11);
     221        PostMessage(string("*IDN?\n"));
     222        PostMessage(string("meas:volt?\n"));
     223        PostMessage(string("meas:curr?\n"));
    186224    }
    187225};
     
    212250        ConnectionAgilent(ioservice, imp),
    213251        fDim("AGILENT_CONTROL/DATA", "F:1;F:1",
    214                     "|U[V]: FACT supply voltage"
    215                     "|I[A]: current consumed by the FACT camera")
     252                    "|U[V]: output voltage"
     253                    "|I[A]: output current")
    216254    {
    217255        // nothing happens here.
     
    267305        // synchronously, i.e. within the call to poll_one()
    268306        poll_one();
    269 
     307        if (fAgilent.fSendRequest)
     308        {
     309            if (Time()-fAgilent.fTime > boost::posix_time::seconds(5))
     310            {
     311                fAgilent.Identify();
     312                fAgilent.fTime = Time();
     313                fAgilent.fSendRequest = false;
     314            }
     315        }
    270316        return fAgilent.IsConnected() ? State::kConnected : State::kDisconnected;
    271317    }
     
    358404             "|[host][string]:new ethernet address in the form <host:port>");
    359405
    360         T::AddEvent("OUTPUT", "B:1")
     406        T::AddEvent("OUTPUT", "B:1", State::kConnected)
    361407            (bind(&StateMachineAgilent::SetOutput, this, placeholders::_1))
    362408            ("set output on or off"
    363409             "|[state][boolean]: output setting (1;0 or 'on';'off')");
    364410
    365         T::AddEvent("IDENTIFY")
     411        T::AddEvent("IDENTIFY", State::kConnected)
    366412            (bind(&StateMachineAgilent::Identify, this))
    367413            ("Request Agilent ID");
Note: See TracChangeset for help on using the changeset viewer.