diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index 7d28afb..5a8f006 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,14 +1,9 @@ using System.Collections.Generic; using System.Drawing; -using System.Threading; using System.Windows; using Correlator.Model; -using Correlator.SensorHubTag; using Correlator.Util; using GalaSoft.MvvmLight.Messaging; -using HandyControl.Controls; -using MessageBox = System.Windows.MessageBox; -using Window = System.Windows.Window; namespace Correlator.View { @@ -49,8 +44,9 @@ yDoubles.Add(model.WavePoints[i]); } - RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), - Color.LimeGreen); + RedSensorScottPlotChart.Plot.AddSignalXY( + xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen + ); RedSensorScottPlotChart.Refresh(); } else @@ -67,89 +63,13 @@ yDoubles.Add(model.WavePoints[i]); } - BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), - Color.LimeGreen); + BlueSensorScottPlotChart.Plot.AddSignalXY( + xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen + ); BlueSensorScottPlotChart.Refresh(); } }); }); - - // SensorACheckBox.Click += delegate - // { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } - // - // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - // } - // else - // { - // if (SensorBCheckBox.IsChecked == true) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - // SensorBCheckBox.IsChecked = false; - // } - // - // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - // } - // }; - // - // SensorBCheckBox.Click += delegate - // { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } - // - // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - // } - // else - // { - // if (SensorACheckBox.IsChecked == true) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - // SensorACheckBox.IsChecked = false; - // } - // - // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - // } - // }; - } - - private void SendSoundCollectCmd(object devCode) - { - //音频输出 - PlayWav.Instance.InitWaveOut(); - - Thread.Sleep(3000); - CommandSender.SendSoundCollectCmd(SerialPortManager.Get.Sp, devCode as string); - Growl.Success(DevCode.Dev1.Equals(devCode as string) ? "设备1发送听音指令" : "设备2发送听音指令"); - FlowStatus.IsListening = true; - Thread.Sleep(2000); - - new Thread(ListeningTimer) { IsBackground = true }.Start(); - } - - private void ListeningTimer() - { - while (FlowStatus.IsListening) - { - Thread.Sleep(1000); - if (++FlowStatus.ElapseTime >= 15) - { - MessageBox.Show("接收不到数据,请重启软件", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information); - break; - } - } - - FlowStatus.ElapseTime = 0; } } } \ No newline at end of file diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index 7d28afb..5a8f006 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,14 +1,9 @@ using System.Collections.Generic; using System.Drawing; -using System.Threading; using System.Windows; using Correlator.Model; -using Correlator.SensorHubTag; using Correlator.Util; using GalaSoft.MvvmLight.Messaging; -using HandyControl.Controls; -using MessageBox = System.Windows.MessageBox; -using Window = System.Windows.Window; namespace Correlator.View { @@ -49,8 +44,9 @@ yDoubles.Add(model.WavePoints[i]); } - RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), - Color.LimeGreen); + RedSensorScottPlotChart.Plot.AddSignalXY( + xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen + ); RedSensorScottPlotChart.Refresh(); } else @@ -67,89 +63,13 @@ yDoubles.Add(model.WavePoints[i]); } - BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), - Color.LimeGreen); + BlueSensorScottPlotChart.Plot.AddSignalXY( + xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen + ); BlueSensorScottPlotChart.Refresh(); } }); }); - - // SensorACheckBox.Click += delegate - // { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } - // - // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - // } - // else - // { - // if (SensorBCheckBox.IsChecked == true) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - // SensorBCheckBox.IsChecked = false; - // } - // - // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - // } - // }; - // - // SensorBCheckBox.Click += delegate - // { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } - // - // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - // } - // else - // { - // if (SensorACheckBox.IsChecked == true) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - // SensorACheckBox.IsChecked = false; - // } - // - // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - // } - // }; - } - - private void SendSoundCollectCmd(object devCode) - { - //音频输出 - PlayWav.Instance.InitWaveOut(); - - Thread.Sleep(3000); - CommandSender.SendSoundCollectCmd(SerialPortManager.Get.Sp, devCode as string); - Growl.Success(DevCode.Dev1.Equals(devCode as string) ? "设备1发送听音指令" : "设备2发送听音指令"); - FlowStatus.IsListening = true; - Thread.Sleep(2000); - - new Thread(ListeningTimer) { IsBackground = true }.Start(); - } - - private void ListeningTimer() - { - while (FlowStatus.IsListening) - { - Thread.Sleep(1000); - if (++FlowStatus.ElapseTime >= 15) - { - MessageBox.Show("接收不到数据,请重启软件", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information); - break; - } - } - - FlowStatus.ElapseTime = 0; } } } \ No newline at end of file diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index ae60c81..ac7ddd0 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -102,11 +102,11 @@ ListenAudioButton.Click += delegate { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } + if (!SerialPortManager.Get.Sp.IsOpen) + { + MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } var auditionWindow = new AuditionWindow { diff --git a/Correlator/View/AuditionWindow.xaml.cs b/Correlator/View/AuditionWindow.xaml.cs index 7d28afb..5a8f006 100644 --- a/Correlator/View/AuditionWindow.xaml.cs +++ b/Correlator/View/AuditionWindow.xaml.cs @@ -1,14 +1,9 @@ using System.Collections.Generic; using System.Drawing; -using System.Threading; using System.Windows; using Correlator.Model; -using Correlator.SensorHubTag; using Correlator.Util; using GalaSoft.MvvmLight.Messaging; -using HandyControl.Controls; -using MessageBox = System.Windows.MessageBox; -using Window = System.Windows.Window; namespace Correlator.View { @@ -49,8 +44,9 @@ yDoubles.Add(model.WavePoints[i]); } - RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), - Color.LimeGreen); + RedSensorScottPlotChart.Plot.AddSignalXY( + xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen + ); RedSensorScottPlotChart.Refresh(); } else @@ -67,89 +63,13 @@ yDoubles.Add(model.WavePoints[i]); } - BlueSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), - Color.LimeGreen); + BlueSensorScottPlotChart.Plot.AddSignalXY( + xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen + ); BlueSensorScottPlotChart.Refresh(); } }); }); - - // SensorACheckBox.Click += delegate - // { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } - // - // if (SensorACheckBox.IsChecked == false || SensorACheckBox.IsChecked == null) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - // } - // else - // { - // if (SensorBCheckBox.IsChecked == true) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - // SensorBCheckBox.IsChecked = false; - // } - // - // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev1); - // } - // }; - // - // SensorBCheckBox.Click += delegate - // { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } - // - // if (SensorBCheckBox.IsChecked == false || SensorBCheckBox.IsChecked == null) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev2); - // } - // else - // { - // if (SensorACheckBox.IsChecked == true) - // { - // CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, DevCode.Dev1); - // SensorACheckBox.IsChecked = false; - // } - // - // new Thread(SendSoundCollectCmd) { IsBackground = true }.Start(DevCode.Dev2); - // } - // }; - } - - private void SendSoundCollectCmd(object devCode) - { - //音频输出 - PlayWav.Instance.InitWaveOut(); - - Thread.Sleep(3000); - CommandSender.SendSoundCollectCmd(SerialPortManager.Get.Sp, devCode as string); - Growl.Success(DevCode.Dev1.Equals(devCode as string) ? "设备1发送听音指令" : "设备2发送听音指令"); - FlowStatus.IsListening = true; - Thread.Sleep(2000); - - new Thread(ListeningTimer) { IsBackground = true }.Start(); - } - - private void ListeningTimer() - { - while (FlowStatus.IsListening) - { - Thread.Sleep(1000); - if (++FlowStatus.ElapseTime >= 15) - { - MessageBox.Show("接收不到数据,请重启软件", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information); - break; - } - } - - FlowStatus.ElapseTime = 0; } } } \ No newline at end of file diff --git a/Correlator/View/HomePageProWindow.xaml.cs b/Correlator/View/HomePageProWindow.xaml.cs index ae60c81..ac7ddd0 100644 --- a/Correlator/View/HomePageProWindow.xaml.cs +++ b/Correlator/View/HomePageProWindow.xaml.cs @@ -102,11 +102,11 @@ ListenAudioButton.Click += delegate { - // if (!SerialPortManager.Get.Sp.IsOpen) - // { - // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // return; - // } + if (!SerialPortManager.Get.Sp.IsOpen) + { + MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } var auditionWindow = new AuditionWindow { diff --git a/Correlator/ViewModel/AuditionViewModel.cs b/Correlator/ViewModel/AuditionViewModel.cs index b43b47e..0aa76f1 100644 --- a/Correlator/ViewModel/AuditionViewModel.cs +++ b/Correlator/ViewModel/AuditionViewModel.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using Correlator.Model; +using Correlator.SensorHubTag; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; @@ -105,12 +106,14 @@ /// /// 录音 + /// 波形图暂时采用NAudio录音形成波形图 /// private void RecordAudio() { if (_isStartRecording) { LazyWaveIn.Value.StopRecording(); + CommandSender.SendSoundStopCmd(SerialPortManager.Get.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); } else { @@ -120,6 +123,7 @@ ); LazyWaveIn.Value.StartRecording(); + CommandSender.SendSoundCollectCmd(SerialPortManager.Get.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); } }