// 外界只能使用靜態方法取得實例 public new static DrawMaxChart GetInstance() { if (null == instance) { lock (thisLock) { if (null == instance) { instance = new DrawMaxChart(); } } } return(instance); }
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); } }
private void CreateFreqMaxGraph(ZedGraphControl zgc, double[] sectionBuffers) { try { DrawMaxChart DMC = DrawMaxChart.GetInstance(); List <double[]> chart_info = new List <double[]> { }; chart_info = DMC.DrawChart(zgc, sectionBuffers); GraphPane myPane = zgc.GraphPane; // Set the titles and axis labels LineItem myCurve; if (LongTermcheckBox.Checked) { list.Add(chart_info[0], chart_info[1]); // Generate a blue curve with circle symbols, and "My Curve " in the legend myCurve = myPane.AddCurve("Channel 0", list, Color.DarkGreen, SymbolType.Square); myCurve.Line.Width = 3.0f; zgc.AxisChange(); zgc.Refresh(); StreamcheckBox.Checked = false; } else if (StreamcheckBox.Checked) { list.Add(chart_info[0], chart_info[1]); // Generate a blue curve with circle symbols, and "My Curve 2" in the legend myCurve = myPane.AddCurve("Channel 0", list, Color.DarkGreen, SymbolType.Square); myCurve.Line.Width = 3.0f; zgc.AxisChange(); zgc.Refresh(); if (list.Count >= 30) { list.RemoveAt(0); } LongTermcheckBox.Checked = false; } else { MessageBox.Show("chart attribute is null"); 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; } } catch (Exception err) { _log.Error("initial textbox at max chart message is---" + err.Message); MessageBox.Show(err.Message); } }