📄 sys.cpp
字号:
// 本程序演示了半满方式的AD采集过程
// 只采集0,1两个通道
// 量程设为:-5V至+5V
// 使用内触发
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "conio.h"
#include "PCI2006.h" // 驱动程序头文件(必须)
int main(int argc, char* argv[])
{
HANDLE hDevice;
int DeviceID;
PCI2006_PARA_AD ADPara;
SHORT ADBuffer[ 8192 ];
int nReadSizeWords;
BOOL bNotEmpty, bHalf, bOverflow; // 获得状态数组
int nRemainder;
float PerLsbVolt = (float)(10000.0/16384.0); // 取得单位LSB所对应的电压值
DeviceID = 0; // 假如只管理一个设备
hDevice = PCI2006_CreateDevice( DeviceID );
if(hDevice == INVALID_HANDLE_VALUE) return 0;
ADPara.ADMode = PCI2006_SEQUENCE_MODE;//连续采集
ADPara.ChannelCount = 2; // 通道数量
ADPara.ChannelArray[0].ADChannel = 0; // 0通道
ADPara.ChannelArray[0].ADGains = 0; // 1倍增益
ADPara.ChannelArray[1].ADChannel = 1; // 1通道
ADPara.ChannelArray[1].ADGains = 0; // 1倍增益
ADPara.Frequency = 25000; // 采样频率(Hz)
ADPara.GroupInterval = 1000; //分组间隔时间 采集模式为分组方式时才有效(uS)
ADPara.TriggerSource =PCI2006_IN_TRIGGER; // 内触发方式
ADPara.OutDigitAnalog =PCI2006_ANALOG_TRIGGER; // 模拟触发(外触发时有效)
ADPara.OutTriggerEdge =PCI2006_RISING_EDGE; // 上升沿((外触发时有效))
ADPara.ClockSource =PCI2006_IN_CLOCK; // 内部时钟
nReadSizeWords = 32; // 每次只读取32个点
// 为每次读操作时,通道能对齐所进行的算法
nRemainder = nReadSizeWords % ADPara.ChannelCount ;
nReadSizeWords = nReadSizeWords - nRemainder;
if(!PCI2006_InitDeviceProAD( hDevice, &ADPara)) // 硬件参数, 它仅在此函数中决定硬件状态
goto ExitRead1;
if(!PCI2006_StartDeviceProAD(hDevice)) // 启动AD转换
goto ExitRead1;
while ( !kbhit() )
{
if(!PCI2006_GetDevStatusProAD(hDevice,&bNotEmpty,&bHalf,&bOverflow))
{
printf("获得状态错误!");
break;
}
if(!bHalf)
{
//没有半满重新读标志
continue;
}
if(!PCI2006_ReadDeviceProAD_Half( hDevice, ADBuffer, nReadSizeWords)) // 读入的数据
goto ExitRead0;
for( int Index = 0; Index< 32; Index+=2 )
{
// 按照-5V --- +5V 量程转换为电压值
printf("CH0 = %7.2f \t" , (((ADBuffer[Index]^0x2000 )&0x3fff)) * PerLsbVolt - 5000.0 );
printf("CH1 = %7.2f \n" , (((ADBuffer[Index+1]^0x2000 )&0x3fff)) * PerLsbVolt - 5000.0 );
}
}
ExitRead0:
PCI2006_ReleaseDeviceProAD( hDevice );
ExitRead1:
PCI2006_ReleaseDevice( hDevice );
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -