00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #if ! defined( AnalogInputSubsystem_hpp )
00011 #define AnalogInputSubsystem_hpp
00012
00013
00014 #include <AI16_InputRange.hpp>
00015 #include <AI16_DataSet.hpp>
00016 #include <DeviceSubsystem.hpp>
00017
00018
00019 namespace AIOUSB {
00020
00021 class AI16_DataSet;
00022
00029 class AnalogInputSubsystem : public DeviceSubsystem {
00030 friend class USB_AI16_Family;
00031
00032
00033 public:
00034
00035
00036
00037
00038
00039
00041 static const int CAL_MODE_NORMAL = 0;
00043 static const int CAL_MODE_GROUND = 1;
00045 static const int CAL_MODE_REFERENCE = 3;
00046
00047
00048
00049
00051 static const int TRIG_MODE_CTR0_EXT = 0x10;
00053 static const int TRIG_MODE_FALLING_EDGE = 0x08;
00055 static const int TRIG_MODE_SCAN = 0x04;
00057 static const int TRIG_MODE_EXTERNAL = 0x02;
00059 static const int TRIG_MODE_TIMER = 0x01;
00060
00061
00062
00063
00065 static const int RANGE_0_10V = 0;
00067 static const int RANGE_10V = 1;
00069 static const int RANGE_0_5V = 2;
00071 static const int RANGE_5V = 3;
00073 static const int RANGE_0_2V = 4;
00075 static const int RANGE_2V = 5;
00077 static const int RANGE_0_1V = 6;
00079 static const int RANGE_1V = 7;
00080
00082 static const int MIN_COUNTS = 0;
00084 static const int MAX_COUNTS = 0xffff;
00085
00087 static const int CAL_TABLE_WORDS = 64 * 1024;
00088
00089
00090
00091 protected:
00092 static const char RANGE_TEXT[][ 10 ];
00093
00094
00095
00096 protected:
00097
00098
00099
00100 static const int NUM_CONFIG_REGISTERS = 20;
00101 static const int NUM_MUX_CONFIG_REGISTERS = 21;
00102 static const int NUM_GAIN_CODE_REGISTERS = 16;
00103 static const int REG_GAIN_CODE = 0;
00104
00105 static const int REG_CAL_MODE = 16;
00106 static const int REG_TRIG_MODE = 17;
00107 static const int REG_START_END = 18;
00108 static const int REG_OVERSAMPLE = 19;
00109 static const int REG_MUX_START_END = 20;
00110
00111 static const int DIFFERENTIAL_MODE = 8;
00112 static const int MAX_OVERSAMPLE = 0xff;
00113 static const int TRIG_MODE_VALID_MASK = (
00114 TRIG_MODE_CTR0_EXT
00115 | TRIG_MODE_FALLING_EDGE
00116 | TRIG_MODE_SCAN
00117 | TRIG_MODE_EXTERNAL
00118 | TRIG_MODE_TIMER );
00119
00120 static const int AUTO_CAL_UNKNOWN = 0;
00121 static const int AUTO_CAL_NOT_PRESENT = 1;
00122 static const int AUTO_CAL_PRESENT = 2;
00123
00124 static const int MAX_CHANNELS = 128;
00125
00126 int numChannels;
00127 int numMUXChannels;
00128 int channelsPerGroup;
00129 int configBlockSize;
00130 int autoCalFeature;
00131 AI16_InputRange *inputRange;
00132 bool *differentialMode;
00133 int calMode;
00134 int triggerMode;
00135 int startChannel;
00136 int endChannel;
00137 int overSample;
00138 unsigned short *readBulkBuffer;
00139 int readBulkSamplesRequested;
00140 int readBulkSamplesRetrieved;
00141 bool autoConfig;
00142
00143
00144
00145 protected:
00146 AnalogInputSubsystem &setScanRange( int startChannel, int numChannels );
00147 AnalogInputSubsystem( USBDevice &parent );
00148 virtual ~AnalogInputSubsystem();
00149
00150
00151
00152 public:
00153
00154
00155
00156
00157
00158 virtual std::ostream &print( std::ostream &out );
00159
00165 int getNumChannels() const {
00166 return numChannels;
00167 }
00168
00174 int getNumMUXChannels() const {
00175 return numMUXChannels;
00176 }
00177
00183 int getChannelsPerGroup() {
00184 return channelsPerGroup;
00185 }
00186
00187 bool isAutoCalPresent( bool force );
00188 static std::string getRangeText( int range );
00189
00190
00191
00192
00193
00202 bool isAutoConfig() const {
00203 return autoConfig;
00204 }
00205
00225 AnalogInputSubsystem &setAutoConfig( bool autoConfig ) {
00226 this->autoConfig = autoConfig;
00227 return *this;
00228 }
00229
00230 AnalogInputSubsystem &readConfig();
00231 AnalogInputSubsystem &writeConfig();
00232 bool isDiscardFirstSample() const;
00233 AnalogInputSubsystem &setDiscardFirstSample( bool discard );
00234
00242 int getCalMode() const {
00243 return calMode;
00244 }
00245
00246 AnalogInputSubsystem &setCalMode( int calMode );
00247
00255 int getTriggerMode() const {
00256 return triggerMode;
00257 }
00258
00259 AnalogInputSubsystem &setTriggerMode( int triggerMode );
00260 int getRange( int channel ) const;
00261 IntArray getRange( int startChannel, int numChannels ) const;
00262 AnalogInputSubsystem &setRange( int channel, int range );
00263 AnalogInputSubsystem &setRange( int startChannel, const IntArray &range );
00264 bool isDifferentialMode( int channel ) const;
00265 BoolArray isDifferentialMode( int startChannel, int numChannels ) const;
00266 AnalogInputSubsystem &setDifferentialMode( int channel, bool differentialMode );
00267 AnalogInputSubsystem &setDifferentialMode( int startChannel, const BoolArray &differentialMode );
00268 AnalogInputSubsystem &setRangeAndDiffMode( int channel, int range, bool differentialMode );
00269 AnalogInputSubsystem &setRangeAndDiffMode( int startChannel, const IntArray &range, const BoolArray &differentialMode );
00270 AnalogInputSubsystem &setRangeAndDiffMode( int range, bool differentialMode );
00271
00278 int getOverSample() const {
00279 return overSample;
00280 }
00281
00282 AnalogInputSubsystem &setOverSample( int overSample );
00283 AnalogInputSubsystem &setCalibrationTable( const std::string &fileName );
00284 AnalogInputSubsystem &setCalibrationTable( const UShortArray &calTable );
00285
00293 int getStreamingBlockSize() {
00294 return parent->getStreamingBlockSize();
00295 }
00296
00306 AnalogInputSubsystem &setStreamingBlockSize( int blockSize ) {
00307 parent->setStreamingBlockSize( blockSize );
00308 return *this;
00309 }
00310
00316 double getClock() {
00317 return parent->getMiscClock();
00318 }
00319
00327 AnalogInputSubsystem &setClock( double clockHz ) {
00328 parent->setMiscClock( clockHz );
00329 return *this;
00330 }
00331
00332
00333
00334
00335
00336 UShortArray calibrate( bool autoCal, bool returnCalTable, const std::string &saveFileName );
00337 UShortArray calibrate( const DoubleArray &points, bool returnCalTable, const std::string &saveFileName );
00338 AI16_DataSet *read( int startChannel, int numChannels );
00339 unsigned short readCounts( int channel );
00340 UShortArray readCounts( int startChannel, int numChannels );
00341 double readVolts( int channel );
00342 DoubleArray readVolts( int startChannel, int numChannels );
00343 AnalogInputSubsystem &readBulkStart( int startChannel, int numChannels, int numSamples );
00344 int readBulkSamplesAvailable();
00345 UShortArray readBulkNext( int numSamples );
00346
00357 AnalogInputSubsystem &clearFIFO( int method ) {
00358 parent->clearFIFO( method );
00359 return *this;
00360 }
00361
00362
00363
00364
00365
00366 double countsToVolts( int channel, unsigned short counts ) const;
00367 DoubleArray countsToVolts( int startChannel, const UShortArray &counts ) const;
00368 unsigned short voltsToCounts( int channel, double volts ) const;
00369 UShortArray voltsToCounts( int startChannel, const DoubleArray &volts ) const;
00370
00371
00372
00373 };
00374
00375 }
00376
00377 #endif
00378
00379