Exemple #1
0
        /// <summary>
        /// 设置模拟输入模式
        /// </summary>
        /// <param name="e">事件入口</param>
        /// <param name="timers">检测时间(秒)</param>
        /// <param name="isAutoReset">是否循环获取</param>
        public void StartAiMode(DAQNaviHelper.DelegateAiEvent e, double timers = 1, bool isAutoReset = false)
        {
            try
            {
                aiModeData = new AiModeType();
                EventAi    = e;
                numTimeAi  = (timers > 0.3) ? Convert.ToInt32(timers * 1000) : 300;
                queueAiData.Clear();

                timerAi.Interval  = numTimeAi;
                timerAi.AutoReset = isAutoReset;
                timerAi.Enabled   = true;

                ErrorCode err = waveformAiCtrlUsb4704.Prepare();
                if (err == ErrorCode.Success)
                {
                    err = waveformAiCtrlUsb4704.Start();
                }
                if (err != ErrorCode.Success)
                {
                    ActiveEventError("设置模拟输入功能开启失败:" + err.ToString());
                    return;
                }
            }
            catch (Exception error)
            {
                ActiveEventError("设置模拟输入模式失败:" + error.Message);
            }
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                deviceDescription = DeviceIDtextBox.Text;
                // Step 3: Select a device by device number or device description and specify the access mode.
                // in this example we use ModeWrite mode so that we can fully control the device, including configuring, sampling, etc.
                waveformAiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
                //errorCode = waveformAiCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device.
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }

                convertClkRate = int.Parse(SamplingTextbox.Text);
                sectionLength  = int.Parse(DataLengthtextBox.Text);
                startChannel   = int.Parse(ChanneltextBox.Text);
                // Step 4: Set necessary parameter
                Conversion conversion = waveformAiCtrl.Conversion;
                conversion.ChannelStart = startChannel;
                conversion.ChannelCount = channelCount;
                conversion.ClockRate    = convertClkRate;
                Record record = waveformAiCtrl.Record;
                record.SectionCount  = sectionCount;//The 0 means setting 'streaming' mode.
                record.SectionLength = sectionLength;

                // Step 5: prepare the Streaming AI.
                errorCode = waveformAiCtrl.Prepare();
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }

                // Step 6: The operation has been started
                // We can get samples via event handlers.
                errorCode = waveformAiCtrl.Start();
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                Console.WriteLine(" StreamingAI is in progress... any key to quit !\n");

                // Step 7: The device is acquiring data.

                // step 8: Stop the operation if it is running.
                SamplingTextbox.Enabled   = false;
                DataLengthtextBox.Enabled = false;
                ChanneltextBox.Enabled    = false;
                FreqrangetextBox.Enabled  = false;
                DeviceIDtextBox.Enabled   = false;
                FreqMintextBox.Enabled    = false;
                FreqMaxtextBox.Enabled    = false;
                button2.Enabled           = false;
                button3.Enabled           = true;
            }
            catch (Exception err)
            {
                // If something wrong in this execution, print the error code on screen for tracking.
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                        : err.Message;
                MessageBox.Show(errStr);
            }
        }
Exemple #3
0
        private void StartAcquisitionBtn_Click(object sender, EventArgs e)
        {
            try
            {
                _log.Info("Starts to Data acquisition.");
                string deviceDescription = DeviceIDtextBox.Text;
                waveformAiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);

                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                string DAQinputrange   = InputrangecomboBox.Text;
                string DAQaisignaltype = ConnecttypecomboBox.Text;
                string DAQCoupletype   = CoupletypecomboBox.Text;
                convertClkRate = int.Parse(SamplingTextbox.Text);
                int sectionLength = int.Parse(DataLengthtextBox.Text);
                int startChannel  = int.Parse(ChanneltextBox.Text);
                int Freqrange     = int.Parse(FreqrangetextBox.Text);
                int Minxlength    = int.Parse(FreqMintextBox.Text);
                int Maxxlength    = int.Parse(FreqMaxtextBox.Text);
                lowcutoff  = int.Parse(Lowcutoffbox.Text);
                highcutoff = int.Parse(highcutoffbox.Text);
                //Load parameter
                Conversion conversion = waveformAiCtrl.Conversion;
                conversion.ChannelStart = startChannel;
                conversion.ChannelCount = channelCount;
                conversion.ClockRate    = convertClkRate;
                Record record = waveformAiCtrl.Record;
                record.SectionCount  = sectionCount;// 'streaming' mode.
                record.SectionLength = sectionLength;
                //initial Draw parameter
                DrawClass DC = DrawClass.GetInstance();
                DC.Sampling = convertClkRate;
                DrawFFTChart DFC = DrawFFTChart.GetInstance();
                DFC.DataLength = sectionLength;
                DFC.Freqrange  = Freqrange;
                DFC.FreqMax    = Maxxlength;
                DFC.FreqMin    = Minxlength;
                DFC.Sampling   = convertClkRate;
                DrawMaxChart DMC = DrawMaxChart.GetInstance();
                DMC.DataLength = sectionLength;
                DMC.Freqrange  = Freqrange;
                DMC.FreqMax    = Maxxlength;
                DMC.FreqMin    = Minxlength;
                DMC.Sampling   = convertClkRate;
                try
                {
                    _log.Info("Load DAQ parameter");
                    //mapping inputrange - 5 to 5 V // -10 to 10 V // -1 to 1 V // 4 to 20 mA
                    switch (DAQinputrange)
                    {
                    case "-1 to 1 V":
                        inputrange = ValueRange.V_Neg1To1;
                        break;

                    case "-1.25 to 1.25 V":
                        inputrange = ValueRange.V_Neg1pt25To1pt25;
                        break;

                    case "-5 to 5 V":
                        inputrange = ValueRange.V_Neg5To5;
                        break;

                    case "-10 to 10 V":
                        inputrange = ValueRange.V_Neg10To10;
                        break;

                    case "4 to 20 mA":
                        inputrange = ValueRange.mA_4To20;
                        break;

                    default:
                        break;
                    }

                    //mapping DAQ Signal Type // Differential // SingleEnded
                    switch (DAQaisignaltype)
                    {
                    case "Differential":
                        aisignaltype = AiSignalType.Differential;
                        break;

                    case "PsuedoDifferential":
                        aisignaltype = AiSignalType.PseudoDifferential;
                        break;

                    case "SingleEnded":
                        aisignaltype = AiSignalType.SingleEnded;
                        break;

                    default:
                        break;
                    }

                    switch (DAQCoupletype)
                    {
                    case "ACCouple":
                        coupletype = CouplingType.ACCoupling;
                        break;

                    case "DCCouple":
                        coupletype = CouplingType.DCCoupling;
                        break;

                    default:
                        break;
                    }


                    foreach (AnalogInputChannel ai in waveformAiCtrl.Channels)
                    {
                        if (DAQCoupletype != "None")
                        {
                            try
                            {
                                ai.CouplingType = coupletype;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("This DAQ do not support AC/DC Couple" + ex);
                            }
                        }
                        ai.ValueRange = inputrange;
                        ai.SignalType = aisignaltype;
                        if (IEPEcheckbox.Checked == true)
                        {
                            ai.IepeType = IepeType.IEPE4mA;
                        }
                    }
                }
                catch (Exception err)
                {
                    _log.Error("Faile to Load DAQ parameter message is---" + err.Message);
                }

                // prepare the Streaming AI.
                errorCode = waveformAiCtrl.Prepare();
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }

                // The operation has been started
                // We can get samples via event handlers.
                errorCode = waveformAiCtrl.Start();
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }

                // The device is acquiring data.

                // Stop the operation if it is running.
                SamplingTextbox.Enabled     = false;
                DataLengthtextBox.Enabled   = false;
                ChanneltextBox.Enabled      = false;
                FreqrangetextBox.Enabled    = false;
                DeviceIDtextBox.Enabled     = false;
                FreqMintextBox.Enabled      = false;
                FreqMaxtextBox.Enabled      = false;
                StartAcquisitionBtn.Enabled = false;
                StopAcquisitionBtn.Enabled  = true;
                acquisitionstatus.Text      = "Status : Start reading";
                acquisitionbar.Style        = System.Windows.Forms.ProgressBarStyle.Marquee;
                _log.Info("Start Data Collection");
            }
            catch (Exception err)
            {
                errorCode = waveformAiCtrl.Stop();
                if (BioFailed(errorCode))
                {
                    throw new Exception();
                }
                waveformAiCtrl.Dispose();
                SamplingTextbox.Enabled     = true;
                DataLengthtextBox.Enabled   = true;
                ChanneltextBox.Enabled      = true;
                FreqrangetextBox.Enabled    = true;
                DeviceIDtextBox.Enabled     = true;
                FreqMintextBox.Enabled      = true;
                FreqMaxtextBox.Enabled      = true;
                StartAcquisitionBtn.Enabled = true;
                StopAcquisitionBtn.Enabled  = false;
                acquisitionstatus.Text      = "Status : Stop";
                acquisitionbar.Style        = System.Windows.Forms.ProgressBarStyle.Blocks;
                _log.Error("Start acquisition failed---" + err.Message);
                // If something wrong in this execution, print the error code on screen for tracking.
                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
                                                        : err.Message;
                MessageBox.Show(errStr);
            }
        }