// 说明: 本程序演示了如何用程序查询方式读取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]; // 分配缓冲区(存储原始数据) 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; } printf("ADBuff[0]=0x%X\n", ADBuffer[0]); return 0; } int main(int argc, char* argv[]) { int DeviceLgcID; ULONG ulDDR2Length = 0; ULONGLONG ulDDR2LengthByte = 0; ACTS1000_PARA_AD ADPara; // 硬件参数 int nCurrentChannel = 0,nADChannel = 0; ACTS1000_AD_MAIN_INFO ADMainInfo; WORD wMaxLSB = 0x3FFF; float fLsbCount = 16384.0; ULONG nSamplesPerChan = 0; HANDLE hDevice; int InputRange; 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); } ulDDR2LengthByte = ADMainInfo.nDepthOfMemory; wMaxLSB = (WORD)(ADMainInfo.nSampCodeCount - 1); fLsbCount = (float)ADMainInfo.nSampCodeCount; InputRange = ACTS1000_INPUT_N1000_P1000mV; // 要求用户从键盘上选择输入量程 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_CONTINUOUS; // 有限点采样 ADPara.FreqDivision = 1000; for (int nCH=0; nCH