00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if ! defined( AnalogInputSubsystem_hpp )
00012 #define AnalogInputSubsystem_hpp
00013
00014
00015 #include <DeviceSubsystem.hpp>
00016
00017
00018 namespace AIOUSB {
00019
00020
00021
00022
00023
00024
00025
00026 class AnalogInputSubsystem : public DeviceSubsystem {
00027 public:
00028 enum {
00029 MAX_COUNTS = 65535
00030 };
00031
00032 protected:
00033 enum {
00034 NUM_CONFIG_REGISTERS = 20
00035 , NUM_MUX_CONFIG_REGISTERS = 21
00036
00037 , GAIN_CODE_VALID_MASK = 7
00038 , MAX_OVERSAMPLE = 0xff
00039
00040 , AUTO_CAL_UNKNOWN = 0
00041 , AUTO_CAL_NOT_PRESENT = 1
00042 , AUTO_CAL_PRESENT = 2
00043 };
00044
00045 int numChannels;
00046 int numMUXChannels;
00047 int autoCalFeature;
00048 UCharArray configBlock;
00049 UCharArray prevConfigBlock;
00050 unsigned short *readBulkBuffer;
00051 int readBulkSamplesRequested;
00052 int readBulkSamplesRetrieved;
00053
00054 void validateConfigBlock() const;
00055 AnalogInputSubsystem &writeConfig( bool force );
00056 int getStartChannel() const;
00057 int getEndChannel() const;
00058 AnalogInputSubsystem &setScanRange( int startChannel, int numChannels );
00059
00060 public:
00061 AnalogInputSubsystem( USBDevice &parent );
00062 virtual ~AnalogInputSubsystem();
00063
00064
00065 virtual std::ostream &print( std::ostream &out );
00066
00067 int getNumChannels() const {
00068 return numChannels;
00069 }
00070
00071 int getNumMUXChannels() const {
00072 return numMUXChannels;
00073 }
00074
00075 bool isAutoCalPresent( bool force );
00076
00077
00078 bool isDiscardFirstSample() const;
00079 AnalogInputSubsystem &setDiscardFirstSample( bool discard );
00080 int getCalMode() const;
00081 AnalogInputSubsystem &setCalMode( int mode );
00082 int getTriggerMode() const;
00083 AnalogInputSubsystem &setTriggerMode( int mode );
00084 int getGainCode( int channel ) const;
00085 IntArray getGainCode( int startChannel, int numChannels ) const;
00086 AnalogInputSubsystem &setGainCode( int channel, int gainCode );
00087 AnalogInputSubsystem &setGainCode( int startChannel, const IntArray &gainCode );
00088 bool isDifferentialMode( int channel ) const;
00089 BoolArray isDifferentialMode( int startChannel, int numChannels ) const;
00090 AnalogInputSubsystem &setDifferentialMode( int channel, bool differentialMode );
00091 AnalogInputSubsystem &setDifferentialMode( int startChannel, const BoolArray &differentialMode );
00092 AnalogInputSubsystem &setGainCodeAndDiffMode( int channel, int gainCode, bool differentialMode );
00093 AnalogInputSubsystem &setGainCodeAndDiffMode( int startChannel, const IntArray &gainCode, const BoolArray &differentialMode );
00094 AnalogInputSubsystem &setGainCodeAndDiffMode( int gainCode, bool differentialMode );
00095 int getOversample() const;
00096 AnalogInputSubsystem &setOversample( int oversample );
00097 AnalogInputSubsystem &setCalibrationTable( const std::string &fileName );
00098 AnalogInputSubsystem &setCalibrationTable( const UShortArray &calTable );
00099 AnalogInputSubsystem &setStreamingBlockSize( int blockSize );
00100 AnalogInputSubsystem &setClock( double clockHz );
00101
00102
00103 UShortArray calibrate( bool autoCal, bool returnCalTable, const std::string &saveFileName );
00104 UShortArray calibrate( const DoubleArray &points, bool returnCalTable, const std::string &saveFileName );
00105 unsigned short read( int channel );
00106 UShortArray read( int startChannel, int numChannels );
00107 double readVolts( int channel );
00108 DoubleArray readVolts( int startChannel, int numChannels );
00109 AnalogInputSubsystem &readBulkStart( int startChannel, int numChannels, int numSamples );
00110 int readBulkSamplesAvailable();
00111 UShortArray readBulkNext( int numSamples );
00112
00113 AnalogInputSubsystem &clearFIFO( int method ) {
00114 parent->clearFIFO( method );
00115 return *this;
00116 }
00117
00118
00119 double countsToVolts( int channel, unsigned short counts ) const;
00120 DoubleArray countsToVolts( int startChannel, const UShortArray &counts ) const;
00121 unsigned short voltsToCounts( int channel, double volts ) const;
00122 UShortArray voltsToCounts( int startChannel, const DoubleArray &volts ) const;
00123 };
00124
00125
00126
00127 }
00128
00129 #endif
00130
00131
00132