Facebook
From xxx, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 177
  1. /*******************************************************************************
  2. Copyright (c) 1983-2012 Advantech Co., Ltd.
  3. ********************************************************************************
  4. THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY INFORMATION
  5. WHICH IS THE PROPERTY OF ADVANTECH CORP., ANY DISCLOSURE, USE, OR REPRODUCTION,
  6. WITHOUT WRITTEN AUTHORIZATION FROM ADVANTECH CORP., IS STRICTLY PROHIBITED.
  7.  
  8. ================================================================================
  9. REVISION HISTORY
  10. --------------------------------------------------------------------------------
  11. $Log:  $
  12. --------------------------------------------------------------------------------
  13. $NoKeywords:  $
  14. */
  15. /******************************************************************************
  16. *
  17. * Windows Example:
  18. *    InstantAI.cpp
  19. *
  20. * Example Category:
  21. *    AI
  22. *
  23. * Description:
  24. *    This example demonstrates how to use Instant AI function.
  25. *
  26. * Instructions for Running:
  27. *    1. Set the 'deviceDescription' for opening the device.
  28. *    2. Set the 'startChannel' as the first channel for scan analog samples
  29. *    3. Set the 'channelCount' to decide how many sequential channels to scan analog samples.
  30. *
  31. * I/O Connections Overview:
  32. *    Please refer to your hardware reference manual.
  33. *
  34. ******************************************************************************/
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include "C:/Advantech/DAQNavi/Examples/C++_Console/inc/compatibility.h"
  38. #include "C:/Advantech/DAQNavi/inc/bdaqctrl.h"
  39. #include <iostream>
  40. using namespace Automation::BDaq;
  41. using namespace std;
  42. //-----------------------------------------------------------------------------------
  43. // Configure the following three parameters before running the example
  44. //-----------------------------------------------------------------------------------
  45. #define      deviceDescription  L"PCI-1710HG,BID#0"
  46. int32        startChannel = 4;
  47. const int32  channelCount = 1;
  48.  
  49. inline void waitAnyKey()
  50. {
  51.         do { SLEEP(1); } while (!kbhit());
  52. }
  53.  
  54. int main(int argc, char* argv[])
  55. {
  56.         ErrorCode        ret = Success;
  57.  
  58.         // Step 1: Create a 'instantAiCtrl' for InstantAI function.
  59.         InstantAiCtrl * instantAiCtrl = AdxInstantAiCtrlCreate();
  60.  
  61.         do
  62.         {
  63.                 // Step 2: Select a device by device number or device description and specify the access mode.
  64.                 // in this example we use AccessWriteWithReset(default) mode so that we can
  65.                 // fully control the device, including configuring, sampling, etc.
  66.                 DeviceInformation devInfo(deviceDescription);
  67.                 ret = instantAiCtrl->setSelectedDevice(devInfo);
  68.                 printf("%d\n", ret);
  69.                 CHK_RESULT(ret);
  70.  
  71.  
  72.                 auto device = instantAiCtrl->getChannels();
  73.                 device[0].getItem(4).setValueRange(mV_Neg500To500);
  74.  
  75.  
  76.                 // Step 3: Read samples and do post-process, we show data here.
  77.                 printf("Acquisition is in progress, any key to quit!\n\n");
  78.                 double   scaledData[channelCount] = { 0 };//the count of elements in this array should not be less than the value of the variable channelCount
  79.                 int16 rawData = 0;
  80.                 int32 channelCountMax = instantAiCtrl->getFeatures()->getChannelCountMax();
  81.  
  82.                 do
  83.                 {
  84.                         //read samples and save to buffer 'scaledData'.
  85.                         ret = instantAiCtrl->Read(startChannel, channelCount, &rawData, scaledData);
  86.                         CHK_RESULT(ret);
  87.  
  88.                         // process the acquired data. only show data here.
  89.                         for (int32 i = startChannel; i< startChannel + channelCount; ++i)
  90.                         {
  91.                                 printf("Channel %d data: %10.6f\n, int 0x%x\n ", i % channelCountMax, scaledData[i - startChannel], (rawData & 0xFFF) );
  92.                                
  93.        
  94.                                
  95.  
  96.                                 //cout << 12.3858622 << hex;
  97.                         }
  98.                         printf("\n");
  99.                         SLEEP(1);
  100.                 } while (!kbhit());
  101.         } while (false);
  102.  
  103.         // Step 4 : Close device and release any allocated resource.
  104.         instantAiCtrl->Dispose();
  105.  
  106.         // If something wrong in this execution, print the error code on screen for tracking.
  107.         if (BioFailed(ret))
  108.         {
  109.                 printf("Some error occurred. And the last error code is Ox%X.\n", ret);
  110.                 waitAnyKey();// wait any key to quit!
  111.         }
  112.         return 0;
  113. }
  114.  
  115.  
  116.  
  117.