diff --git a/Correlator/Util/PlayWav.cs b/Correlator/Util/PlayWav.cs index 670f9f5..a3e8825 100644 --- a/Correlator/Util/PlayWav.cs +++ b/Correlator/Util/PlayWav.cs @@ -30,12 +30,14 @@ { try { - var ws = new WaveOutStream(""); + //必须填入文件名,否则ws无法实例化 + var ws = new WaveOutStream("AutoGenerate.txt"); _mFormat = ws.Format; _waveOutStream = ws; } - catch (Exception) + catch (Exception e) { + LogWithConsole.WriteLine(e.Message, "PlayWav"); CloseFile(); } diff --git a/Correlator/Util/PlayWav.cs b/Correlator/Util/PlayWav.cs index 670f9f5..a3e8825 100644 --- a/Correlator/Util/PlayWav.cs +++ b/Correlator/Util/PlayWav.cs @@ -30,12 +30,14 @@ { try { - var ws = new WaveOutStream(""); + //必须填入文件名,否则ws无法实例化 + var ws = new WaveOutStream("AutoGenerate.txt"); _mFormat = ws.Format; _waveOutStream = ws; } - catch (Exception) + catch (Exception e) { + LogWithConsole.WriteLine(e.Message, "PlayWav"); CloseFile(); } diff --git a/Correlator/Util/WaveOut.cs b/Correlator/Util/WaveOut.cs index 91752af..6131836 100644 --- a/Correlator/Util/WaveOut.cs +++ b/Correlator/Util/WaveOut.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -42,8 +41,9 @@ var buf = (WaveOutBuffer)h.Target; buf.OnCompleted(); } - catch (Exception) + catch (Exception e) { + LogWithConsole.WriteLine(e.Message, "WaveOut"); } } @@ -91,9 +91,7 @@ private void GetMemory(string title) { - Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " WaveOut => {0}: {1}, {2}", title, - _mPlaying, _mark); - // Console.WriteLine(@"{0}: {1}, {2}", title, _mPlaying, _mark); + LogWithConsole.WriteLine($"{title}: {_mPlaying}, {_mark}", "WaveOut"); } public bool Play() @@ -115,10 +113,6 @@ { _mPlaying = _mPlayEvent.WaitOne(); } - else - { - //Thread.Sleep(0); - } } private void OnCompleted() @@ -191,9 +185,6 @@ if (_mWaveOut != IntPtr.Zero) WaveOutBase.waveOutReset(_mWaveOut); - //m_Thread.Abort(); - //m_Thread.Join(); - _mFillProc = null; FreeBuffers(); if (_mWaveOut != IntPtr.Zero) diff --git a/Correlator/Util/PlayWav.cs b/Correlator/Util/PlayWav.cs index 670f9f5..a3e8825 100644 --- a/Correlator/Util/PlayWav.cs +++ b/Correlator/Util/PlayWav.cs @@ -30,12 +30,14 @@ { try { - var ws = new WaveOutStream(""); + //必须填入文件名,否则ws无法实例化 + var ws = new WaveOutStream("AutoGenerate.txt"); _mFormat = ws.Format; _waveOutStream = ws; } - catch (Exception) + catch (Exception e) { + LogWithConsole.WriteLine(e.Message, "PlayWav"); CloseFile(); } diff --git a/Correlator/Util/WaveOut.cs b/Correlator/Util/WaveOut.cs index 91752af..6131836 100644 --- a/Correlator/Util/WaveOut.cs +++ b/Correlator/Util/WaveOut.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -42,8 +41,9 @@ var buf = (WaveOutBuffer)h.Target; buf.OnCompleted(); } - catch (Exception) + catch (Exception e) { + LogWithConsole.WriteLine(e.Message, "WaveOut"); } } @@ -91,9 +91,7 @@ private void GetMemory(string title) { - Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " WaveOut => {0}: {1}, {2}", title, - _mPlaying, _mark); - // Console.WriteLine(@"{0}: {1}, {2}", title, _mPlaying, _mark); + LogWithConsole.WriteLine($"{title}: {_mPlaying}, {_mark}", "WaveOut"); } public bool Play() @@ -115,10 +113,6 @@ { _mPlaying = _mPlayEvent.WaitOne(); } - else - { - //Thread.Sleep(0); - } } private void OnCompleted() @@ -191,9 +185,6 @@ if (_mWaveOut != IntPtr.Zero) WaveOutBase.waveOutReset(_mWaveOut); - //m_Thread.Abort(); - //m_Thread.Join(); - _mFillProc = null; FreeBuffers(); if (_mWaveOut != IntPtr.Zero) diff --git a/Correlator/Util/WaveOutStream.cs b/Correlator/Util/WaveOutStream.cs index 8789a42..497f779 100644 --- a/Correlator/Util/WaveOutStream.cs +++ b/Correlator/Util/WaveOutStream.cs @@ -21,7 +21,7 @@ return Encoding.ASCII.GetString(ch); } - public WaveOutStream(string fileName) : this(new FileStream(fileName, FileMode.Open)) + public WaveOutStream(string fileName) : this(new FileStream(fileName, FileMode.OpenOrCreate)) { } diff --git a/Correlator/Util/PlayWav.cs b/Correlator/Util/PlayWav.cs index 670f9f5..a3e8825 100644 --- a/Correlator/Util/PlayWav.cs +++ b/Correlator/Util/PlayWav.cs @@ -30,12 +30,14 @@ { try { - var ws = new WaveOutStream(""); + //必须填入文件名,否则ws无法实例化 + var ws = new WaveOutStream("AutoGenerate.txt"); _mFormat = ws.Format; _waveOutStream = ws; } - catch (Exception) + catch (Exception e) { + LogWithConsole.WriteLine(e.Message, "PlayWav"); CloseFile(); } diff --git a/Correlator/Util/WaveOut.cs b/Correlator/Util/WaveOut.cs index 91752af..6131836 100644 --- a/Correlator/Util/WaveOut.cs +++ b/Correlator/Util/WaveOut.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -42,8 +41,9 @@ var buf = (WaveOutBuffer)h.Target; buf.OnCompleted(); } - catch (Exception) + catch (Exception e) { + LogWithConsole.WriteLine(e.Message, "WaveOut"); } } @@ -91,9 +91,7 @@ private void GetMemory(string title) { - Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " WaveOut => {0}: {1}, {2}", title, - _mPlaying, _mark); - // Console.WriteLine(@"{0}: {1}, {2}", title, _mPlaying, _mark); + LogWithConsole.WriteLine($"{title}: {_mPlaying}, {_mark}", "WaveOut"); } public bool Play() @@ -115,10 +113,6 @@ { _mPlaying = _mPlayEvent.WaitOne(); } - else - { - //Thread.Sleep(0); - } } private void OnCompleted() @@ -191,9 +185,6 @@ if (_mWaveOut != IntPtr.Zero) WaveOutBase.waveOutReset(_mWaveOut); - //m_Thread.Abort(); - //m_Thread.Join(); - _mFillProc = null; FreeBuffers(); if (_mWaveOut != IntPtr.Zero) diff --git a/Correlator/Util/WaveOutStream.cs b/Correlator/Util/WaveOutStream.cs index 8789a42..497f779 100644 --- a/Correlator/Util/WaveOutStream.cs +++ b/Correlator/Util/WaveOutStream.cs @@ -21,7 +21,7 @@ return Encoding.ASCII.GetString(ch); } - public WaveOutStream(string fileName) : this(new FileStream(fileName, FileMode.Open)) + public WaveOutStream(string fileName) : this(new FileStream(fileName, FileMode.OpenOrCreate)) { } diff --git a/Correlator/ViewModel/AuditionViewModel.cs b/Correlator/ViewModel/AuditionViewModel.cs index 609bfbb..1ea67f4 100644 --- a/Correlator/ViewModel/AuditionViewModel.cs +++ b/Correlator/ViewModel/AuditionViewModel.cs @@ -136,7 +136,7 @@ #endregion - private readonly DispatcherTimer _statusTimer = new DispatcherTimer(); + private readonly DispatcherTimer _statusTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; public AuditionViewModel() { @@ -232,7 +232,6 @@ Task.Factory.StartNew(RandomTempValue); //每秒查询信号状态 - _statusTimer.Interval = TimeSpan.FromSeconds(1); _statusTimer.Tick += delegate { SensorASignalIntensity = FlowStatus.SensorASignalIntensity;