Control.cpp
上传用户:dtengfei
上传日期:2013-01-16
资源大小:393k
文件大小:6k
源码类别:

医药行业

开发平台:

Visual C++

  1. // Control.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "心跳检测.h"
  5. #include "Control.h"
  6. #include "MainFrm.h"
  7. #include "Math.h"
  8. #include "conio.h"
  9. #include "stdlib.h"
  10. #include "Driver.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. // ------------------------------------------------------------------------
  17. // CONSTANT DEFINITION
  18. // ------------------------------------------------------------------------
  19. #define     MAX_DEVICES     100
  20. // ------------------------------------------------------------------------
  21. // GLOBAL VARIABLES
  22. // ------------------------------------------------------------------------
  23. static      DEVFEATURES     DevFeatures;    // structure for device features
  24. static      PT_AIConfig     ptAIConfig;     // structure for AIConfig table
  25. static      PT_AIVoltageIn  ptAIVoltageIn;  // structure for AIVoltageIn table
  26. static      PT_DeviceGetFeatures  ptDevFeatures;
  27. char        szErrMsg[80];               // Use for MESSAGEBOX function
  28. LRESULT     ErrCde;                     // Return error code
  29. //
  30. // used for dynamic allocation memory for the installed devices
  31. //
  32. // static  HGLOBAL     hDeviceList,hSubDeviceList;
  33. // static  LPDEVLIST   DeviceList,SubDeviceList;
  34. //
  35. //
  36. // used for fixed memory for the installed devices
  37. //
  38. DEVLIST     DeviceList[MAX_DEVICES];
  39. DEVLIST     SubDeviceList[MAX_DEVICES];
  40. LONG        DriverHandle = (LONG)NULL;          // driver handle
  41. //BOOL        bRun = FALSE;                       // flag for running
  42. USHORT      gwDevice = 0, gwSubDevice = 0;      // Device index
  43. USHORT      gwChannel=0 ;                       // input channel
  44. USHORT      gwGain = 0;                         // gain index
  45. SHORT       gnNumOfDevices, gnNumOfSubdevices;  // number of installed devices
  46. USHORT      gwScanTime = 500;                   // scan time 采样周期、扫描时间
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CControl dialog
  49. CControl::CControl(CWnd* pParent /*=NULL*/)
  50. : CDialog(CControl::IDD, pParent)
  51. {
  52. //{{AFX_DATA_INIT(CControl)
  53. // NOTE: the ClassWizard will add member initialization here
  54. //}}AFX_DATA_INIT
  55. }
  56. void CControl::DoDataExchange(CDataExchange* pDX)
  57. {
  58. CDialog::DoDataExchange(pDX);
  59. //{{AFX_DATA_MAP(CControl)
  60. // NOTE: the ClassWizard will add DDX and DDV calls here
  61. //}}AFX_DATA_MAP
  62. }
  63. BEGIN_MESSAGE_MAP(CControl, CDialog)
  64. //{{AFX_MSG_MAP(CControl)
  65. //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CControl message handlers
  69. int CControl::Init() //1,成功;0,失败;
  70. {
  71. return 1;
  72.        // --------------------------------
  73.         // 1.Initialize Device List Combobox
  74.         // --------------------------------
  75.         // get number of the installed devices
  76.         if ((ErrCde = DRV_DeviceGetNumOfList((SHORT far *)&gnNumOfDevices)) !=
  77.             SUCCESS)
  78.         {
  79.              DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
  80.              MessageBox((LPCSTR)szErrMsg, "Driver Message", MB_OK);
  81.         }
  82.         if (gnNumOfDevices > MAX_DEVICES)
  83.             gnNumOfDevices = MAX_DEVICES;
  84.         // retrieve the information of all installed devices
  85.         if ((ErrCde = DRV_DeviceGetList((DEVLIST far *)&DeviceList[0],
  86.             (SHORT)gnNumOfDevices, (SHORT far *)&nOutEntries)) != (LONG)SUCCESS)
  87.         {
  88.             DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
  89.             MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
  90.         }
  91.         gnNumOfSubdevices = DeviceList[gwDevice].nNumOfSubdevices;
  92.         if (gnNumOfSubdevices > MAX_DEVICES)
  93.             gnNumOfSubdevices = MAX_DEVICES;
  94.         if (gnNumOfSubdevices != 0)
  95.         {
  96.             if ((ErrCde = DRV_DeviceGetSubList(
  97.                 (DWORD)DeviceList[gwDevice].dwDeviceNum,
  98.                 (DEVLIST far *)&SubDeviceList[0],
  99.                 (SHORT)gnNumOfSubdevices,
  100.                 (SHORT far *)&nOutEntries)) != (LONG)SUCCESS)
  101.             {
  102.                 DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
  103.                 MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
  104.             }
  105.         }
  106.         // first : Open Device
  107.         if (gnNumOfSubdevices == 0)
  108.         {
  109.             ErrCde = DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,
  110.                (LONG far *)&DriverHandle);
  111.         }
  112.         else
  113.         {
  114.             ErrCde = DRV_DeviceOpen(
  115.                 SubDeviceList[gwSubDevice].dwDeviceNum,
  116.                 (LONG far *)&DriverHandle);
  117.         }
  118.         if (ErrCde != SUCCESS)
  119.         {
  120. //            strcpy(szErrMsg,"Device open error !");
  121.  //           MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
  122.         }
  123.         // second: get device features
  124.         ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
  125.         ptDevFeatures.size = sizeof(DEVFEATURES);
  126.         if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
  127.             (LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
  128.         {
  129.             DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
  130.  //           MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
  131.             DRV_DeviceClose((LONG far *)&DriverHandle);
  132.         }
  133. //        DRV_DeviceClose((LONG far *)&DriverHandle);
  134. return 1;
  135. }
  136. double CControl::Collectdata()
  137. {
  138. return rand()/500;//返回随机数
  139. //返回板卡采集电压
  140.    /* float fVoltage;
  141. gwChannel=0;
  142. ptAIConfig.DasGain = DevFeatures.glGainList[gwGain].usGainCde;
  143. ptAIConfig.DasChan = gwChannel;
  144. if ((ErrCde = DRV_AIConfig(DriverHandle,(LPT_AIConfig)&ptAIConfig)) != 0)  
  145. {
  146. DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
  147. MessageBox((LPCSTR)szErrMsg,"Driver Message,and Stopping!",MB_OK);
  148. DRV_DeviceClose((LONG far *)&DriverHandle);
  149. }
  150. //2.read an analog input channel
  151. ptAIVoltageIn.chan =gwChannel; 
  152. ptAIVoltageIn.gain =ptAIConfig.DasGain  ;
  153. ptAIVoltageIn.TrigMode = 0;  
  154. ptAIVoltageIn.voltage=(FLOAT far*)&fVoltage;
  155. ErrCde = DRV_AIVoltageIn(DriverHandle, &ptAIVoltageIn);
  156. if(ErrCde != SUCCESS)
  157. {
  158. DRV_DeviceClose((LONG far *)&DriverHandle);
  159. }
  160. return fVoltage;*/
  161. }