📄 control.cpp
字号:
// Control.cpp : implementation file
//
#include "stdafx.h"
#include "心跳检测.h"
#include "Control.h"
#include "MainFrm.h"
#include "Math.h"
#include "conio.h"
#include "stdlib.h"
#include "Driver.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// ------------------------------------------------------------------------
// CONSTANT DEFINITION
// ------------------------------------------------------------------------
#define MAX_DEVICES 100
// ------------------------------------------------------------------------
// GLOBAL VARIABLES
// ------------------------------------------------------------------------
static DEVFEATURES DevFeatures; // structure for device features
static PT_AIConfig ptAIConfig; // structure for AIConfig table
static PT_AIVoltageIn ptAIVoltageIn; // structure for AIVoltageIn table
static PT_DeviceGetFeatures ptDevFeatures;
char szErrMsg[80]; // Use for MESSAGEBOX function
LRESULT ErrCde; // Return error code
//
// used for dynamic allocation memory for the installed devices
//
// static HGLOBAL hDeviceList,hSubDeviceList;
// static LPDEVLIST DeviceList,SubDeviceList;
//
//
// used for fixed memory for the installed devices
//
DEVLIST DeviceList[MAX_DEVICES];
DEVLIST SubDeviceList[MAX_DEVICES];
LONG DriverHandle = (LONG)NULL; // driver handle
//BOOL bRun = FALSE; // flag for running
USHORT gwDevice = 0, gwSubDevice = 0; // Device index
USHORT gwChannel=0 ; // input channel
USHORT gwGain = 0; // gain index
SHORT gnNumOfDevices, gnNumOfSubdevices; // number of installed devices
USHORT gwScanTime = 500; // scan time 采样周期、扫描时间
/////////////////////////////////////////////////////////////////////////////
// CControl dialog
CControl::CControl(CWnd* pParent /*=NULL*/)
: CDialog(CControl::IDD, pParent)
{
//{{AFX_DATA_INIT(CControl)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CControl::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CControl)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CControl, CDialog)
//{{AFX_MSG_MAP(CControl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CControl message handlers
int CControl::Init() //1,成功;0,失败;
{
return 1;
// --------------------------------
// 1.Initialize Device List Combobox
// --------------------------------
// get number of the installed devices
if ((ErrCde = DRV_DeviceGetNumOfList((SHORT far *)&gnNumOfDevices)) !=
SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg, "Driver Message", MB_OK);
}
if (gnNumOfDevices > MAX_DEVICES)
gnNumOfDevices = MAX_DEVICES;
// retrieve the information of all installed devices
if ((ErrCde = DRV_DeviceGetList((DEVLIST far *)&DeviceList[0],
(SHORT)gnNumOfDevices, (SHORT far *)&nOutEntries)) != (LONG)SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
}
gnNumOfSubdevices = DeviceList[gwDevice].nNumOfSubdevices;
if (gnNumOfSubdevices > MAX_DEVICES)
gnNumOfSubdevices = MAX_DEVICES;
if (gnNumOfSubdevices != 0)
{
if ((ErrCde = DRV_DeviceGetSubList(
(DWORD)DeviceList[gwDevice].dwDeviceNum,
(DEVLIST far *)&SubDeviceList[0],
(SHORT)gnNumOfSubdevices,
(SHORT far *)&nOutEntries)) != (LONG)SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
}
}
// first : Open Device
if (gnNumOfSubdevices == 0)
{
ErrCde = DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
else
{
ErrCde = DRV_DeviceOpen(
SubDeviceList[gwSubDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
if (ErrCde != SUCCESS)
{
// strcpy(szErrMsg,"Device open error !");
// MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
}
// second: get device features
ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
ptDevFeatures.size = sizeof(DEVFEATURES);
if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
(LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
// MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
}
// DRV_DeviceClose((LONG far *)&DriverHandle);
return 1;
}
double CControl::Collectdata()
{
return rand()/500;//返回随机数
//返回板卡采集电压
/* float fVoltage;
gwChannel=0;
ptAIConfig.DasGain = DevFeatures.glGainList[gwGain].usGainCde;
ptAIConfig.DasChan = gwChannel;
if ((ErrCde = DRV_AIConfig(DriverHandle,(LPT_AIConfig)&ptAIConfig)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message,and Stopping!",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
}
//2.read an analog input channel
ptAIVoltageIn.chan =gwChannel;
ptAIVoltageIn.gain =ptAIConfig.DasGain ;
ptAIVoltageIn.TrigMode = 0;
ptAIVoltageIn.voltage=(FLOAT far*)&fVoltage;
ErrCde = DRV_AIVoltageIn(DriverHandle, &ptAIVoltageIn);
if(ErrCde != SUCCESS)
{
DRV_DeviceClose((LONG far *)&DriverHandle);
}
return fVoltage;*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -