コード例 #1
0
ファイル: DataAcqBoard.cs プロジェクト: ScottAtUG/EvcProver
        public DataAcqBoard(int boardNumber, DigitalPortType channelType, int channelNumber)
        {
            _ulStatErrorInfo = MccService.ErrHandling(ErrorReporting.PrintAll, ErrorHandling.DontStop);

            _board       = new MccBoard(boardNumber);
            _channelType = channelType;
            _channelNum  = channelNumber;

            _pulseIsCleared = true;
            _log.Info("Initialized DataAcqBoard: {0}, channel type {1}, channel number {2}", boardNumber, channelType, channelNumber);
        }
コード例 #2
0
 private void StopDaq()
 {
     //Stop Daquisition
     _daqBoard.StopBackground(MccDaq.FunctionType.AiFunction);
     //Reset buttons and flag for chart update
     _isReading = false;
     MccService.WinBufFreeEx(_dataPtr);
     CanStart    = true;
     CanStop     = false;
     CanBrowse   = true;
     Status      = "Stopped";
     StatusBrush = Brushes.Red;
 }
コード例 #3
0
        public void init()
        {
            if (_initialized)
            {
                return;
            }

            int wantedBoards = 3;        // We always have three boards, either real or simulated
            int maxMccBoards;

            if (!Simulated)
            {
                MccService.GetRevision(out mccRevNum, out mccVxdRevNum);
                MccService.ErrHandling(MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop);
                maxMccBoards = MccDaq.GlobalConfig.NumBoards;

                // get the real Mcc boards
                for (int i = 0; i < maxMccBoards; i++)
                {
                    int type;

                    MccDaq.MccBoard board = new MccDaq.MccBoard(i);
                    board.BoardConfig.GetBoardType(out type);
                    if (type != 0)
                    {
                        WiseBoards.Add(new WiseBoard(board));
                    }
                }
            }

            // Add simulated boards, as needed
            for (int i = WiseBoards.Count; i < wantedBoards; i++)
            {
                WiseBoards.Add(new WiseBoard(null, i));
            }

            domeboard = WiseBoards.Find(x => x.mccBoard.BoardNum == 0);
            teleboard = WiseBoards.Find(x => x.mccBoard.BoardNum == 1);
            miscboard = WiseBoards.Find(x => x.mccBoard.BoardNum == 2);

            if (computerControlPin == null)
            {
                computerControlPin = new WisePin("CompControl", teleboard, DigitalPortType.SecondPortCH, 0, DigitalPortDirection.DigitalIn);
                computerControlPin.Connect(true);
            }

            _initialized = true;
        }
コード例 #4
0
        private void StartDaq()
        {
            //Insert the range value into the table
            if (CanSelectRange)
            {
                Database.InsertInfoCommand.Parameters.Add(new SQLiteParameter("Resolution", (int)Resolution));
                Database.ExecuteCommand(Database.InsertInfoCommand);
                CanSelectRange = false;
            }

            //Begin Daquisition
            int packetSize = 16;

            _dataPtr = MccService.ScaledWinBufAllocEx(32);
            ScanOptions options = ScanOptions.SingleIo | ScanOptions.Continuous | ScanOptions.Background | ScanOptions.ScaleData;

            if (SamplePeriod > 1000)
            {
                options |= ScanOptions.HighResRate;
            }

            if (DaqBoard.BoardName == "USB-1608G")
            {
                packetSize = 8;
            }

            if (DaqBoard.BoardName == "USB-1408FS")
            {
                MccService.WinBufFreeEx(_dataPtr);
                _dataPtr   = MccService.WinBufAllocEx(4);
                packetSize = 2;
                options    = ScanOptions.SingleIo | ScanOptions.Continuous | ScanOptions.Background;
            }

            _daqBoard.AInScan(0, numChannels, 2 * packetSize, ref _sampleRate, Resolution, _dataPtr, options);
            _isReading = true;
            BeginChartUpdateAsync();

            //Set buttons and status label to Running state
            CanStart    = false;
            CanStop     = true;
            CanBrowse   = false;
            Status      = "Running";
            StatusBrush = Brushes.LimeGreen;
        }
コード例 #5
0
        static void Main(string[] args)
        {
            System.ConsoleKeyInfo cki = new System.ConsoleKeyInfo();
            MccDaq.ErrorInfo      RetVal;

            int  BoardNum       = 0;
            int  DeviceChannels = 0;
            int  Rate           = FREQ;
            bool ReadLower      = true;

            BoardNum = GetBoardNum(DEVICE);

            if (BoardNum == -1)
            {
                Console.WriteLine("No USB-{0} detected!", DEVICE);
                cki = Console.ReadKey();
            }
            else
            {
                MccBoard daq = new MccDaq.MccBoard(BoardNum);

                daq.BoardConfig.GetNumAdChans(out DeviceChannels);

                if (DeviceChannels > 8)
                {
                    Console.WriteLine("Single-Ended Channels");
                }
                else
                {
                    Console.WriteLine("Differentially-Ended Channels");
                }


                IntPtr buffer = MccService.ScaledWinBufAllocEx(BUFFERSIZE);

                if (buffer == IntPtr.Zero)
                {
                    Console.WriteLine("Bad Handle");
                    return;
                }

                short[] chArray = new short[CHANCOUNT]; //configuration array for channel numbers
                Range[] chRange = new Range[CHANCOUNT]; //configuration array for input ranges

                chArray[0] = 0;
                chArray[1] = 1;
                chArray[2] = 2;
                chArray[3] = 3;

                chRange[0] = Range.Bip10Volts;
                chRange[1] = Range.Bip10Volts;
                chRange[2] = Range.Bip10Volts;
                chRange[3] = Range.Bip10Volts;

                RetVal = daq.ALoadQueue(chArray, chRange, CHANCOUNT);
                IsError(RetVal);

                //setup the acquisiton
                RetVal = daq.AInScan(FIRSTCHANNEL,
                                     LASTCHANNEL,
                                     BUFFERSIZE,
                                     ref Rate,
                                     Range.Bip10Volts,
                                     buffer,
                                     ScanOptions.Background | ScanOptions.ScaleData | ScanOptions.Continuous
                                     );
                IsError(RetVal);

                fStream = new StreamWriter(@"C:\Users\Public\Documents\DataFile1608G.asc");
                CreateFileHeaders(chArray); //writes basic info to the beginning of the file

                int   Count = 0;
                int   Index = 0;
                short daqStatus;

                double[] theArray = new double[BUFFERSIZE];



                //Loop until key press
                do
                {
                    RetVal = daq.GetStatus(out daqStatus, out Count, out Index, FunctionType.AiFunction);
                    if ((Index >= HALFBUFFSIZE) & ReadLower) //check for 50% more data
                    {
                        //get lower half of buffer - ScaledWinBufToArray returns engineering units
                        RetVal = MccService.ScaledWinBufToArray(buffer, theArray, 0, HALFBUFFSIZE);
                        IsError(RetVal);

                        DisplayData(theArray, HALFBUFFSIZE / CHANCOUNT);
                        ReadLower = false; //flag that controls the next read
                    }
                    else if ((Index < HALFBUFFSIZE) & !ReadLower)
                    {
                        //get the upper half  - ScaledWinBufToArray returns engineering units
                        RetVal = MccService.ScaledWinBufToArray(buffer, theArray, HALFBUFFSIZE, HALFBUFFSIZE);
                        IsError(RetVal);

                        DisplayData(theArray, HALFBUFFSIZE / CHANCOUNT);
                        ReadLower = true;//flag that controls the next read
                    }
                } while (!Console.KeyAvailable);

                cki = Console.ReadKey();

                //flush any buffered data out to disk
                fStream.Close();

                //stop the  acquisition
                RetVal = daq.StopBackground(FunctionType.AiFunction);

                //free up memory
                MccService.WinBufFreeEx(buffer);

                WaitForKey();
            }
        }
コード例 #6
0
        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;
            }
        }