private void DaqBoard_DataReceived(int BoardNum, EventType EventType, uint EventData, IntPtr pUserData) { //Get timestamp immediately, increment SampleCount. _timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff"); SampleCount++; //Copy input to Data[], using temp[] to notify the change. if (DaqBoard.BoardName != "USB-1408FS") { double[] temp = new double[16]; if (tick) { MccService.ScaledWinBufToArray(_dataPtr, temp, 0, numChannels + 1); tick = false; } else { MccService.ScaledWinBufToArray(_dataPtr, temp, numChannels + 1, numChannels + 1); tick = true; } _data = temp; } else { short[] tempShort = new short[4]; MccService.WinBufToArray(_dataPtr, tempShort, 0, 4); float[] tempFloat = new float[4]; double[] tempDouble = new double[16]; for (int i = 0; i < 4; i++) { DaqBoard.ToEngUnits(Resolution, tempShort[i], out tempFloat[i]); tempDouble[i] = (double)tempFloat[i]; } _data = tempDouble; } //Update chart on the worker thread _updateChart = true; //Prep command parameters Database.InsertRowCommand.Parameters.Add(new SQLiteParameter("Time", _timeStamp)); //TODO: Use a Sync Queue to insert data for (int i = 0; i < _data.Length; i++) { if (_data[i] != 0.0) { GridData.Rows[i][1] = _data[i]; Database.InsertRowCommand.Parameters.Add(new SQLiteParameter("Dev" + i.ToString(), _data[i])); } else { Database.InsertRowCommand.Parameters.Add(new SQLiteParameter("Dev" + i.ToString(), null)); } //If more than ~1hr of data at 200ms, remove to keep memory low if (SampleCount > 20000) { Series[i].Values.RemoveAt(0); } } //Execute Command Database.ExecuteCommand(Database.InsertRowCommand); //Update X Axis bounds if (SampleCount >= XAxisMax) { XAxisMax = SampleCount; XAxisMin = SampleCount - DisplayPoints; } }