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 { public partial class AuditionWindow : Window { public AuditionWindow() { InitializeComponent(); //去掉四周坐标轴 RedSensorScottPlotChart.Plot.XAxis.IsVisible = false; RedSensorScottPlotChart.Plot.XAxis2.IsVisible = false; RedSensorScottPlotChart.Plot.YAxis.IsVisible = false; RedSensorScottPlotChart.Plot.YAxis2.IsVisible = false; BlueSensorScottPlotChart.Plot.XAxis.IsVisible = false; BlueSensorScottPlotChart.Plot.XAxis2.IsVisible = false; BlueSensorScottPlotChart.Plot.YAxis.IsVisible = false; BlueSensorScottPlotChart.Plot.YAxis2.IsVisible = false; GoBackButton.Click += delegate { Close(); }; Messenger.Default.Register(this, MessengerToken.RenderAudioOscillogram, delegate(AudioWaveModel model) { Application.Current.Dispatcher.Invoke(delegate { if (model.IsRedSensor) { RedSensorScottPlotChart.Plot.Clear(); RedSensorScottPlotChart.Refresh(); var xDoubles = new List<double>(); var yDoubles = new List<double>(); for (var i = 0; i < model.WavePoints.Length; i++) { xDoubles.Add(i); yDoubles.Add(model.WavePoints[i]); } RedSensorScottPlotChart.Plot.AddSignalXY(xDoubles.ToArray(), yDoubles.ToArray(), Color.LimeGreen); RedSensorScottPlotChart.Refresh(); } else { BlueSensorScottPlotChart.Plot.Clear(); BlueSensorScottPlotChart.Refresh(); var xDoubles = new List<double>(); var yDoubles = new List<double>(); for (var i = 0; i < model.WavePoints.Length; i++) { xDoubles.Add(i); yDoubles.Add(model.WavePoints[i]); } 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; } } }