private void cmdStart_Click(object eventSender, System.EventArgs eventArgs) /* Handles cmdStart.Click */ { cmdStart.Enabled = false; // Select the trigger source using Mccdaq.MccBoard.SetTrigger() // Parameters: // TrigType :the type of triggering based on external trigger source // LowThreshold :Low threshold when the trigger input is analog // HighThreshold :High threshold when the trigger input is analog float highVal = 1.0F; MccDaq.Range Range = MccDaq.Range.Bip10Volts; // analog trigger range ushort HighThreshold = 0; MccDaq.ErrorInfo ULStat = DaqBoard.FromEngUnits(Range, highVal, out HighThreshold); float lowVal = 0.1F; ushort LowThreshold = 0; ULStat = DaqBoard.FromEngUnits(Range, lowVal, out LowThreshold); MccDaq.TriggerType TrigType = MccDaq.TriggerType.TrigAbove; ULStat = DaqBoard.SetTrigger(TrigType, LowThreshold, HighThreshold); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { // Collect the values with 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 int LowChan = 0; // first channel to acquire HighChan = int.Parse(txtHighChan.Text); // last channel to acquire if (HighChan > 7) { HighChan = 7; } txtHighChan.Text = HighChan.ToString(); int Count = NumPoints; // total number of data points to collect int Rate = 390; // per channel sampling rate ((samples per second) per channel) Range = MccDaq.Range.Bip5Volts; // set the range MccDaq.ScanOptions Options = MccDaq.ScanOptions.ConvertData // return data as 12-bit values | MccDaq.ScanOptions.ExtTrigger; ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.BadRange) { MessageBox.Show("Change the Range argument to one supported by this board.", "Unsupported Range", 0); } // Transfer the data from the memory buffer set up by Windows to an array ULStat = MccDaq.MccService.WinBufToArray(MemHandle, out ADData[0], FirstPoint, Count); for (int i = 0; i <= HighChan; ++i) { lblADData[i].Text = ADData[i].ToString("0"); } for (int j = HighChan + 1; j <= 7; ++j) { lblADData[j].Text = ""; } } cmdStart.Enabled = true; }
public int FindAnalogChansOfType(MccDaq.MccBoard DaqBoard, int AnalogType, out int Resolution, out MccDaq.Range DefaultRange, out int DefaultChan, out MccDaq.TriggerType DefaultTrig) { int ChansFound, IOType; MccDaq.ErrorInfo ULStat; bool CheckPretrig, CheckATrig = false; MccDaq.Range TestRange; bool RangeFound; // check supported features by trial // and error with error handling disabled ULStat = MccDaq.MccService.ErrHandling (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop); TestBoard = DaqBoard; ATrigRes = 0; DefaultChan = 0; DefaultTrig = TriggerType.TrigPosEdge; DefaultRange = Range.NotUsed; Resolution = 0; IOType = (AnalogType & 3); switch (IOType) { case ANALOGINPUT: // Get the number of A/D channels ULStat = DaqBoard.BoardConfig.GetNumAdChans(out ChansFound); if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)) { clsErrorDefs.DisplayError(ULStat); return(ChansFound); } if (ChansFound > 0) { // Get the resolution of A/D ULStat = DaqBoard.BoardConfig.GetAdResolution(out ADRes); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { Resolution = ADRes; } // check ranges for a valid default RangeFound = TestInputRanges(out TestRange); if (RangeFound) { DefaultRange = TestRange; } } break; default: // Get the number of D/A channels ULStat = DaqBoard.BoardConfig.GetNumDaChans(out ChansFound); if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)) { clsErrorDefs.DisplayError(ULStat); return(ChansFound); } if (ChansFound > 0) { ULStat = TestBoard.GetConfig(2, 0, 292, out DARes); Resolution = DARes; RangeFound = TestOutputRanges(out TestRange); if (RangeFound) { DefaultRange = TestRange; } } break; } CheckATrig = ((AnalogType & ATRIGIN) == ATRIGIN); if ((ChansFound > 0) & CheckATrig) { ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigAbove, 0, 0); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { DefaultTrig = MccDaq.TriggerType.TrigAbove; GetTrigResolution(); } else { ChansFound = 0; } } CheckPretrig = ((AnalogType & PRETRIGIN) == PRETRIGIN); if ((ChansFound > 0) & CheckPretrig) { // if DaqSetTrigger supported, trigger type is analog ULStat = DaqBoard.DaqSetTrigger(MccDaq.TriggerSource.TrigImmediate, MccDaq.TriggerSensitivity.AboveLevel, 0, MccDaq.ChannelType.Analog, DefaultRange, 0.0F, 0.1F, MccDaq.TriggerEvent.Start); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { DefaultTrig = MccDaq.TriggerType.TrigAbove; } else { ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigPosEdge, 0, 0); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { DefaultTrig = MccDaq.TriggerType.TrigPosEdge; } else { ChansFound = 0; } } } ULStat = MccDaq.MccService.ErrHandling (clsErrorDefs.ReportError, clsErrorDefs.HandleError); return(ChansFound); }