private void cmdStart_Click(object eventSender, System.EventArgs eventArgs) { MccDaq.ErrorInfo ULStat; int Rate; int Count; int FirstCtr; MccDaq.ScanOptions Options; MccDaq.CounterMode Mode; MccDaq.CounterDebounceTime DebounceTime; MccDaq.CounterDebounceMode DebounceMode; MccDaq.CounterEdgeDetection EdgeDetection; MccDaq.CounterTickSize TickSize; int MappedChannel; cmdStart.Enabled = false; FirstCtr = 0; // first channel to acquire LastCtr = 0; // Setup Counter 0 // Parameters: // BoardNum :the number used by CB.CFG to describe this board // CounterNum :counter to set up // Mode :counter Mode // DebounceTime :debounce Time // DebounceMode :debounce Mode // EdgeDetection :determines whether the rising edge or falling edge is to be detected // TickSize :reserved. // MappedChannel :mapped channel // Counter 0 Mode = MccDaq.CounterMode.Encoder | MccDaq.CounterMode.EncoderModeX1 | MccDaq.CounterMode.ClearOnZOn; DebounceTime = MccDaq.CounterDebounceTime.DebounceNone; DebounceMode = 0; EdgeDetection = MccDaq.CounterEdgeDetection.RisingEdge; TickSize = 0; MappedChannel = 2; ULStat = DaqBoard.CConfigScan(CounterNum, Mode, DebounceTime, DebounceMode, EdgeDetection, TickSize, MappedChannel); // Collect the values by calling MccDaq.MccBoard.CInScan function // Parameters: // FirstCtr :the first counter of the scan // LastCtr :the last counter of the scan // Count :the total number of counter samples to collect // Rate :sample rate // MemHandle :Handle for Windows buffer to store data in // Options :data collection options Count = NumPoints; // total number of data points to collect Rate = 10; // per channel sampling rate ((samples per second) per channel) Options = MccDaq.ScanOptions.Ctr32Bit; ULStat = DaqBoard.CInScan(FirstCtr, LastCtr, Count, ref Rate, MemHandle, Options); // Transfer the data from the memory buffer set up by Windows to an array ULStat = MccDaq.MccService.WinBufToArray32(MemHandle, CounterData, FirstPoint, Count); string NL = Environment.NewLine; txtEncoderValues.Text = " Counter Data" + NL + NL; for (int sample = 0; sample < Count; sample++) { txtEncoderValues.Text += CounterData[sample].ToString("d").PadLeft(6) + NL; } cmdStart.Enabled = true; }
private void frmStatusDisplay_Load(System.Object eventSender, System.EventArgs eventArgs) { int NumCntrs, NumPorts, CounterNum; int FirstBit; int ProgAbility = 0; int NumBits = 0; MccDaq.DigitalPortType PortNum = DigitalPortType.AuxPort; MccDaq.DigitalPortDirection Direction; MccDaq.ErrorInfo ULStat; MccDaq.TriggerType DefaultTrig; InitUL(); NumCntrs = 0; NumPorts = 0; // determine the number of analog, digital, and counter channels and their capabilities int ChannelType = clsAnalogIO.ANALOGINPUT; NumAIChans = AIOProps.FindAnalogChansOfType(DaqBoard, ChannelType, out ADResolution, out Range, out LowChan, out DefaultTrig); ChannelType = DigitalIO.clsDigitalIO.PORTIN; if (!clsErrorDefs.GeneralError) { NumPorts = DioProps.FindPortsOfType(DaqBoard, ChannelType, out ProgAbility, out PortNum, out NumBits, out FirstBit); } ChannelType = clsCounters.CTRSCAN; if (!clsErrorDefs.GeneralError) { NumCntrs = CtrProps.FindCountersOfType(DaqBoard, ChannelType, out CounterNum); } if (NumCntrs == 0) { lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() + " has no counter devices."; cmdStartBgnd.Enabled = false; } else if (NumAIChans == 0) { lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() + " does not have analog input channels."; cmdStartBgnd.Enabled = false; } else if (NumPorts == 0) { lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() + " has no digital devices."; cmdStartBgnd.Enabled = false; } else { cmdStartBgnd.Enabled = true; ADData = new ushort[NumElements]; ChanArray = new short[ChanCount]; ChanTypeArray = new MccDaq.ChannelType[ChanCount]; GainArray = new MccDaq.Range[ChanCount]; MemHandle = MccDaq.MccService.WinBufAllocEx(NumElements); if (MemHandle == IntPtr.Zero) { this.cmdStartBgnd.Enabled = false; NumAIChans = 0; } //load the arrays with values ChanArray[0] = 0; ChanTypeArray[0] = MccDaq.ChannelType.Analog; GainArray[0] = Range; ChanArray[1] = System.Convert.ToInt16(PortNum); ChanTypeArray[1] = MccDaq.ChannelType.Digital8; if (NumBits == 16) { ChanTypeArray[1] = MccDaq.ChannelType.Digital16; } GainArray[1] = MccDaq.Range.NotUsed; ChanArray[2] = 0; ChanTypeArray[2] = MccDaq.ChannelType.Ctr32Low; GainArray[2] = MccDaq.Range.NotUsed; ChanArray[3] = 0; ChanTypeArray[3] = MccDaq.ChannelType.Ctr32High; GainArray[3] = MccDaq.Range.NotUsed; if (ProgAbility == -1) { //configure programmable port for digital input Direction = MccDaq.DigitalPortDirection.DigitalIn; ULStat = DaqBoard.DConfigPort(PortNum, Direction); } ULStat = DaqBoard.CConfigScan(0, MccDaq.CounterMode.Bit16, MccDaq.CounterDebounceTime.DebounceNone, MccDaq.CounterDebounceMode.TriggerAfterStable, MccDaq.CounterEdgeDetection.FallingEdge, MccDaq.CounterTickSize.Tick20833pt3ns, 0); lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() + " collecting analog, digital, and counter data " + " using DaqInScan with Range set to " + Range.ToString() + "."; } }
private void cmdStart_Click(object eventSender, System.EventArgs eventArgs) { int i; MccDaq.ErrorInfo ULStat; int Rate; int Count; int FirstCtr; MccDaq.ScanOptions Options; int CounterNum; MccDaq.CounterMode Mode; MccDaq.CounterDebounceTime DebounceTime; MccDaq.CounterDebounceMode DebounceMode; MccDaq.CounterEdgeDetection EdgeDetection; MccDaq.CounterTickSize TickSize; int MapCounter; cmdStart.Enabled = false; FirstCtr = 0; // first channel to acquire LastCtr = 0; // Setup Counter 0 for decrement mode mapped in from counter 1 // Parameters: // BoardNum :the number used by CB.CFG to describe this board // CounterNum :counter to set up // Mode :counter Mode // DebounceTime :debounce Time // DebounceMode :debounce Mode // EdgeDetection :determines whether the rising edge or falling edge is to be detected // TickSize :reserved. // MapCounter :mapped counter CounterNum = FirstCtr; Mode = MccDaq.CounterMode.DecrementOn; DebounceTime = MccDaq.CounterDebounceTime.DebounceNone; DebounceMode = 0; EdgeDetection = MccDaq.CounterEdgeDetection.FallingEdge; TickSize = 0; MapCounter = 1; ULStat = DaqBoard.CConfigScan(CounterNum, Mode, DebounceTime, DebounceMode, EdgeDetection, TickSize, MapCounter); // Collect the values by calling MccDaq.MccBoard.CInScan function // Parameters: // FirstCtr :the first counter of the scan // LastCtr :the last counter of the scan // Count :the total number of counter samples to collect // Rate :sample rate // MemHandle :Handle for Windows buffer to store data in // Options :data collection options Count = NumPoints; // total number of data points to collect Rate = 390; // per channel sampling rate ((samples per second) per channel) Options = MccDaq.ScanOptions.Ctr32Bit; ULStat = DaqBoard.CInScan(FirstCtr, LastCtr, Count, ref Rate, MemHandle, Options); // Transfer the data from the memory buffer set up by Windows to an array ULStat = MccDaq.MccService.WinBufToArray32(MemHandle, CounterData, FirstPoint, Count); for (i = 0; i <= 4; ++i) { lblCounterData[i].Text = CounterData[i].ToString("D"); } cmdStart.Enabled = true; }