private void CreateTimeGraph(ZedGraphControl zgc, double[] sectionBuffers) { try { DrawClass DC = DrawClass.GetInstance(); List <double[]> excel_Info = new List <double[]> { }; excel_Info = DC.DrawChart(zgc, sectionBuffers); if (SavecheckBox.Checked) { _log.Info("Start store raw data"); sd.CreateExcelFile(excel_Info[0], excel_Info[1], sectionBuffers); } } catch (Exception err) { waveformAiCtrl.Stop(); _log.Error("Time domain calculate or drawing Error message is---" + err.Message); MessageBox.Show(err.Message); 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; } }
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); } }