// 说明: 本程序演示了如何用程序查询方式读取AD数据 #include "stdafx.h" #include "windows.h" #include "stdio.h" #include "conio.h" #include "ACTS1000.h" #define AD_DATA_LEN 512*1024 // 要读取和处理的AD数据长度(点或字) USHORT ADBuffer[AD_DATA_LEN]; // 分配缓冲区(存储原始数据) ULONGLONG nReadCnt = 0; LONG ADCallBackFunc(HANDLE hDevice, ULONG nSamplesPerChan, ULONG nChannelCount, void *callbackData) { ULONG nRetSizeWords; ULONG nAvailSampsPoints; if (nSamplesPerChan>(AD_DATA_LEN/nChannelCount)) { nSamplesPerChan = AD_DATA_LEN/nChannelCount; } if (hDevice == INVALID_HANDLE_VALUE) { return 1; } if(!ACTS1000_ReadDeviceAD(hDevice, ADBuffer, nSamplesPerChan*nChannelCount, &nRetSizeWords, &nAvailSampsPoints,0.1)) { printf("ACTS1000_ReadDeviceAD error...\n"); _getch(); return 2; } if (nRetSizeWords!=(nSamplesPerChan*nChannelCount)) { printf("nRetSizeWords error...\n"); _getch(); return 3; } nReadCnt+=nSamplesPerChan; printf("ADBuff[0]=0x%X\n", ADBuffer[0]); return 0; } int main(int argc, char* argv[]) { HANDLE hDevice; int DeviceLgcID; ULONG ulDDR2Length = 0; ACTS1000_PARA_AD ADPara; // 硬件参数 ULONGLONG nReadSizeWords; ULONG InputRange = ACTS1000_INPUT_N1000_P1000mV; int nADChannel = 0; ACTS1000_AD_MAIN_INFO ADMainInfo; WORD wMaxLSB = 0x3FFF; float fLsbCount = 16384.0; ULONG nSamplesPerChan = 131072; DeviceLgcID = 0; printf("请输入逻辑ID:"); scanf_s("%d", &DeviceLgcID); hDevice = ACTS1000_CreateDevice(DeviceLgcID); // 创建设备对象 if(hDevice == INVALID_HANDLE_VALUE) { printf("CreateDevice error...\n"); _getch(); return 0; // 如果创建设备对象失败,则返回 } ACTS1000_GetMainInfo(hDevice,&ADMainInfo); // DDR2的长度(单位:MB) switch (ADMainInfo.nDeviceType>>16) { case 0x2012: printf("PXIE%04X\n",ADMainInfo.nDeviceType&0xFFFF); break; case 0x2111: printf("PCIE%04X\n",ADMainInfo.nDeviceType&0xFFFF); break; default: printf("ACTS1000-%04X\n",ADMainInfo.nDeviceType); } wMaxLSB = (WORD)(ADMainInfo.nSampCodeCount - 1); fLsbCount = (float)ADMainInfo.nSampCodeCount; ULONG nRevisionID = 0; if(!ACTS1000_GetBusInfo(hDevice, NULL, NULL, NULL, &nRevisionID)) { printf("ACTS1000_GetBusInfo error...\n"); } memset(&ADPara, 0x00, sizeof(ADPara)); // 将各项参数复位至确定值0(强烈建议) // 预置硬件参数 ADPara.SampleMode = ACTS1000_SAMPMODE_FINITE; // 有限点采样 ADPara.FreqDivision = 1; for (int nCH=0; nCH=nReadSizeWords) { printf("有限点采样(%I64d字节)完成按任意键退出\n", nReadCnt*ChannelCount*2); break; } } ACTS1000_StopDeviceAD(hDevice); // 停止AD ACTS1000_ReleaseDeviceAD(hDevice); // 释放AD ACTS1000_ReleaseDevice(hDevice); // 释放设备对象 _getch(); return 0; }