// DelayTrigger_AI_Scan_Cplusplus.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include #include "..\Lib\HSDAQ.h" #pragma comment(lib,"..\\Lib\\HSDAQ.lib") HANDLE hHS; char IP[20]; float FdataBuffer[30000000]; int _tmain(int argc, _TCHAR* argv[]) { bool ret = false; char str[50]; int ch = 0; unsigned short gVal = 0; short oVal = 0; unsigned short gVarr[8]; short oVarr[8]; short ChCnt = 0; short Gain = 0; short TrigMode = 5; //5 : delay trigger long sampleRate = 0; unsigned long targetCnt = 0; unsigned long delaytime=0; short DataTransMethod = 0; short AutoRun = 0; unsigned short BufferStatus = 0; unsigned int readsize = 0; unsigned long totalRecv = 0; unsigned long Reserv = 0; unsigned int i = 0; printf("Please input IP (xxx.xxx.xxx.xxx) !!\n"); while(1) { scanf("%s",IP); hHS = HS_Device_Create(IP); if (hHS < 0) { printf("Invalid IP, please input again.\n"); } else { Sleep(100); break; } } printf("ET-7H16 AI Scan Delay-trigger demo\n"); HS_GetSDKVersion(str); printf("HSDAQ SDK Version = %s\n", str); HS_GetFirmwareVersion(hHS,str); printf("ET7H16 Firmware Versoin = %s\n",str); for (ch = 0; ch < 8; ch++) { //Read Gain Offset valus for each channel HS_ReadGainOffset(hHS, ch, &gVal, &oVal); printf("ch : %d Gain Value : %u Offset Valus : %d\n", ch,gVal,oVal); gVarr[ch] = gVal; oVarr[ch] = oVal; } printf("Please input number of channels for sample data(1 ~ 8)\n"); scanf("%d",&ChCnt); printf("Please Select AI range\n"); printf("0 : +/- 5V\n"); printf("1 : +/- 10V\n"); scanf("%d",&Gain); printf("Please input sample rate(1 Hz ~ 200 KHz)\n"); scanf("%ld",&sampleRate); printf("Please input Target Count(1 ~ 30000000)\n"); scanf("%lu",&targetCnt); printf("Please input Delay time(5us ~ 10000000us)\n"); scanf("%lu",&delaytime); ret = HS_SetAIScanParam(hHS, ChCnt, Gain, TrigMode, sampleRate, targetCnt, DataTransMethod, AutoRun); if (!ret) { printf("HS_SetAIScanParam failed Error code1 0x%x \n", HS_GetLastError()); return 0; } ret = HS_SetAIDelayTriggerParam(hHS,delaytime,0); if (!ret) { printf("HS_SetAIDelayTriggerParam failed Error code1 0x%x",HS_GetLastError()); return 0; } else { HS_GetAIScanParam(hHS, &ChCnt, &Gain, &TrigMode, &sampleRate, &targetCnt, &DataTransMethod, &AutoRun); HS_GetAIDelayTriggerParam(hHS, &delaytime,&Reserv); printf("Set AI Scan : Ch = %d Gain = %d TrigMode = %d sampleRate = %lu targetCnt = %lu Delat time = %lu us\n",ChCnt,Gain,TrigMode,sampleRate,targetCnt,delaytime); ret = HS_StartAIScan(hHS); if (ret == false) { printf("Error code2 0x%x\n",HS_GetLastError()); } printf("The AI Scan is ready now, please input a 5v-pulse signal into the pins of Trig+ and Trig-"); for(;;) { ret = HS_GetAIBufferStatus(hHS, &BufferStatus, &totalRecv); if (ret == false) { printf("Error code3 0x%x",HS_GetLastError()); } else { if ((BufferStatus >>7) == 1 && (totalRecv >= targetCnt)) { readsize = HS_GetAIBuffer(hHS, FdataBuffer, targetCnt); break; } else if ((BufferStatus >>2) == 1) { printf("[error] AD_DATA_SAMPLING_TIMEOUT \n"); break; } else if ((BufferStatus >>1) == 1) { printf("[error] AD_BUF_OVERFLOW \n"); break; } else if ((BufferStatus & 0x01) == 0x01) { printf("Received Count : %lu Status :%X\r",totalRecv,BufferStatus); } else { printf("Sampling Count : %lu Status :%X\r",totalRecv,BufferStatus); } } Sleep(10); } HS_StopAIScan(hHS); HS_Device_Release(hHS); printf("\nIndex"); for (i = 0; i < ChCnt; i++) { printf("|CH%1d ",i); } for (i = 0; i < targetCnt; i++) { if(i%ChCnt==0) printf("\n%5d", i); printf("|%9.4f", FdataBuffer[i]); if (i % ChCnt == ChCnt - 1) { //printf("\n"); } } printf("\r\nAP total read = %lu\r\n",totalRecv ); printf("\n"); printf("Press any key to quit program"); } getchar(); getchar(); return 0; }