示例#1
1
        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();
            }
        }
示例#2
0
文件: ULEV02.cs 项目: r4forth/sdkpub
        private void cmdStart_Click(object sender, System.EventArgs e)
        {
            //Start input scan with  MccBoard.AInScan
            int rate = DesiredRate;

            DaqBoard.AInScan(0, 0, TotalCount, ref rate, Range, hBuffer, Options);
        }
        public Double[] StartSingleReadingWindow(double time, string output_fmt = "OD")
        {
            DaqBoard = new MccDaq.MccBoard(0);

            MccDaq.ErrorInfo ULStat;
            int   FirstPoint, NumChans = HighChan - LowChan + 1, CurIndex, CurCount;
            short Status;

            NumPoints = (int)(time) * Rate * NumChans;
            MemHandle = MccDaq.MccService.WinBufAllocEx(10 * NumPoints);

            Thread.Sleep(100);
            MccDaq.ScanOptions Options = MccDaq.ScanOptions.ConvertData;
            ULStat = DaqBoard.AInScan(LowChan, HighChan, NumPoints, ref Rate,
                                      MccDaq.Range.Bip10Volts, MemHandle, Options);
            DaqBoard.GetStatus(out Status, out CurCount,
                               out CurIndex, MccDaq.FunctionType.AiFunction);
            FirstPoint = CurIndex;

            // recently collected data
            int N = FirstPoint + NumChans;

            ushort[] addata = new ushort[N];
            MccDaq.MccService.WinBufToArray(MemHandle, addata, 0, N);

            List <float> channel_data = new List <float>();

            for (int i = 0; i <= HighChan; ++i)
            {
                //sum = 0;
                channel_data.RemoveRange(0, channel_data.Count);
                for (int j = i; j < N; j += NumChans)
                {
                    //sum += addata[j];
                    channel_data.Add(addata[j]);
                }
                // take median voltage value
                channel_data.Sort();
                ADData[i] = channel_data[(Int32)(channel_data.Count / 2)];
                // convert from int to double precision voltage value
                ADData[i] = (ADData[i] - 32768) / (float)3276.8;
            }

            DaqBoard.StopBackground(MccDaq.FunctionType.AiFunction);
            MccDaq.MccService.WinBufFreeEx(MemHandle);
            if (output_fmt == "OD")
            {
                return(convertADtoOD(ADData));
            }
            else
            {
                return(ADData);
            }
        }
        public void startContinuousRead()
        {
            //  per channel sampling rate ((samples per second) per channel)
            MccDaq.ScanOptions Options = MccDaq.ScanOptions.Background
                                         | MccDaq.ScanOptions.Continuous;

            //  collect data in background continuously
            DaqBoard.AInScan(LowChan, HighChan, NumPoints,
                             ref Rate, MccDaq.Range.Bip10Volts, MemHandle, Options);
            tmrContinuousRead.Start();
        }