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?)$"); } 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, 1); 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, 1); 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 = ""; HSDAQNet.DATALOG.HS_GetLogFileInfo(hlf, ref filesize, ref filetype, ref fileversion); Console.WriteLine("filesize = " + filesize + ",filetype =" + filetype); HSDAQNet.DATALOG.HS_GetLogFile_AIScanSampleInfo(hlf, ref samplecount, ref DataTime, ref StartTime); Console.WriteLine("Samplecount = " + samplecount + ",DataTime = " + DataTime + ",StartTime = " + StartTime); float[] fValue = new float[targetCnt]; HSDAQNet.DATALOG.HS_GetLogFile_AIData(hlf, 0, targetCnt, fValue); 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) ; } } }