00001
00006 #ifndef _GISI_GISU_HXX_
00007 #define _GISI_GISU_HXX_
00008
00009 #include "cplRaw/sm.hxx"
00010 #include "cplRaw/dbg.hxx"
00011 #include "gpib/gumi_user.hxx"
00012 #include "gpibc/gumi_msgs.hxx"
00013 #include <iostream>
00014 #include <vector>
00015
00016 class Block;
00017
00018 namespace INdepGpib100 {
00019 namespace Umi=INdepUmi100;
00020 namespace Gif=INdepGpib100;
00021
00022 typedef int DelE;
00023
00027 class GpibAddress {
00028 int _iPa;
00029 bool _fSa;
00030 int _iSa;
00031 public:
00036 friend bool operator==(const GpibAddress &gaL, const GpibAddress& gaR) {
00037 return (
00038 gaL._iPa == gaR._iPa &&
00039 gaL._fSa == gaR._fSa &&
00040 gaL._iSa == gaR._iSa
00041 );
00042 }
00043 friend bool operator!=(const GpibAddress &gaL, const GpibAddress& gaR) { return !operator==(gaL, gaR); }
00044 bool fSa() const { return _fSa; }
00045 int iPa() const { return _iPa; }
00046 int iSa() const { return _iSa; }
00051 GpibAddress(int iPa, bool fSa=false, int iSa=0): _iPa(iPa), _fSa(fSa), _iSa(iSa) {}
00052
00055 GpibAddress(): _iPa(0), _fSa(false), _iSa(0) {}
00056 ~GpibAddress() {}
00057 };
00058
00061 class GpibAddrList:public std::vector<GpibAddress> { };
00062 class GpibStbList:public std::vector<char> { };
00063 class GpibResList:public std::vector<short> { };
00064
00069 class GpibCmds {
00070 enum {
00071 MAX_CMD=40
00072 };
00073 char _mpch[MAX_CMD];
00074 char *_pch;
00075 GpibAddress _ga;
00076
00077 bool canput(unsigned i) { return _pch+i < _mpch+MAX_CMD; }
00078 void put(int ch) { *(_pch++)=ch; }
00079
00080 public:
00081
00082 void setupReceive( const GpibAddress &gaFrom);
00083 void setupReceive( );
00084 void setupSend( const GpibAddress& gaTo );
00085 void setupSendAdd( const GpibAddress &gaTo );
00086 void setupSend( const GpibAddrList &gal );
00087 void cmdAdd( int i);
00088 void addr( int cmd, const GpibAddress &ga);
00089
00090 unsigned size() { return _pch-_mpch; }
00091 char *mpch() { return _mpch; }
00092 char *pch() { return _mpch; }
00093 void clear() { _pch=_mpch; }
00094 GpibCmds(const GpibAddress &ga):_pch(_mpch), _ga(ga) {}
00095 ~GpibCmds() {}
00096 };
00097
00114 class GpibControl:public Failable, public SmM, public DebugLog {
00115 Umi::Umi *_mppum[2];
00116 int _iTrans;
00117
00118 ErrE _eErr;
00119 Gif::StatE _fStat;
00120 GpibInfo _gi;
00121 GpibAddress _ga;
00122 int _iPaLast;
00123 bool _fSc;
00124 bool _fDel;
00125 const Gpib_gco_Proto _pt;
00126 enum { S_CLOSED, S_OPEN };
00127
00128
00129
00130 Umi::Umi *pum() const { return _mppum[0]; }
00131 void wait();
00132 void signal();
00133
00134 void setTransNext() { _iTrans ++ ; }
00135 int iTransCur() { return _iTrans; }
00136 typedef INdepGpib100::StatE StatE;
00137
00138
00139
00140
00141 GpibControl &setState( GpibResp *pgh ) {
00142 _eErr=(ErrE)pgh->eErr();
00143 _fStat=(Gif::StatE)pgh->fStat();
00144 if (_eErr) Failable::setFailed("bus error no", _eErr);
00145 return *this;
00146 }
00147
00148 GpibControl &setState( GpibResp *pgh, int eState ) {
00149 setState(pgh);
00150 if (isGood()) SmM::setState(eState);
00151 return *this;
00152 }
00154 GpibControl &setFailed( Umi::Umi *pum) {
00155 Failable::setBad(__FILE__, __LINE__, pum);
00156 return *this;
00157 }
00158
00159 GpibControl &setFailed( ErrE eErr ) {
00160 if ((_eErr=eErr)) Failable::setFailed("error no", _eErr);
00161 return *this;
00162 }
00163
00164 #if 0
00165 int setFailed( Umi::Umi *pum, int i ) { return i; }
00166 GpibControl &setFailed( Umi::Umi *pum ) { return *this; }
00167
00168
00169
00170
00171
00172 GpibControl &setFailed(ErrE i) { _eErr=i; return *this; }
00173
00174 void pushReceivedMessages(Umi::UmiControl*, Umi::UmiData*);
00175 #endif
00176
00177
00178 int cwr(Block &bl, const Umi::Time &ti, const GpibTermOut *gto, GpibTrf *ptr);
00179
00180 GpibControl &getLines(unsigned *pf, const Umi::Time &tiSettle);
00181
00185 GpibControl &xchMsg(const Umi::UmiControl&uc);
00186
00187 public:
00188
00189
00190
00191
00192
00193
00194
00195 ErrE eErr() const { return _eErr; }
00196 bool isErr(ErrE e) const { return _eErr == e; }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00216 GpibControl &open(bool fSc, const GpibAddress &ga);
00217
00222 GpibControl &close();
00224
00229
00231 GpibControl &updateStb(const GpibSta &gst);
00232
00234 GpibControl &ifc(const Umi::Time &ti=Umi::Time(0, 100000));
00235
00237 GpibControl &ren(bool f);
00238
00244 GpibControl &cac(bool fSync);
00245
00250 GpibControl >s();
00251
00252 GpibControl &ist(bool f);
00253 GpibControl &iblinec( unsigned *pCap );
00254 GpibControl &iblines( unsigned *pStat );
00257 GpibControl &rtl();
00258 GpibControl &ppc(int v);
00259 GpibControl &rpp(unsigned char *chPpr, const Umi::Time &ti=Umi::Time());
00280 GpibControl &wait(StatE fStat, const Umi::Time &ti, bool fIgnTmo=false);
00281
00286 StatE fStat() { return _fStat; }
00287
00288
00289
00290
00291
00292
00293
00294
00296
00302
00313 int cmd( const char *pch, int c, const Umi::Time &ti );
00314
00325 int cwr( const char *pch, int c, const Umi::Time &ti, const GpibTermOut >o );
00326
00330 int cwr( const char *pch1, int c1, const char *pch2, int c2, const Umi::Time &ti, const GpibTermOut & );
00331
00332
00347 int crd( char *pch, int c, const Umi::Time &ti, const GpibTermIn >i, DelE *peDel=0 );
00348
00350
00355 bool isSc() { return _fSc; }
00356 int iPa() { return _ga.iPa(); }
00357 int iSa() { return _ga.iSa(); }
00358 bool fSa() { return _ga.fSa(); }
00359 const GpibAddress &ga() const { return _ga; }
00360 int iPaLast() { return _iPaLast; }
00361 void clrPaLast(int i) { _iPaLast=i; }
00362 int isOpen() { return isState(S_OPEN); }
00364
00371
00372
00373
00375 GpibControl &sendCmds(const char *, unsigned *pc, const Umi::Time &ti=Umi::Time(10));
00376
00378 GpibControl &sendSetup(const GpibAddrList &al, const Umi::Time&ti=Umi::Time(10));
00379
00381 GpibControl &sendDataBytes(
00382 const char *, unsigned *pc,
00383 const char *szTerm="\n",
00384 const GpibTermOut>o=GpibTermOut().fEnd(true),
00385 const Umi::Time&ti=Umi::Time(10)
00386 );
00387
00389 GpibControl &send(
00390 const GpibAddress &,
00391 const char *, unsigned *pc,
00392 const char *szTerm="\n",
00393 const GpibTermOut>o=GpibTermOut().fEnd(true),
00394 const Umi::Time&ti=Umi::Time(10)
00395 );
00396
00398 GpibControl &send(
00399 const GpibAddrList &,
00400 const char *, unsigned *pc,
00401 const char *szTerm="\n",
00402 const GpibTermOut>o=GpibTermOut().fEnd(true),
00403 const Umi::Time&ti=Umi::Time(10)
00404 );
00405
00407 GpibControl &sendsz(
00408 const GpibAddress &ga,
00409 const char *pch,
00410 const char *szTerm="\n",
00411 const GpibTermOut>o=GpibTermOut().fEnd(true),
00412 const Umi::Time&ti=Umi::Time(10)
00413 ) {
00414 unsigned c(strlen(pch));
00415 return send(ga, pch, &c, szTerm, gto, ti);
00416 }
00417
00419 GpibControl &receiveSetup(const GpibAddress &ga, const Umi::Time&ti=Umi::Time(10));
00420
00422 GpibControl &rcvRespMsg(char *, unsigned *pc, const GpibTermIn>i=GpibTermIn(), const Umi::Time&ti=Umi::Time(10), DelE *peDel=0);
00423
00424
00426 GpibControl &receive(char *, unsigned *pc, const GpibAddress &,
00427 const GpibTermIn>i=GpibTermIn(),
00428 const Umi::Time&ti=Umi::Time(10),
00429 DelE *peDel=0
00430 );
00431
00433 GpibControl &sendIfc();
00434
00436 GpibControl &devClear( const GpibAddrList &al, const Umi::Time&ti=Umi::Time(10));
00438 GpibControl &clear(const GpibAddress &gad, const Umi::Time &ti=Umi::Time(10));
00439
00441 GpibControl &devClear( const Umi::Time&ti=Umi::Time(10));
00442
00444 GpibControl &enableLocal( const GpibAddrList &al, const Umi::Time&ti=Umi::Time(10));
00446 GpibControl &enableLocal( );
00447
00449 GpibControl &enableRemote( const GpibAddrList &al, const Umi::Time&ti=Umi::Time(10));
00450
00452 GpibControl &setRWLS( const GpibAddrList &al, const Umi::Time&ti=Umi::Time(10));
00453
00455 GpibControl &sendLLO( const Umi::Time&ti=Umi::Time(10));
00456
00458 GpibControl &passControl( const GpibAddress &al, const Umi::Time&ti=Umi::Time(10));
00459
00461 GpibControl &ppoll( unsigned *puRes, const Umi::Time&ti=Umi::Time(0));
00462
00464 GpibControl &ppollConfig( const GpibAddress &ga, int iLine, int iSense, const Umi::Time&ti=Umi::Time(10));
00465
00467 GpibControl &ppollUnconfig( const GpibAddrList &ga, const Umi::Time&ti=Umi::Time(10));
00469 GpibControl &ppollUnconfig( const Umi::Time&ti=Umi::Time(10));
00470
00472 GpibControl &readStatusByte(char *pch, const GpibAddress &gad, const Umi::Time &ti=Umi::Time(10));
00473
00475 GpibControl &trigger(const GpibAddrList &ga, const Umi::Time &ti=Umi::Time(10));
00476
00478 GpibControl &reset(const GpibAddrList &ga, const Umi::Time &ti=Umi::Time(10));
00479
00481 GpibControl &findRqs(char *pch, GpibAddrList::const_iterator *pit, const GpibAddrList &ga, const Umi::Time &ti=Umi::Time(10));
00482
00483
00485 GpibControl &allSpoll(GpibStbList *pgs, const GpibAddrList &ga, const Umi::Time &ti=Umi::Time(10));
00486
00488 GpibControl &findLstn(GpibAddrList *pga, const GpibAddrList &ga, const Umi::Time &tiSettle=Umi::Time(0,1000000), const Umi::Time &ti=Umi::Time(10));
00489
00491 GpibControl &testSys(GpibResList *prl, const GpibAddrList &ga, const Umi::Time &ti=Umi::Time(10));
00493
00494 GpibControl( Umi::Factory *puf);
00495 GpibControl( Umi::Umi *pum );
00496 ~GpibControl() ;
00497 };
00503 class GpibInterfaceControl:public Failable {
00504 GpibControl *_pGuc;
00505
00506
00507 public:
00508 GpibControl *pGuc() { return _pGuc; }
00509 GpibControl *pGucRelease();
00516 GpibInterfaceControl(const char *sz);
00517 ~GpibInterfaceControl();
00518 };
00519
00520
00598
00599
00600
00601 }
00602
00603 namespace INdepUmi100 {
00613 }
00614
00618 #endif