新增阿尔泰卡测试功能。
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
#include "StdAfx.h"
|
||||
#include <WinDef.h>
|
||||
#include <WinBase.h>
|
||||
#include "ART_PCI8622.h"
|
||||
|
||||
#define MAX_AD_CHANNELS 4
|
||||
#define SEGMENT_COUNT 32
|
||||
#define HALF_SIZE_WORDS 4096
|
||||
|
||||
|
||||
CART_PCI8622::CART_PCI8622()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CART_PCI8622::~CART_PCI8622()
|
||||
{
|
||||
|
||||
}
|
||||
//========================================
|
||||
BOOL CART_PCI8622::Init()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
//========================================
|
||||
BOOL CART_PCI8622::Exit()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
//========================================
|
||||
BOOL CART_PCI8622::GetData()
|
||||
{
|
||||
BOOL rStatus(TRUE);
|
||||
#ifdef _RELEASE_FULL_VERSION
|
||||
int InputRange(0);
|
||||
int SelectInputRange(void);
|
||||
WORD ADBuffer[SEGMENT_COUNT][HALF_SIZE_WORDS]; // 分配缓冲区(存储原始数据)
|
||||
ULONG SegmentID = 0;
|
||||
|
||||
HANDLE hDevice;
|
||||
int DeviceLgcID;
|
||||
|
||||
PCI8622_PARA_AD ADPara; // 硬件参数
|
||||
PCI8622_STATUS_DMA DMAStatus; // DMA状态参数
|
||||
|
||||
int Index(0);
|
||||
|
||||
int nADChannel = 0;
|
||||
WORD ADData(0);
|
||||
float fVolt(0);
|
||||
|
||||
DeviceLgcID = 0;
|
||||
hDevice = PCI8622_CreateDevice(DeviceLgcID); // 创建设备对象
|
||||
if(hDevice == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
rStatus=FALSE;
|
||||
return rStatus; // 如果创建设备对象失败,则返回
|
||||
}
|
||||
|
||||
memset(&ADPara, 0x00, sizeof(ADPara)); // 将各项参数复位至确定值0(强烈建议)
|
||||
|
||||
// 预置硬件参数
|
||||
ADPara.ADMode = PCI8622_ADMODE_SEQUENCE; // AD模式为连续模式
|
||||
ADPara.FirstChannel = 1; // 首通道
|
||||
ADPara.LastChannel = 2; // 末通道
|
||||
ADPara.Frequency = 10000; // 采样频率(Hz)
|
||||
ADPara.GroupInterval = 50; // 组间间隔(uS)
|
||||
ADPara.LoopsOfGroup = 1; // 组内各通道点数
|
||||
ADPara.Gains = PCI8622_GAINS_1MULT;
|
||||
ADPara.InputRange = InputRange; // 模拟量输入量程范围
|
||||
|
||||
ADPara.TriggerMode = PCI8622_TRIGMODE_SOFT; // 触发模式为软件触发
|
||||
ADPara.TriggerType = PCI8622_TRIGTYPE_EDGE; // 触发类型为边沿触发
|
||||
ADPara.TriggerDir = PCI8622_TRIGDIR_NEGATIVE; // 触发方向为负向
|
||||
ADPara.TrigWindow = 40; // 触发灵敏度
|
||||
|
||||
ADPara.ClockSource = PCI8622_CLOCKSRC_IN; // 时钟源选用板内时钟源
|
||||
ADPara.bClockOutput = FALSE; // 禁止时钟输出
|
||||
ADPara.GroundingMode = PCI8622_GNDMODE_SE; // 单端方式(SE:Single end)
|
||||
ADPara.TimeoutForNpt = 10; // 在非空方式下,设置超时时间为10秒钟(只在非空查询方式下有效)
|
||||
|
||||
HANDLE hDmaEvent = PCI8622_CreateSystemEvent();
|
||||
if(!PCI8622_InitDeviceDmaAD( hDevice, hDmaEvent, &ADBuffer[0][0], 4096, SEGMENT_COUNT, HALF_SIZE_WORDS, &ADPara)) // 初始化硬件
|
||||
{
|
||||
rStatus=FALSE;
|
||||
goto ExitRead0;
|
||||
}
|
||||
|
||||
PCI8622_StartDeviceDmaAD(hDevice); // 启动设备
|
||||
bool bWait(true);
|
||||
while(bWait) // 查询当前物理缓冲区数据是否已准备就绪
|
||||
{
|
||||
if(WaitForSingleObject (hDmaEvent, 100)==WAIT_OBJECT_0)
|
||||
bWait=false; // 等待DMA事件
|
||||
}
|
||||
|
||||
if(!PCI8622_GetDevStatusDmaAD(hDevice, &DMAStatus))
|
||||
{
|
||||
rStatus=FALSE;
|
||||
goto ExitRead0;
|
||||
}
|
||||
|
||||
if(DMAStatus.bBufferOverflow)
|
||||
{
|
||||
rStatus=FALSE;
|
||||
}
|
||||
|
||||
for(SegmentID=0; SegmentID<SEGMENT_COUNT; SegmentID++)
|
||||
{
|
||||
if(DMAStatus.bSegmentSts[SegmentID])
|
||||
{
|
||||
nADChannel = ADPara.FirstChannel;
|
||||
for(Index=0; Index<64; Index++)
|
||||
{
|
||||
ADData = ((ADBuffer[SegmentID][Index]));
|
||||
// 将原码转换为电压值
|
||||
switch(InputRange)
|
||||
{
|
||||
case PCI8622_INPUT_N10000_P10000mV: // -10V - +10V
|
||||
fVolt = (float)((20000.0/65536) * ADData - 10000.0);
|
||||
break;
|
||||
case PCI8622_INPUT_N5000_P5000mV: // -5V - +5V
|
||||
fVolt = (float)((10000.0/65536) * ADData - 5000.0);
|
||||
break;
|
||||
case PCI8622_INPUT_N2500_P2500mV: // -2.5V - +2.5V
|
||||
fVolt = (float)((5000.0/65536) * ADData - 2500.0);
|
||||
break;
|
||||
case PCI8622_INPUT_0_P10000mV: // 0V - +10V
|
||||
fVolt = (float)((10000.0/65536) * ADData);
|
||||
break;
|
||||
case PCI8622_INPUT_0_P5000mV: // 0V - +5V
|
||||
fVolt = (float)((5000.0/65536) * ADData);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
nADChannel++;
|
||||
if(nADChannel > ADPara.LastChannel)
|
||||
{
|
||||
nADChannel = ADPara.FirstChannel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!PCI8622_SetDevStatusDmaAD(hDevice, SegmentID))
|
||||
{
|
||||
rStatus=FALSE;
|
||||
goto ExitRead0;
|
||||
}
|
||||
} // end of for(SegmentID=0; SegmentID<SEGMENT_COUNT; SegmentID++)
|
||||
|
||||
ExitRead0:
|
||||
PCI8622_ReleaseDeviceDmaAD(hDevice); // 释放AD
|
||||
PCI8622_ReleaseSystemEvent(hDmaEvent);
|
||||
PCI8622_ReleaseDevice(hDevice); // 释放设备对象
|
||||
#endif //_RELEASE_FULL_VERSION
|
||||
|
||||
return rStatus;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user