Main Page | Modules | Class Hierarchy | Class List | File List | Class Members

dataqsdk.cpp

00001 /***************************************************************************
00002                           dataqsdk.cpp  -  DataqSDK for Linux.
00003                              -------------------
00004     begin                : Wed Jun 9 2004
00005     author               : Ioan S. Popescu
00006 
00007 Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either
00012 version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023  ***************************************************************************/
00024 
00025 #include "dataqsdk.h"   // SDK interface file
00026 #include <string>       // String functions include file
00027 using namespace std;
00028 
00029 int my_errno = 0;
00030 
00031 // Supported device classes
00032 #include "di194/di194.h"
00033 #include "di154/di154.h"
00034 
00035 dataqsdk::dataqsdk()
00036 {
00037     m_ProductName = 0;
00038     m_last_error = 0;
00039     m_classID = 0;
00040 }
00041 
00042 dataqsdk::~dataqsdk()
00043 {
00044   if(m_ProductName != 0)
00045   {
00046     delete [] m_ProductName;
00047     m_ProductName = 0;
00048   }
00049   if(m_classID != 0)
00050   {
00051     delete m_classID;
00052     m_classID = 0;
00053   }
00054 }
00055 
00056 // Get Properties
00057 
00066 const int dataqsdk::ADChannelCount()
00067 {
00068   // pointer check
00069   if(m_classID == 0)
00070   {
00071     m_last_error = ENODEV;
00072     return 0;
00073   }
00074 
00075   return m_classID->ADChannelCount();
00076 }
00077 
00084 const long int dataqsdk::ADCounter()
00085 {
00086   // pointer check
00087   if(m_classID == 0)
00088   {
00089     m_last_error = ENODEV;
00090     return 0;
00091   }
00092 
00093   return m_classID->ADCounter();
00094 }
00095 
00105 const long int dataqsdk::AvailableData()
00106 {
00107   // pointer check
00108   if(m_classID == 0)
00109   {
00110     m_last_error = ENODEV;
00111     return 0;
00112   }
00113 
00114   return m_classID->AvailableData();
00115 }
00116 
00123 const long int dataqsdk::BurstCounter()
00124 {
00125   // pointer check
00126   if(m_classID == 0)
00127   {
00128     m_last_error = ENODEV;
00129     return 0;
00130   }
00131 
00132   return m_classID->BurstCounter();
00133 }
00134 
00143 const char *const dataqsdk::DeviceFile()
00144 {
00145   // pointer check
00146   if(m_classID == 0)
00147   {
00148     m_last_error = ENODEV;
00149     return 0;
00150   }
00151 
00152   return m_classID->DeviceFile();
00153 }
00154 
00163 const long int dataqsdk::EventPoint()
00164 {
00165   // pointer check
00166   if(m_classID == 0)
00167   {
00168     m_last_error = ENODEV;
00169     return 0;
00170   }
00171 
00172   return m_classID->EventPoint();
00173 }
00174 
00181 const int dataqsdk::InfoBoardID()
00182 {
00183   // pointer check
00184   if(m_classID == 0)
00185   {
00186     m_last_error = ENODEV;
00187     return 0;
00188   }
00189 
00190   return m_classID->InfoBoardID();
00191 }
00192 
00199 const bool dataqsdk::InfoPGL()
00200 {
00201   // pointer check
00202   if(m_classID == 0)
00203   {
00204     m_last_error = ENODEV;
00205     return false;
00206   }
00207 
00208   return m_classID->InfoPGL();
00209 }
00210 
00217 const int dataqsdk::InfoRev()
00218 {
00219   // pointer check
00220   if(m_classID == 0)
00221   {
00222     m_last_error = ENODEV;
00223     return 0;
00224   }
00225 
00226   return m_classID->InfoRev();
00227 }
00228 
00241 const char *const dataqsdk::InfoSerial()
00242 {
00243   // pointer check
00244   if(m_classID == 0)
00245   {
00246     m_last_error = ENODEV;
00247     return 0;
00248   }
00249 
00250   return m_classID->InfoSerial();
00251 }
00252 
00261 const double dataqsdk::MaxBurstRate()
00262 {
00263   // pointer check
00264   if(m_classID == 0)
00265   {
00266     m_last_error = ENODEV;
00267     return 0;
00268   }
00269 
00270   return m_classID->MaxBurstRate();
00271 }
00272 
00279 const char *const dataqsdk::ProductName()
00280 {
00281   char *temp = 0;
00282   // pointer check
00283   if(m_ProductName == 0)  // no product loaded
00284   {
00285     // create a second memory location to hold the copy
00286     temp = new char[BIG_STR];
00287     int i=0;
00288     // return list of supported products
00289     strcpy(temp+i, "DI-194RS"); i += 9;
00290     strcpy(temp+i, "DI-154RS"); i += 9;
00291     // make sure to use double quotes around product name
00292     // to add other products, use this template:
00293     //strcpy(temp+i, [actual product name]);
00294     //i += [length of product name plus 1 for NULL];
00295 
00296     // need to have 2 '\\0' characters at the end (one is already there)
00297     temp[i] = 0;
00298   }
00299   else
00300   {
00301     // create a second memory location to hold the copy
00302     temp = new char[SMALL_STR];
00303     // copy string
00304     strcpy(temp, m_ProductName);
00305   }
00306 
00307   // return either a list of devices or current device
00308   return temp;
00309 }
00310 
00319 const double dataqsdk::SampleRate()
00320 {
00321   // pointer check
00322   if(m_classID == 0)
00323   {
00324     m_last_error = ENODEV;
00325     return 0;
00326   }
00327 
00328   return m_classID->SampleRate();
00329 }
00330 
00337 const int dataqsdk::TrigHysteresisIdx()
00338 {
00339   // pointer check
00340   if(m_classID == 0)
00341   {
00342     m_last_error = ENODEV;
00343     return 0;
00344   }
00345 
00346   return m_classID->TrigHysteresisIdx();
00347 }
00348 
00355 const int dataqsdk::TrigLevel()
00356 {
00357   // pointer check
00358   if(m_classID == 0)
00359   {
00360     m_last_error = ENODEV;
00361     return 0;
00362   }
00363 
00364   return m_classID->TrigLevel();
00365 }
00366 
00373 const int dataqsdk::TrigMode()
00374 {
00375   // pointer check
00376   if(m_classID == 0)
00377   {
00378     m_last_error = ENODEV;
00379     return 0;
00380   }
00381 
00382   return m_classID->TrigMode();
00383 }
00384 
00391 const int dataqsdk::TrigScnChnIdx()
00392 {
00393   // pointer check
00394   if(m_classID == 0)
00395   {
00396     m_last_error = ENODEV;
00397     return 0;
00398   }
00399 
00400   return m_classID->TrigScnChnIdx();
00401 }
00402 
00409 const int dataqsdk::TrigSlope()
00410 {
00411   // pointer check
00412   if(m_classID == 0)
00413   {
00414     m_last_error = ENODEV;
00415     return 0;
00416   }
00417 
00418   return m_classID->TrigSlope();
00419 }
00420 
00427 const int dataqsdk::TrigPostLength()
00428 {
00429   // pointer check
00430   if(m_classID == 0)
00431   {
00432     m_last_error = ENODEV;
00433     return 0;
00434   }
00435 
00436   return m_classID->TrigPostLength();
00437 }
00438 
00445 const int dataqsdk::TrigPreLength()
00446 {
00447   // pointer check
00448   if(m_classID == 0)
00449   {
00450     m_last_error = ENODEV;
00451     return 0;
00452   }
00453 
00454   return m_classID->TrigPreLength();
00455 }
00456 
00457 // Set Properties
00458 
00470 void dataqsdk::ADChannelCount(const int ChannelCount)
00471 {
00472   // pointer check
00473   if(m_classID == 0)
00474   {
00475     m_last_error = ENODEV;
00476     return;
00477   }
00478 
00479   m_classID->ADChannelCount(ChannelCount);
00480 }
00481 
00490 void dataqsdk::ADCounter(const long int Counter)
00491 {
00492   // pointer check
00493   if(m_classID == 0)
00494   {
00495     m_last_error = ENODEV;
00496     return;
00497   }
00498 
00499   m_classID->ADCounter(Counter);
00500 }
00501 
00510 void dataqsdk::BurstCounter(const long int BurstCounter)
00511 {
00512   // pointer check
00513   if(m_classID == 0)
00514   {
00515     m_last_error = ENODEV;
00516     return;
00517   }
00518 
00519   m_classID->BurstCounter(BurstCounter);
00520 }
00521 
00531 void dataqsdk::DeviceFile(const char *const DeviceFile)
00532 {
00533   // pointer check
00534   if(DeviceFile == 0)
00535   {
00536     m_last_error = EINVAL;
00537     return;
00538   }
00539   // pointer check
00540   if(m_classID == 0)
00541   {
00542     m_last_error = ENODEV;
00543     return;
00544   }
00545 
00546   m_classID->DeviceFile(DeviceFile);
00547 }
00548 
00558 void dataqsdk::EventPoint(const long int EventPnt)
00559 {
00560   // pointer check
00561   if(m_classID == 0)
00562   {
00563     m_last_error = ENODEV;
00564     return;
00565   }
00566 
00567   m_classID->EventPoint(EventPnt);
00568 }
00569 
00578 void dataqsdk::MaxBurstRate(const double MaxBurstRt)
00579 {
00580   // pointer check
00581   if(m_classID == 0)
00582   {
00583     m_last_error = ENODEV;
00584     return;
00585   }
00586 
00587   m_classID->MaxBurstRate(MaxBurstRt);
00588 }
00589 
00599 void dataqsdk::ProductName(const char *const ProductName)
00600 {
00601   // pointer check
00602   if(ProductName == 0)
00603   {
00604     m_last_error = EINVAL;
00605     return;
00606   }
00607   // pointer check
00608   if(m_ProductName == 0)
00609     m_ProductName = new char[SMALL_STR];
00610 
00611   // determine device
00612   if(strncmp(ProductName, "DI-194RS", SMALL_STR) == 0)
00613   {
00614     // put correct device name into variable
00615     strcpy(m_ProductName, "DI-194RS");
00616     if(m_classID != 0)
00617     {
00618       delete m_classID;
00619       m_classID = 0;
00620     }
00621     m_classID = new di194_dsdk;
00622   }
00623   else if(strncmp(ProductName, "DI-154RS", SMALL_STR) == 0)
00624   {
00625     // put correct device name into variable
00626     strcpy(m_ProductName, "DI-154RS");
00627     if(m_classID != 0)
00628     {
00629       delete m_classID;
00630       m_classID = 0;
00631     }
00632     m_classID = new di154_dsdk;
00633   }
00634   // other devices go here
00635   else  // no devices matched
00636   {
00637     m_last_error = ENODEV;
00638     return;
00639   }
00640 }
00641 
00656 void dataqsdk::SampleRate(const double SampleRt)
00657 {
00658   // pointer check
00659   if(m_classID == 0)
00660   {
00661     m_last_error = ENODEV;
00662     return;
00663   }
00664 
00665   m_classID->SampleRate(SampleRt);
00666 }
00667 
00676 void dataqsdk::TrigHysteresisIdx(const int Hidx)
00677 {
00678   // pointer check
00679   if(m_classID == 0)
00680   {
00681     m_last_error = ENODEV;
00682     return;
00683   }
00684 
00685   m_classID->TrigHysteresisIdx(Hidx);
00686 }
00687 
00696 void dataqsdk::TrigLevel(const int Level)
00697 {
00698   // pointer check
00699   if(m_classID == 0)
00700   {
00701     m_last_error = ENODEV;
00702     return;
00703   }
00704 
00705   m_classID->TrigLevel(Level);
00706 }
00707 
00716 void dataqsdk::TrigMode(const int Mode)
00717 {
00718   // pointer check
00719   if(m_classID == 0)
00720   {
00721     m_last_error = ENODEV;
00722     return;
00723   }
00724 
00725   m_classID->TrigMode(Mode);
00726 }
00727 
00736 void dataqsdk::TrigScnChnIdx(const int SCidx)
00737 {
00738   // pointer check
00739   if(m_classID == 0)
00740   {
00741     m_last_error = ENODEV;
00742     return;
00743   }
00744 
00745   m_classID->TrigScnChnIdx(SCidx);
00746 }
00747 
00756 void dataqsdk::TrigSlope(const int Slope)
00757 {
00758   // pointer check
00759   if(m_classID == 0)
00760   {
00761     m_last_error = ENODEV;
00762     return;
00763   }
00764 
00765   m_classID->TrigSlope(Slope);
00766 }
00767 
00776 void dataqsdk::TrigPostLength(const int PostLength)
00777 {
00778   // pointer check
00779   if(m_classID == 0)
00780   {
00781     m_last_error = ENODEV;
00782     return;
00783   }
00784 
00785   m_classID->TrigPostLength(PostLength);
00786 }
00787 
00796 void dataqsdk::TrigPreLength(const int PreLength)
00797 {
00798   // pointer check
00799   if(m_classID == 0)
00800   {
00801     m_last_error = ENODEV;
00802     return;
00803   }
00804 
00805   m_classID->TrigPreLength(PreLength);
00806 }
00807 
00808 // Methods
00809 
00825 void dataqsdk::ADChannelList(const int *const ChannelList)
00826 {
00827   // pointer check
00828   if(ChannelList == 0)
00829   {
00830     m_last_error = EINVAL;
00831     return;
00832   }
00833   // pointer check
00834   if(m_classID == 0)
00835   {
00836     m_last_error = ENODEV;
00837     return;
00838   }
00839 
00840   m_classID->ADChannelList(ChannelList);
00841 }
00842 
00852 void dataqsdk::ADDiffList(const int *const DiffList)
00853 {
00854   // pointer check
00855   if(DiffList == 0)
00856   {
00857     m_last_error = EINVAL;
00858     return;
00859   }
00860   // pointer check
00861   if(m_classID == 0)
00862   {
00863     m_last_error = ENODEV;
00864     return;
00865   }
00866 
00867   m_classID->ADDiffList(DiffList);
00868 }
00869 
00879 void dataqsdk::ADGainList(const int *const GainList)
00880 {
00881   // pointer check
00882   if(GainList == 0)
00883   {
00884     m_last_error = EINVAL;
00885     return;
00886   }
00887   // pointer check
00888   if(m_classID == 0)
00889   {
00890     m_last_error = ENODEV;
00891     return;
00892   }
00893 
00894   m_classID->ADGainList(GainList);
00895 }
00896 
00911 void dataqsdk::ADMethodList(const int *const MethodList)
00912 {
00913   // pointer check
00914   if(MethodList == 0)
00915   {
00916     m_last_error = EINVAL;
00917     return;
00918   }
00919   // pointer check
00920   if(m_classID == 0)
00921   {
00922     m_last_error = ENODEV;
00923     return;
00924   }
00925 
00926   m_classID->ADMethodList(MethodList);
00927 }
00928 
00938 void dataqsdk::DAOutput(const int value, const int port)
00939 {
00940   // pointer check
00941   if(m_classID == 0)
00942   {
00943     m_last_error = ENODEV;
00944     return;
00945   }
00946 
00947   m_classID->DAOutput(value, port);
00948 }
00949 
00950 // attempts to detect any currently connected devices and returns a
00951 // pointer to a string of ProductNames separated by the '\\0' character
00952 // with the last entry followed by 2 '\\0' characters.
00953 // will not detect devices that aren't automatically detected by the
00954 // kernel (USB devices are most likely to be detected)
00955 const char *const dataqsdk::DetectedDevices()
00956 {
00957   m_last_error = ENOSYS;
00958 /********************************************
00959             NOT YET IMPLEMENTED
00960 ********************************************/
00961   return 0;
00962 }
00963 
00970 const long int dataqsdk::DigitalInput()
00971 {
00972   // pointer check
00973   if(m_classID == 0)
00974   {
00975     m_last_error = ENODEV;
00976     return 0;
00977   }
00978 
00979   return m_classID->DigitalInput();
00980 }
00981 
00990 void dataqsdk::DigitalOutput(const int value)
00991 {
00992   // pointer check
00993   if(m_classID == 0)
00994   {
00995     m_last_error = ENODEV;
00996     return;
00997   }
00998 
00999   m_classID->DigitalOutput(value);
01000 }
01001 
01002 void dataqsdk::GetData()
01003 {
01004   // pointer check
01005   if(m_classID == 0)
01006   {
01007     m_last_error = ENODEV;
01008     return;
01009   }
01010 
01011   m_classID->GetData();
01012 }
01013 
01040 void dataqsdk::GetDataEx(short int *iArray, const int Count)
01041 {
01042   // pointer check
01043   if(m_classID == 0)
01044   {
01045     m_last_error = ENODEV;
01046     return;
01047   }
01048 
01049   m_classID->GetDataEx(iArray, Count);
01050 }
01051 
01052 void dataqsdk::GetDataFrame()
01053 {
01054   // pointer check
01055   if(m_classID == 0)
01056   {
01057     m_last_error = ENODEV;
01058     return;
01059   }
01060 
01061   m_classID->GetDataFrame();
01062 }
01063 
01064 void dataqsdk::GetDataFrameEx(short int *iArray, const int Count)
01065 {
01066   // pointer check
01067   if(m_classID == 0)
01068   {
01069     m_last_error = ENODEV;
01070     return;
01071   }
01072 
01073   m_classID->GetDataFrameEx(iArray, Count);
01074 }
01075 
01088 void dataqsdk::Start()
01089 {
01090   // pointer check
01091   if(m_classID == 0)
01092   {
01093     m_last_error = ENODEV;
01094     return;
01095   }
01096 
01097   m_classID->Start();
01098 }
01099 
01112 void dataqsdk::Stop()
01113 {
01114   // pointer check
01115   if(m_classID == 0)
01116   {
01117     m_last_error = ENODEV;
01118     return;
01119   }
01120 
01121   m_classID->Stop();
01122 }
01123 
01124 
01125 // "Event Occur" Methods
01126 
01139 const bool dataqsdk::ControlError(long int &Code)
01140 {
01141   // pointer check, causes error if no product specified
01142   if(m_classID == 0)
01143   {
01144     Code = ENODEV;
01145     m_last_error = 0;
01146     return true;
01147   }
01148 
01149   // give priority to errors from device
01150   if(m_classID->ControlError(Code))
01151   {
01152     m_last_error = 0; // reset this class' errors
01153     return true;
01154   }
01155   // this class' errors get reported second
01156   else if(m_last_error != 0)
01157   {
01158     Code = m_last_error;
01159     m_last_error = 0;
01160     return true;
01161   }
01162 
01163   return false;
01164 }
01165 
01176 const bool dataqsdk::NewData(long int &Count)
01177 {
01178   // pointer check
01179   if(m_classID == 0)
01180   {
01181     m_last_error = ENODEV;
01182     return false;
01183   }
01184 
01185   return m_classID->NewData(Count);
01186 }
01187 
01201 const bool dataqsdk::OverRun()
01202 {
01203   // pointer check
01204   if(m_classID == 0)
01205   {
01206     m_last_error = ENODEV;
01207     return false;
01208   }
01209 
01210   return m_classID->OverRun();
01211 }
01212 
01221 dataqsdk::dataqsdk(const dataqsdk &copy)
01222 {
01223 }
01224 

Generated on Mon Aug 2 09:44:49 2004 for DataqSDK by doxygen 1.3.6