public void StartReading() { //We always want to read SCAN_RATE samples per channel int scanRate = _daqs.Length * SCAN_RATE; int iteration = 0; while (_continueReading) { int memHandle = MccDaq.MccService.WinBufAlloc(scanRate); MccDaq.MccBoard theBoard = new MccDaq.MccBoard(0); ushort[] buffer = new ushort[scanRate]; float[] outVal = new float[(int)scanRate]; MccDaq.ErrorInfo stat = new MccDaq.ErrorInfo(); int scannedRate = 1000; stat = theBoard.AInScan(0, _daqs.Length - 1, scanRate, ref scannedRate, MccDaq.Range.Bip5Volts, memHandle, MccDaq.ScanOptions.Default); stat = MccDaq.MccService.WinBufToArray(memHandle, out buffer[0], 0, scanRate); for (int i = 0; i < buffer.Length; i++) { theBoard.ToEngUnits(MccDaq.Range.Bip5Volts, buffer[i], out outVal[i]); } MccDaq.MccService.WinBufFree(memHandle); Dictionary<IDAQ, IDAQPoint[]> readingDictionary = new Dictionary<IDAQ, IDAQPoint[]>(); foreach (IDAQ daq in _daqs) { readingDictionary.Add(daq, new IDAQPoint[SCAN_RATE]); } for (int i = 0; i < scanRate;) { foreach (IDAQ daq in _daqs) { DAQChannel chDaq = (DAQChannel)daq; ReadingDetail rd = new ReadingDetail(); int currentIndex = i / _daqs.Length; rd.ParentChannel = chDaq; rd.Time = currentIndex + (iteration * SCAN_RATE); rd.Reading = outVal[i]; readingDictionary[daq][currentIndex] = rd; chDaq.ReadingDetails.Add(rd); i++; } } iteration++; _dataRetrieved(readingDictionary); } lock (this) { _stopFinishedCallback(); } }
private void GetReadingDetailsForChannel(DAQChannel ch) { Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@cid",ch.ID); IDataReader reader = ExecuteQuery("SELECT rd_id,rd_time,rd_point from READING_DETAIL where rd_cid = @cid order by rd_time asc", parameters); while (reader.Read()) { ReadingDetail rd = new ReadingDetail(); rd.ID = reader.GetInt32(0); rd.ParentChannel = ch; rd.Time = reader.GetInt32(1); rd.Reading = reader.GetFloat(2); ch.ReadingDetails.Add(rd); } reader.Close(); }
public void SaveReadingDetail(ReadingDetail rd) { SQLiteCommand cmd = _connection.CreateCommand(); cmd.CommandText = Properties.Settings.Default.INSERT_READING_DETAIL; cmd.Parameters.Add(new SQLiteParameter("@rid", rd.ParentChannel.ParentReading.ID)); cmd.Parameters.Add(new SQLiteParameter("@cid", rd.ParentChannel.ID)); cmd.Parameters.Add(new SQLiteParameter("@time", rd.Time)); cmd.Parameters.Add(new SQLiteParameter("@point", rd.Reading)); rd.ID = Convert.ToInt32(cmd.ExecuteScalar()); }
public ReadingDetail CreateDetailForChannelandReading(DAQChannel ch, int time, int reading) { ReadingDetail rd = new ReadingDetail(); rd.Time = time; rd.Reading = reading; rd.ParentChannel = ch; SQLiteCommand cmd = _connection.CreateCommand(); cmd.CommandText = Properties.Settings.Default.INSERT_READING_DETAIL; cmd.Parameters.Add(new SQLiteParameter("@rid", ch.ParentReading.ID)); cmd.Parameters.Add(new SQLiteParameter("@cid", ch.ID)); cmd.Parameters.Add(new SQLiteParameter("@time", time)); cmd.Parameters.Add(new SQLiteParameter("@point", reading)); int rdid = Convert.ToInt32(cmd.ExecuteScalar()); rd.ID = rdid; ch.ReadingDetails.Add(rd); return rd; }