// Analog_Input_Scan.cpp : Defines the entry point for the console application. // // HSDAQ data logger folder structure // // +----\log // +----\xx.xx.xx.xx // +----\yyyy_mm_dd_hh_mm [] // +----xx_xx_xx_xx_4c42_yyyy_mm_dd_hh_mm_ss.bin [file name] // // Note: // 1.xx.xx.xx.xx : [The folder name is IP address of the PET-7H16M] // 2.yyyy_mm_dd_hh_mm [It's the default folder format yyyy:year, mm:month, dd:day, hh:hour, mm:minute] // 3.10_1_107_125_4c42_2018_11_30_14_16_29.bin [file name] #include "stdafx.h" #include "HSDAQ.h" #include #include int ReplaceChar(char *srcStr,char r, char t) { int len=strlen(srcStr); int i; if(len) { for(i=0;i>= 15; lAD_Data += (int)o; if (lAD_Data > 32767) lAD_Data = 32767; else if (lAD_Data < -32768) lAD_Data = -32768; switch (iGain) { case 1: fVal = lAD_Data / (float)3276.8; //==> AD/32768*10 break; case 0: fVal = lAD_Data / (float)6553.6; //==> AD/32768*5 break; } return fVal; } int _tmain(int argc, _TCHAR* argv[]) { HANDLE hHS; char IPadd[64]="\0"; char sdk_version[16]={0}; char fw_version[32]={0}; bool ret= false; short chCnt=0; short useGain=0; short extriggMode=0; bool continuousMode=false; long continuousTimeout=0; unsigned long targetCnt=0; long sampleRate=0; short DataTransMethod=0; short AutoRun=0; if(argc>1) { wprintf(TEXT("%s\r\n"),argv[1]); WideCharToMultiByte(CP_ACP, 0, argv[1], -1, IPadd, 64, NULL, NULL); printf("program start %s\r\n",IPadd); } else { printf("error argument\r\n"); return 0; } char tmp[128]={0}; printf("ET-7H16 Analog Input data logger & read log file example [N sample mode & Software trigger]\r\n"); HS_GetSDKVersion(sdk_version); printf("HSDAQ SDK Ver=%s\r\n",sdk_version); sprintf(tmp,"%s",IPadd); //Step 1: Create a TCP connection with ET-7H16 hHS = HS_Device_Create(tmp); if(hHS!=NULL) { HS_GetFirmwareVersion(hHS,fw_version); printf("ET7H16 Firmware Ver=%s\r\n",fw_version); chCnt=8; extriggMode=0; targetCnt=800; sampleRate=1000; ret=HS_SetAIScanParam(hHS, chCnt, useGain, extriggMode, sampleRate, targetCnt, DataTransMethod,AutoRun); //Step 2: SetScanParam sets chCnt, useGain, triggerMode, sampleRate, targetCnt to ET7H16 if(ret==false) { printf("Error code 0x%x\r\n",HS_GetLastError()); } HS_GetAIScanParam(hHS, &chCnt, &useGain, &extriggMode, &sampleRate, &targetCnt,&DataTransMethod,&AutoRun); //Step 3: GetScanParam getsx chCnt, useGain, triggerMode, sampleRate, targetCnt to check with ET7H16 printf("ET-7H16 first Scan parameters chCnt %d, useGain %d, triggMode %d, sampleRate %ld, targetCnt %lu \n", chCnt, useGain, extriggMode, sampleRate, targetCnt); Sleep(10); TCHAR tcfullPath[MAX_PATH]; char cfullPath[MAX_PATH]; GetCurrentDirectory( MAX_PATH, tcfullPath ); WideToChar(tcfullPath,cfullPath); //Step 4: Start AI data logger ret=HS_StartLogger(hHS,cfullPath,2,0); // 2 mins //second paramter ==> NULL, it means the log file will saved to the current directory if(ret==false) { printf("Error code 0x%x\r\n",HS_GetLastError()); } WORD BufferStatus=0; #define BUFFERSIZE 1000 float fdataBuffer[BUFFERSIZE]; unsigned long ulleng=0; unsigned long totalRecv=0; unsigned int remChannel=0; unsigned long CH1checkerror=0; unsigned long CH7checkerror=0; unsigned long otherCHcheckerror=0; bool quit=false; unsigned int triggerStatus; //Step 5: while loop to get total received data count from ET-7H16 while(quit==false) { ret=HS_GetTotalSamplingStatus(hHS,&ulleng,&triggerStatus); if(ret==false) { printf("Error code 0x%x\r\n",HS_GetLastError()); } else { if(ulleng>=targetCnt && targetCnt>0) //N sample mode { //Step 6:When the total number of samples reaches the target counts. Send a command to get the all acquisition data over the Ethernet. //ret=HS_TransmitDataCmd(hHS); Sleep(6000); break; } else printf("."); } if(_kbhit()) { Sleep(1); if(_getch()=='q' || _getch()=='Q') break; } else Sleep(100); } //Step7: Stop AI data logger HS_StopLogger(hHS); printf("AP total read %lu\n", ulleng); //Step8: Close the connection HS_Device_Release(hHS); ReplaceChar(IPadd,'.','_'); strcat(cfullPath,"\\log\\"); strcat(cfullPath,IPadd); printf("\r\npath=%s\r\n",cfullPath); CharToWide(cfullPath,tcfullPath); short gchCnt=0; short guseGain=0; short gextriggMode=0; bool gcontinuousMode=false; long gcontinuousTimeout=0; unsigned long gtargetCnt=0; long gsampleRate=0; short gDataTransMethod; unsigned short gVarr[8]; short oVarr[8]; //Step 9: Get the total number of files in the specified folder according to the file type int ind=HS_GetAllLogFiles(tcfullPath,0); printf("ind=%d\r\n",ind); if(ind>0) { for(int i=0;i%s\r\n"),i,tcgetfulfilelPath); //Step 11:Get chCnt, useGain, triggerMode, sampleRate, targetCnt parameters of the selected log file HS_GetLogFile_AIScanConfigInfo(hlf,&gchCnt,&guseGain,&gextriggMode,&gsampleRate,&gDataTransMethod); printf("%d, %d, %d, %ld, %d\r\n",gchCnt,guseGain,gextriggMode,gsampleRate,gDataTransMethod); unsigned short gainVal=0; short offsetVal=0; //Step 12:Get gain/offset parameters of the selected log file for(int i=0;i