示例#1
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;
        }