using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.IO; using System.Text.RegularExpressions; namespace AI_SoftwareTrigger_Log { class Program { public static bool IsIP(string ip) //Check the IP format { return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); } private static float Calibrate(UInt16 h16Bit, Int16 iGain, UInt16 g, Int16 o) { Int32 lAD_Data; float fVal = 0; lAD_Data = (Int32)h16Bit * (Int32)(g); lAD_Data >>= 15; lAD_Data += (Int16)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; } static void Main(string[] args) { string IP = ""; bool ret = false; bool quitIP = false; bool quit = false; IntPtr hHS; UInt16 gVal = 0; Int16 oVal = 0; UInt16[] gVarr = new UInt16[8]; Int16[] oVarr = new Int16[8]; short ChCnt = 8; short Gain = 0; uint ulleng = 0; uint triggerStatus = 0; short TrigMode = 0; UInt32 targetCnt = 800; int sampleRate = 1000; //unsigned long totalRead=0,totalReceived=0; short DataTransMethod = 0; short AutoRun = 0; string path = Directory.GetCurrentDirectory(); while (quitIP == false) { Console.WriteLine("Please Enter IP!!"); IP = Console.ReadLine(); ret = IsIP(IP); if (ret == false) { Console.WriteLine("Please enter the correct IP"); } else { quitIP = true; Thread.Sleep(100); } } hHS = HSDAQNet.Sys.HS_Device_Create(IP); if (hHS != IntPtr.Zero) { Console.WriteLine("HSDAQ SDK Ver= " + HSDAQNet.Sys.GetSDKVersion().ToString()); Console.WriteLine("ET7H16 Firmware Ver= " + HSDAQNet.Sys.GetFirmwareVersion(hHS).ToString()); ret = HSDAQNet.HSIO.HS_SetAIScanParam(hHS, ChCnt, Gain, TrigMode, sampleRate, targetCnt, DataTransMethod, AutoRun); HSDAQNet.HSIO.HS_GetAIScanParam(hHS, ref ChCnt, ref Gain, ref TrigMode, ref sampleRate, ref targetCnt, ref DataTransMethod, ref AutoRun); Console.WriteLine("Ch=" + ChCnt + ",Gain=" + Gain + ",TrigMode=" + TrigMode + ",sampleRate=" + sampleRate + ",targetCnt=" + targetCnt); for (int ch = 0; ch < 8; ch++) { HSDAQNet.Config.HS_ReadGainOffset(hHS, ch, ref gVal, ref oVal); gVarr[ch] = gVal; oVarr[ch] = oVal; Console.WriteLine("[ch" + ch + "]Gain = " + gVal + " , Offset = " + oVal); } if (!ret) { Console.WriteLine("Error code1 0x" + HSDAQNet.ErrHandling.GetLastError().ToString("x8")); } else { ret = HSDAQNet.DATALOG.HS_StartLogger(hHS, path, 2, 0); if (ret == false) { Console.WriteLine("Error code2 0x" + HSDAQNet.ErrHandling.GetLastError().ToString("x8")); } while (quit == false) { ret = HSDAQNet.HSIO.HS_GetTotalSamplingStatus(hHS, ref ulleng, ref triggerStatus); if (ret == false) { Console.WriteLine("Error code3 0x" + HSDAQNet.ErrHandling.GetLastError().ToString("x8")); } else { if (ulleng >= targetCnt && (triggerStatus >> 7) == 1) //N sample mode { Console.WriteLine("\r\nAP total read = " + ulleng.ToString() + "\r\n"); //Step 6:When the total number of samples reaches the target counts. Send a command to get the all acquisition data over the Ethernet. Thread.Sleep(10); break; } } } //Console.WriteLine("1\r\n"); Thread.Sleep(1000); HSDAQNet.DATALOG.HS_StopLogger(hHS); //Console.WriteLine("2\r\n"); Thread.Sleep(10); HSDAQNet.Sys.HS_Device_Release(hHS); } } short gchCnt = 0; short guseGain = 0; short gextriggMode = 0; int gsampleRate = 0; short gDataTransMethod = 0; short SyncMode = 0; Console.WriteLine("Waiting for search ....."); int ind = HSDAQNet.DATALOG.HS_GetAllLogFiles(path, 0); if (ind > 0) { for (int i = 0; i < ind; i++) { path = ""; IntPtr hlf = HSDAQNet.DATALOG.HS_LogFile_Open_byIndex(i,ref path); Console.WriteLine("\r\n" + i + " ==> " + path); HSDAQNet.DATALOG.HS_GetLogFile_AIScanConfigInfo(hlf, ref gchCnt, ref guseGain, ref gextriggMode, ref gsampleRate, ref gDataTransMethod, ref SyncMode); Console.WriteLine("Ch= " + gchCnt + "," + "Gain= " + guseGain + "," + "TriggMode= " + gextriggMode + "," + "SampleRate= " + gsampleRate + "," + "DataTransMethod= " + gDataTransMethod); ushort gainVal = 0; short offsetVal = 0; for (int a = 0; a < gchCnt; a++) { HSDAQNet.DATALOG.HS_GetLogFile_GainOffset(hlf, a, ref gainVal, ref offsetVal); gVarr[a] = gainVal; oVarr[a] = offsetVal; Console.WriteLine(a + ",Gain= " + gainVal + ",Offset= " + offsetVal); } UInt32 filesize = 0; int filetype = 0; int fileversion = 0; uint samplecount = 0; string DataTime = ""; string StartTime = ""; //Step 13:Get the file information of the selected log file HSDAQNet.DATALOG.HS_GetLogFileInfo(hlf, ref filesize, ref filetype, ref fileversion); Console.WriteLine("Filesize= " + filesize + ",Filetype= " + filetype); //float[] fValue = new float[targetCnt]; HSDAQNet.DATALOG.HS_GetLogFile_AIScanSampleInfo(hlf,ref samplecount,ref DataTime,ref StartTime); Console.WriteLine("Samplecount= " + samplecount + ",DataTime= " + DataTime + ",StartTime= " + StartTime); UInt16[] Value = new UInt16[targetCnt]; float[] fValue = new float[targetCnt]; HSDAQNet.DATALOG.HS_GetLogFile_AIDataHex(hlf, 0, targetCnt, Value); for (int a = 0; a < targetCnt; a++) { fValue[a] = Calibrate(Value[a], guseGain, gVarr[a % 8], oVarr[a % 8]); } int index =0; for (int a = 0; a < targetCnt; a+=8) { Console.WriteLine("[" + index + "]," + fValue[a].ToString("F4") + "," + fValue[a + 1].ToString("F4") + "," + fValue[a + 2].ToString("F4") + "," + fValue[a + 3].ToString("F4") + "," + fValue[a + 4].ToString("F4") + "," + fValue[a + 5].ToString("F4") + "," + fValue[a + 6].ToString("F4") + "," + fValue[a + 7].ToString("F4")); index++; } HSDAQNet.DATALOG.HS_LogFile_Close(hlf); } } else { Console.WriteLine("No File!!"); } Console.WriteLine("Press 'Q' to quit program"); while (Console.ReadKey(true).Key != ConsoleKey.Q) ; } } }