Exemple #1
0
        private void cmdStartBgnd_Click(object eventSender, System.EventArgs eventArgs)
        {
            int   CurIndex;
            int   CurCount;
            short Status;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.ScanOptions Options;
            int  Rate;
            int  Count;
            bool ValidChan;

            cmdStartBgnd.Enabled   = false;
            cmdStartBgnd.Visible   = false;
            cmdStopConvert.Enabled = true;
            cmdStopConvert.Visible = true;
            cmdQuit.Enabled        = false;

            //  Collect the values by calling MccDaq.MccBoard.AInScan
            //   Parameters:
            //     LowChan    :the first channel of the scan
            //     HighChan   :the last channel of the scan
            //     Count      :the total number of A/D samples to collect
            //     Rate       :sample rate
            //     Range      :the range for the board
            //     MemHandle  :Handle for Windows buffer to store data in
            //     Options    :data collection options

            ValidChan = int.TryParse(txtHighChan.Text, out HighChan);
            if (ValidChan)
            {
                if (HighChan > MaxChan)
                {
                    HighChan = MaxChan;
                }
                txtHighChan.Text = HighChan.ToString();
            }

            Count = NumPoints;     //  total number of data points to collect

            //  per channel sampling rate ((samples per second) per channel)
            Rate    = 1000 / ((HighChan - LowChan) + 1);
            Options = MccDaq.ScanOptions.Background
                      | MccDaq.ScanOptions.Continuous;

            //  collect data in background continuously
            ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);

            ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.AiFunction);

            if (Status == MccDaq.MccBoard.Running)
            {
                lblShowStat.Text  = "Running";
                lblShowCount.Text = CurCount.ToString("D");
                lblShowIndex.Text = CurIndex.ToString("D");
            }

            tmrCheckStatus.Enabled = true;
        }
        private void cmdStartBgnd_Click(System.Object eventSender, System.EventArgs eventArgs)
        {
            int   CurIndex;
            int   CurCount;
            short Status;

            MccDaq.ErrorInfo ULStat;
            int Rate;

            MccDaq.ScanOptions Options;
            int Count;
            int PretrigCount;

            cmdStartBgnd.Enabled   = false;
            cmdStartBgnd.Visible   = false;
            cmdStopConvert.Enabled = true;
            cmdStopConvert.Visible = true;
            cmdQuit.Enabled        = false;
            UserTerm = 0;             // initialize user terminate flag

            // Collect the values with cbDaqInScan()
            //  Parameters:
            //    BoardNum        :the number used by CB.CFG to describe this board
            //    ChanArray[]     :array of channel values
            //    ChanTypeArray[] : array of channel types
            //    GainArray[]     :array of gain values
            //    ChansCount        :the number of elements in the arrays (0=disable queue)
            //    PretrigCount    :number of pre-trigger A/D samples to collect
            //    Count         :the total number of A/D samples to collect
            //    Rate          :sample rate in samples per second
            //    ADData[]        :the array for the collected data values
            //    Options          :data collection options

            PretrigCount = 0;
            Count        = NumElements;      // Number of data points to collect
            Options      = MccDaq.ScanOptions.ConvertData | MccDaq.ScanOptions.Background
                           | MccDaq.ScanOptions.Continuous;
            Rate = 100;             // Acquire data at 100 Hz

            ULStat = DaqBoard.DaqInScan(ChanArray, ChanTypeArray, GainArray, ChanCount,
                                        ref Rate, ref PretrigCount, ref Count, MemHandle, Options);

            ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex,
                                        MccDaq.FunctionType.DaqiFunction);

            if (Status == MccDaq.MccBoard.Running)
            {
                lblShowStat.Text  = "Running";
                lblShowCount.Text = CurCount.ToString("D");
                lblShowIndex.Text = CurIndex.ToString("D");
            }

            tmrCheckStatus.Enabled = true;
        }
Exemple #3
0
        private void tmrCheckStatus_Tick(object eventSender, System.EventArgs eventArgs)         /* Handles tmrCheckStatus.Tick */
        {
            tmrCheckStatus.Stop();

            int   CurIndex;
            int   CurCount;
            short Status;

            MccDaq.ErrorInfo ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.DiFunction);


            lblShowStat.Text  = Status.ToString("0");
            lblShowCount.Text = CurCount.ToString("0");
            lblShowIndex.Text = CurIndex.ToString("0");
            if (Status == MccDaq.MccBoard.Running)
            {
                lblBGStat.Text = "Background operation running";
            }
            else
            {
                lblBGStat.Text = "Background operation idle";
            }

            if ((CurCount == NumPoints || Status == 0) || (Force == 1))
            {
                ULStat = DaqBoard.StopBackground(MccDaq.FunctionType.DiFunction);

                ShowData();
            }
            else
            {
                tmrCheckStatus.Start();
            }
        }
Exemple #4
0
        private void tmrReadStatus_Tick(object eventSender, System.EventArgs eventArgs)         /* Handles tmrReadStatus.Tick */
        {
            int   CurIndex = 0;
            int   CurCount = 0;
            short Status   = 0;

            tmrReadStatus.Stop();

            // Retrieve the status of the acquisition
            //   Parameters:
            //		Status	: current status of the operation, RUNNING or IDLE.
            //		CurCount: the current number of interrupts
            //		CurIndex  : scan index into buffer to the last counter set read
            //		CtrFunction: Counter Function Type for operation
            MccDaq.ErrorInfo ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.CtrFunction);


            // The calculation below requires that NumCntrs accurately reflects the number
            //   of counters onboard whether or not they are enabled or active.
            FirstPoint = 0;
            if (CurIndex > 0)
            {
                FirstPoint = NumCntrs * CurIndex;
            }

            // Transfer latest set of measurements from the buffer into an array
            // Parameters:
            //   MemHandle	: handle to buffer allocated by MccService.WinBufAlloc
            //   DataBuffer	: array to store latest counter values into
            //	 FirstPoint : sample index into buffer of first sample in last set of counter values read
            //   NumCntrs	: total number counters on the device
            ULStat = MccDaq.MccService.WinBufToArray(MemHandle, out DataBuffer[0], FirstPoint, NumCntrs);

            ushort RealCount = 0;
            String IntStatus = "DISABLED";

            for (int i = 0; i <= 4; ++i)
            {
                if (CntrControl[i] == MccDaq.CounterControl.Enabled)
                {
                    IntStatus = "ENABLED ";
                }
                else
                {
                    IntStatus = "DISABLED";
                }

                //  convert type int to type long
                RealCount = DataBuffer[i];

                lblCounterNum[i].Text = (i + 1).ToString("0");
                lblIntStatus[i].Text  = IntStatus;
                lblCount[i].Text      = RealCount.ToString("0");
            }

            lblShowTotal.Text = CurCount.ToString("0");

            tmrReadStatus.Start();
        }
Exemple #5
0
        private void tmrCheckStatus_Tick(object eventSender, System.EventArgs eventArgs)         /* Handles tmrCheckStatus.Tick */
        {
            int j;
            int i;

            MccDaq.ErrorInfo ULStat;
            int   CurIndex;
            int   CurCount;
            short Status;

            tmrCheckStatus.Stop();

            //  Check the current status of the background data collection
            //   Parameters:
            //     Status     :current status of the background data collection
            //     CurCount   :current number of samples collected
            //     CurIndex   :index to the data buffer pointing to the last value transferred
            //    FunctionType: A/D operation (MccDaq.FunctionType.AiFunction)
            //
            //  Transfer the data from the memory buffer set up by Windows
            //  to an array for use by Visual Basic
            ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.AiFunction);



            if (Status == MccDaq.MccBoard.Idle)
            {
                ULStat = DaqBoard.StopBackground(MccDaq.FunctionType.AiFunction);


                ULStat = MccDaq.MccService.WinBufToArray(MemHandle, out ADData[0], FirstPoint, NumPoints);


                for (i = 0; i <= HighChan; ++i)
                {
                    lblADData[i].Text = ADData[i].ToString("D");
                }

                for (j = HighChan + 1; j <= 7; ++j)
                {
                    lblADData[j].Text = "0";
                }

                cmdConvData.Enabled    = true;
                tmrCheckStatus.Enabled = false;
            }
            else
            {
                tmrCheckStatus.Start();
            }
        }
Exemple #6
0
        private void tmrCheckStatus_Tick(object eventSender, System.EventArgs eventArgs)         /* Handles tmrCheckStatus.Tick */
        {
            int   CurIndex;
            int   CurCount;
            short Status;

            tmrCheckStatus.Stop();

            // Check the current status of the background data collection
            //   Parameters:
            //      Status     :current status of the background data collection
            //      CurCount   :current number of samples collected
            //      CurIndex   :index to the data buffer pointing to the last value transferred
            //      FunctionType: A/D operation (MccDaq.FunctionType.AiFunction)
            MccDaq.ErrorInfo ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.AiFunction);



            //  check if the background operation has finished
            if ((Status == MccDaq.MccBoard.Idle) || (UserTerm == 1))
            {
                lblStatus.Text = "Data collection finished.";

                // the background operation must be explicitly stopped
                ULStat = DaqBoard.StopBackground(MccDaq.FunctionType.AiFunction);


                ULStat = MccDaq.MccService.WinBufToArray(MemHandle, out ADData[0], FirstPoint, NumPoints);


                cmdStartConvert.Enabled   = true;
                cmdQuit.Enabled           = true;
                cmdStopBackground.Enabled = false;
                Convert();
            }
            else
            {
                lblStatus.Text = "Background operation in progress.";
                tmrCheckStatus.Start();
            }

            if (UserTerm == 1)
            {
                lblStatus.Text = "Data collection terminated by user.";
                UserTerm       = 0;
            }
        }
        public int FindPortsOfType(MccDaq.MccBoard DaqBoard, int PortType,
                                   out int ProgAbility, out MccDaq.DigitalPortType DefaultPort,
                                   out int DefaultNumBits, out int FirstBit)

        {
            int   ThisType, NumPorts, NumBits;
            int   DefaultDev, InMask, OutMask;
            int   PortsFound, curCount, curIndex;
            short status;
            bool  PortIsCompatible;
            bool  CheckBitProg = false;

            MccDaq.DigitalPortType CurPort;
            MccDaq.FunctionType    DFunction;
            MccDaq.ErrorInfo       ULStat;
            string ConnectionConflict;

            ULStat = MccDaq.MccService.ErrHandling
                         (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop);

            ConnectionConflict = "This network device is in use by another process or user." +
                                 System.Environment.NewLine + System.Environment.NewLine +
                                 "Check for other users on the network and close any applications " +
                                 System.Environment.NewLine +
                                 "(such as Instacal) that may be accessing the network device.";

            DefaultPort    = (MccDaq.DigitalPortType)(-1);
            CurPort        = DefaultPort;
            PortsFound     = 0;
            FirstBit       = 0;
            ProgAbility    = -1;
            DefaultNumBits = 0;
            ULStat         = DaqBoard.BoardConfig.GetDiNumDevs(out NumPorts);
            if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
            {
                clsErrorDefs.DisplayError(ULStat);
                return(PortsFound);
            }

            if ((PortType == BITOUT) || (PortType == BITIN))
            {
                CheckBitProg = true;
            }
            if ((PortType == PORTOUTSCAN) || (PortType == PORTINSCAN))
            {
                if (NumPorts > 0)
                {
                    DFunction = MccDaq.FunctionType.DiFunction;
                    if (PortType == PORTOUTSCAN)
                    {
                        DFunction = MccDaq.FunctionType.DoFunction;
                    }
                    ULStat = DaqBoard.GetStatus(out status, out curCount, out curIndex, DFunction);
                    if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                    {
                        NumPorts = 0;
                    }
                }
                PortType = PortType & (PORTOUT | PORTIN);
            }

            for (int DioDev = 0; DioDev < NumPorts; ++DioDev)
            {
                ProgAbility = -1;
                ULStat      = DaqBoard.DioConfig.GetDInMask(DioDev, out InMask);
                ULStat      = DaqBoard.DioConfig.GetDOutMask(DioDev, out OutMask);
                if ((InMask & OutMask) > 0)
                {
                    ProgAbility = FIXEDPORT;
                }
                ULStat = DaqBoard.DioConfig.GetDevType(DioDev, out ThisType);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    CurPort = (DigitalPortType)Enum.Parse(typeof(DigitalPortType),
                                                          ThisType.ToString());
                }
                if ((DioDev == 0) && (CurPort == MccDaq.DigitalPortType.FirstPortCL))
                {
                    //a few devices (USB-SSR08 for example)
                    //start at FIRSTPORTCL and number the bits
                    //as if FIRSTPORTA and FIRSTPORTB exist for
                    //compatibiliry with older digital peripherals
                    FirstBit = 16;
                }

                //check if port is set for requested direction
                //or can be programmed for requested direction
                PortIsCompatible = false;
                switch (PortType)
                {
                case (PORTOUT):
                    if (OutMask > 0)
                    {
                        PortIsCompatible = true;
                    }
                    break;

                case (PORTIN):
                    if (InMask > 0)
                    {
                        PortIsCompatible = true;
                    }
                    break;

                default:
                    PortIsCompatible = false;
                    break;
                }
                PortType = (PortType & (PORTOUT | PORTIN));
                if (!PortIsCompatible)
                {
                    if (ProgAbility != FIXEDPORT)
                    {
                        MccDaq.DigitalPortDirection ConfigDirection;
                        ConfigDirection = DigitalPortDirection.DigitalOut;
                        if (PortType == PORTIN)
                        {
                            ConfigDirection = DigitalPortDirection.DigitalIn;
                        }
                        if ((CurPort == MccDaq.DigitalPortType.AuxPort) && CheckBitProg)
                        {
                            //if it's an AuxPort, check bit programmability
                            ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort,
                                                         FirstBit, ConfigDirection);
                            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                            {
                                //return port to input mode
                                ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort,
                                                             FirstBit, DigitalPortDirection.DigitalIn);
                                ProgAbility = PROGBIT;
                            }
                            else
                            {
                                if ((ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUseByAnotherProc) ||
                                    (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUse))
                                {
                                    System.Windows.Forms.MessageBox.Show(ConnectionConflict, "Device In Use");
                                    break;
                                }
                            }
                        }
                        if (ProgAbility == -1)
                        {
                            //check port programmability
                            ULStat = DaqBoard.DConfigPort(CurPort, ConfigDirection);
                            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                            {
                                //return port to input mode
                                ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort,
                                                             FirstBit, DigitalPortDirection.DigitalIn);
                                ProgAbility = PROGPORT;
                            }
                            else
                            {
                                if ((ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUseByAnotherProc) ||
                                    (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUse))
                                {
                                    System.Windows.Forms.MessageBox.Show(ConnectionConflict, "Device In Use");
                                    break;
                                }
                            }
                        }
                    }
                    PortIsCompatible = !(ProgAbility == -1);
                }

                if (PortIsCompatible)
                {
                    PortsFound = PortsFound + 1;
                }
                int BitVals, BitWeight;
                int TotalVal, CurBit;
                if (DefaultPort == (MccDaq.DigitalPortType)(-1))
                {
                    ULStat = DaqBoard.DioConfig.GetNumBits(DioDev, out NumBits);
                    if (ProgAbility == FIXEDPORT)
                    {
                        //could have different number of input and output bits
                        CurBit   = 0;
                        TotalVal = 0;
                        BitVals  = OutMask;
                        if (PortType == PORTIN)
                        {
                            BitVals = InMask;
                        }
                        do
                        {
                            BitWeight = (int)Math.Pow(2, CurBit);
                            TotalVal  = BitWeight + TotalVal;
                            CurBit    = CurBit + 1;
                        } while (TotalVal < BitVals);
                        NumBits = CurBit;
                    }
                    DefaultNumBits = NumBits;
                    DefaultDev     = DioDev;
                    DefaultPort    = CurPort;
                }
                if (ProgAbility == PROGBIT)
                {
                    break;
                }
            }
            ULStat = MccDaq.MccService.ErrHandling
                         (clsErrorDefs.ReportError, clsErrorDefs.HandleError);
            return(PortsFound);
        }
Exemple #8
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();
            }
        }
Exemple #9
0
        private void cmdStartBgnd_Click(object eventSender, System.EventArgs eventArgs) /* Handles cmdStartBgnd.Click */
        {
            int   CurIndex;
            int   CurCount;
            short Status;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.Range       Range;
            MccDaq.ScanOptions Options;
            int Rate;
            int Count;
            int LowChan;

            cmdStartBgnd.Enabled   = false;
            cmdStartBgnd.Visible   = false;
            cmdStopConvert.Enabled = true;
            cmdStopConvert.Visible = true;
            cmdQuit.Enabled        = false;
            UserTerm = 0; //  initialize user terminate flag

            //  Collect the values by calling MccDaq.MccBoard.AInScan function
            //   Parameters:
            //     LowChan    :the first channel of the scan
            //     HighChan   :the last channel of the scan
            //     Count      :the total number of A/D samples to collect
            //     Rate       :sample rate
            //     Range      :the range for the board
            //     MemHandle  :Handle for Windows buffer to store data in
            //     Options    :data collection options
            LowChan  = 0;                           //  first channel to acquire
            HighChan = int.Parse(txtHighChan.Text); //  last channel to acquire
            if ((HighChan > 7))
            {
                HighChan = 7;
            }
            txtHighChan.Text = HighChan.ToString();

            Count = NumPoints; //  total number of data points to collect
            Rate  = 390;       //  per channel sampling rate ((samples per second) per channel)

            Options = MccDaq.ScanOptions.ConvertData | MccDaq.ScanOptions.Background | MccDaq.ScanOptions.SingleIo;

            Range = MccDaq.Range.Bip5Volts; //  set the range


            ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);



            ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.AiFunction);



            if (Status == MccDaq.MccBoard.Running)
            {
                lblShowStat.Text  = "Running";
                lblShowCount.Text = CurCount.ToString("D");
                lblShowIndex.Text = CurIndex.ToString("D");
            }

            tmrCheckStatus.Enabled = true;
        }