00001 00002 00003 00004 00005 00006 00007
00008 #ifndef GPIBEquipment_h
00009 #define GPIBEquipment_h
00010
00011 #include <iosfwd>
00012
00013
00014
00015
00016 #ifdef __STLPORT_STD
00017 #include <streambuf>
00018 #include <istream>
00019 #endif
00020 #include <string>
00021 #include "LibGPIB.h"
00022
00023 extern "C++" {
00024 namespace LibGPIB {
00025 class GPIBController ;
00026 class GPIBEquipment ;
00027
00038 class GPIBEquipmentBuffer : public streambuf {
00039 #ifdef __GNUG__
00040
00041
00042
00043
00044 typedef char char_type ;
00045 typedef int int_type ;
00046 typedef int streamsize ;
00047 #endif
00048 public:
00058 GPIBEquipmentBuffer(GPIBEquipment *device) ;
00059 protected:
00077 virtual streambuf* setbuf(char_type *, streamsize) ;
00078
00084 virtual int_type overflow(int_type c) ;
00085
00093 virtual int_type uflow() ;
00094
00102 virtual int_type underflow() ;
00103
00110 virtual streamsize xsgetn(char_type *s, streamsize n) ;
00111
00118 virtual streamsize xsputn(const char_type* s, streamsize n) ;
00119
00127 virtual int_type pbackfail(int_type c = EOF) ;
00128 private:
00132 GPIBEquipment *mParentGPIBEquipment ;
00133
00139 char mPutbackChar ;
00140
00146 bool mPutbackAvailable ;
00147
00153 char_type GetChar() ;
00154
00159 void PutChar(const char_type c) ;
00160 } ;
00161
00162 inline
00163 GPIBEquipmentBuffer::GPIBEquipmentBuffer(GPIBEquipment *device) :
00164 mParentGPIBEquipment(device),
00165 mPutbackAvailable(false),
00166 mPutbackChar(0) {
00167
00168
00169
00170 setbuf(0, 0) ;
00171 }
00172
00173 inline
00174 streambuf *
00175 GPIBEquipmentBuffer::setbuf(char_type *, streamsize) {
00176
00177
00178
00179
00180 return streambuf::setbuf(0, 0) ;
00181 }
00182
00183 inline
00184 GPIBEquipmentBuffer::int_type
00185 GPIBEquipmentBuffer::overflow(int_type c) {
00186 PutChar(c) ;
00187 return c ;
00188 }
00189
00190 inline
00191 GPIBEquipmentBuffer::int_type
00192 GPIBEquipmentBuffer::underflow() {
00193 return GetChar() ;
00194 }
00195
00196 inline
00197 GPIBEquipmentBuffer::int_type
00198 GPIBEquipmentBuffer::uflow() {
00199 return GetChar() ;
00200 }
00201
00202
00203 inline
00204 GPIBEquipmentBuffer::int_type
00205 GPIBEquipmentBuffer::pbackfail(int_type c) {
00206 mPutbackChar = c ;
00207 mPutbackAvailable = true ;
00208 return c ;
00209 }
00210
00220 class GPIBEquipment : public iostream {
00221 public:
00222 friend GPIBEquipmentBuffer ;
00223
00235 void SetController(GPIBController *controller) ;
00236
00241 void Clear() ;
00242
00247 int PrimAddress(const int addr) ;
00248
00252 int PrimAddress() const ;
00253
00258 int SecAddress(const int addr) ;
00259
00263 int SecAddress() const ;
00264
00268 int DeviceID() const ;
00269
00274 void SendCommand(const string command) ;
00275
00280 const string ReadData(int read_bytes) ;
00281
00286 void SetLocal() ;
00287
00292 GPIBEquipment() ;
00293
00297 virtual ~GPIBEquipment() ;
00298
00299 00300 00301 00302 00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 private:
00325 int mAddress ;
00326
00330 int mSecAddress ;
00331
00335 GPIBController *mController ;
00336
00340 GPIBEquipmentBuffer *mBuffer ;
00341 protected:
00345 int mDeviceID ;
00346
00350 GPIBController& Controller() ;
00351 } ;
00352
00353
00354 inline
00355 int
00356 GPIBEquipment::PrimAddress(const int addr) { mAddress = addr ; return mAddress ; }
00357
00358 inline
00359 int
00360 GPIBEquipment::PrimAddress() const { return mAddress ; }
00361
00362 inline
00363 int
00364 GPIBEquipment::SecAddress(const int addr) { return mSecAddress = addr ; }
00365
00366 inline
00367 int
00368 GPIBEquipment::SecAddress() const { return mSecAddress ; }
00369
00370 inline
00371 int
00372 GPIBEquipment::DeviceID() const { return mDeviceID ; }
00373 }
00374 }
00375 #endif