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; }
public int FindEventsOfType(MccDaq.MccBoard DaqBoard, int EventType) { MccDaq.ErrorInfo ULStat; // check supported features by trial // and error with error handling disabled ULStat = MccDaq.MccService.ErrHandling (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop); TestBoard = DaqBoard; // check support of event handling by trial // and error with error handling disabled int EventsFound = 0; if ((EventType & DCHANGEEVENT) > 0) { ULStat = DaqBoard.DisableEvent(MccDaq.EventType.OnChangeOfDigInput); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { EventsFound = (EventsFound | DCHANGEEVENT); } } if ((EventType & INTEVENT) > 0) { ULStat = DaqBoard.DisableEvent(MccDaq.EventType.OnExternalInterrupt); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { EventsFound = (EventsFound | INTEVENT); } } if ((EventType & ERREVENT) > 0) { ULStat = DaqBoard.DisableEvent(MccDaq.EventType.OnScanError); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { EventsFound = (EventsFound | ERREVENT); } } if ((EventType & DATAEVENT) > 0) { ULStat = DaqBoard.DisableEvent(MccDaq.EventType.OnDataAvailable); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { EventsFound = (EventsFound | DATAEVENT); } } if ((EventType & ENDEVENT) > 0) { ULStat = DaqBoard.DisableEvent(MccDaq.EventType.OnEndOfAiScan); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { EventsFound = (EventsFound | ENDEVENT); } } if ((EventType & PRETRIGEVENT) > 0) { ULStat = DaqBoard.DisableEvent(MccDaq.EventType.OnPretrigger); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { EventsFound = (EventsFound | PRETRIGEVENT); } } if ((EventType & ENDOUTEVENT) > 0) { ULStat = DaqBoard.DisableEvent(MccDaq.EventType.OnEndOfAoScan); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { EventsFound = (EventsFound | ENDOUTEVENT); } } ULStat = MccDaq.MccService.ErrHandling (clsErrorDefs.ReportError, clsErrorDefs.HandleError); return(EventsFound); }