Beispiel #1
0
        public static void MyCallback(int bd, MccDaq.EventType et, uint sampleCount, IntPtr pUserData)
        {
            //MyCallback is a static member function. So, we must do some work to get the reference
            // to this object. Recall that we passed in a pointer to a struct that wrapped the
            // class reference as UserData.

            TUserData       userStruct = (TUserData)Marshal.PtrToStructure(pUserData, typeof(TUserData));
            frmEventDisplay ThisObj    = (frmEventDisplay)userStruct.ThisObj;

            //Calculate the index of the latest sample in the buffer.
            int sampleIdx = ((int)sampleCount - 1) % ThisObj.TotalCount;

            ushort[] rawData   = new ushort[1];
            uint[]   rawData32 = new uint[1];

            float  voltData;
            double highResVoltData;

            ThisObj.lblSampleCount.Text = sampleCount.ToString();

            //Retrieve the latest sample and convert it to engineering units.
            if (ThisObj.ADResolution > 16)
            {
                MccDaq.MccService.WinBufToArray32(ThisObj.MemHandle, rawData32, (int)sampleIdx, 1);
                ThisObj.DaqBoard.ToEngUnits32(ThisObj.Range, rawData32[0], out highResVoltData);
                ThisObj.lblLatestSample.Text = highResVoltData.ToString("F5") + " V";
            }
            else
            {
                MccDaq.MccService.WinBufToArray(ThisObj.MemHandle, rawData, (int)sampleIdx, 1);
                ThisObj.DaqBoard.ToEngUnits(ThisObj.Range, rawData[0], out voltData);
                ThisObj.lblLatestSample.Text = voltData.ToString("F4") + " V";
            }

            if (et == MccDaq.EventType.OnEndOfAiScan)
            {
                // If the event is the end of acquisition, release the
                // resources in preparation for the next scan.
                ThisObj.DaqBoard.StopBackground(MccDaq.FunctionType.AiFunction);

                if (ThisObj.chkAutoRestart.Checked)
                {
                    int rate = ThisObj.DesiredRate;

                    ThisObj.DaqBoard.AInScan(0, 0, ThisObj.TotalCount, ref rate,
                                             ThisObj.Range, ThisObj.MemHandle, ThisObj.Options);
                }
                else
                {
                    ThisObj.lblStatus.Text   = "IDLE";
                    ThisObj.cmdStart.Enabled = true;
                }
            }
        }
Beispiel #2
0
        private void cmdEnableEvent_Click(object sender, System.EventArgs e)
        {
            /// Enable and connect one or more event types to a single user callback
            /// function using MccDaq.MccBoard.EnableEvent().
            ///
            /// If we want to attach a single callback function to more than one event
            /// type, we can do it in a single call to MccDaq.MccBoard.EnableEvent, or we can do this in
            /// separate calls for each event type. The main disadvantage of doing this in a
            /// single call is that if the call generates an error, we will not know which
            /// event type caused the error. In addition, the same error condition could
            /// generate multiple error messages.
            ///
            /// Parameters:
            ///   eventType   :the condition that will cause an event to fire
            ///   eventSize   :only used for MccDaq.EventType.OnDataAvailable to determine how
            ///               many samples to collect before firing an event
            ///   _ptrMyCallback : a pointer to the user function or event handler
            ///                     to call when above event type occurs. Note that the handler
            ///						can be a delegate or a static member function. Here, we use
            ///						a pointer to a static member function.
            ///
            ///   _ptrUserData  : a pointer to a value type that will be used within the event
            ///					   handler. Since our handler is a static member function which
            ///					   does NOT include a reference to this class instance, we're
            ///					   sending the pointer to a struct that holds a reference to the class.

            uint eventSize = 0;

            MccDaq.EventType eventType = MccDaq.EventType.OnEndOfAiScan;
            MccDaq.ErrorInfo ULStat    =
                DaqBoard.EnableEvent(eventType, eventSize, _ptrMyCallback, _ptrUserData);

            bool ValidEntry = uint.TryParse(txtEventSize.Text, out eventSize);

            eventType = MccDaq.EventType.OnDataAvailable;
            if (ValidEntry)
            {
                ULStat = DaqBoard.EnableEvent
                             (eventType, eventSize, _ptrMyCallback, _ptrUserData);
            }
            else
            {
                ULStat = DaqBoard.DisableEvent(eventType);
            }

            eventType = MccDaq.EventType.OnScanError;
            ULStat    = DaqBoard.EnableEvent(eventType, 0, _ptrOnScanError, _ptrUserData);

            cmdEnableEvent.Enabled = false;
        }
Beispiel #3
0
        public static void OnScanError(int bd, MccDaq.EventType et, uint scanError, IntPtr pdata)
        {
            //OnScanError is a static member function. So, we must do some work to get the reference
            // to this object. Recall that we passed in a pointer to a struct that wrapped the
            // class reference as UserData...
            TUserData       thisStruct = (TUserData)Marshal.PtrToStructure(pdata, typeof(TUserData));
            frmEventDisplay ThisObj    = (frmEventDisplay)thisStruct.ThisObj;

            ThisObj.DaqBoard.StopBackground(MccDaq.FunctionType.AiFunction);

            // Reset the chkAutoRestart such that the 'OnEndOfAiScan' event does
            //not automatically start a new scan
            ThisObj.chkAutoRestart.Checked = false;
        }