diff --git a/DataModels/Shx8800Pro/FMChannel.cs b/DataModels/Shx8800Pro/FMChannel.cs index 2603d6f..0eaa1fd 100644 --- a/DataModels/Shx8800Pro/FMChannel.cs +++ b/DataModels/Shx8800Pro/FMChannel.cs @@ -4,7 +4,7 @@ namespace SenhaixFreqWriter.DataModels.Shx8800Pro; public partial class FmChannel : ObservableObject { - [ObservableProperty] private int[] _channels = new int[15]; + [ObservableProperty] private int[] _channels = new int[30]; [ObservableProperty] private int _curFreq = 904; } diff --git a/Utils/Serial/WriFreq8800Pro.cs b/Utils/Serial/WriFreq8800Pro.cs index f49fc4f..5ddda7b 100644 --- a/Utils/Serial/WriFreq8800Pro.cs +++ b/Utils/Serial/WriFreq8800Pro.cs @@ -65,9 +65,9 @@ public class WriFreq8800Pro public ConcurrentQueue statusQueue = new(); - public WriFreq8800Pro(OpType opType) + public WriFreq8800Pro(MySerialPort port, OpType opType) { - this.port = MySerialPort.GetInstance(); + this.port = port; this.opType = opType; this.appData = AppData.GetInstance(); helper = new DataHelper(); @@ -135,7 +135,7 @@ private bool HandShake(CancellationToken cancellationToken) { case Step.StepHandshake1: array = Encoding.ASCII.GetBytes("PROGRAMSHXPU"); - port.Write(array, 0, array.Length); + port.WriteByte(array, 0, array.Length); progressVal = 0; progressCont = "握手..."; statusQueue.Enqueue(new ProgressBarValue(progressVal,progressCont)); @@ -144,13 +144,13 @@ private bool HandShake(CancellationToken cancellationToken) step = Step.StepHandshake2; break; case Step.StepHandshake2: - if (port.BytesToRead >= 1) + if (port.BytesToReadFromCache >= 1) { - port.Read(rxBuffer, 0, 1); + port.ReadByte(rxBuffer, 0, 1); if (rxBuffer[0] == 6) { array = new byte[1] { 70 }; - port.Write(array, 0, array.Length); + port.WriteByte(array, 0, array.Length); resetRetryCount(); step = Step.StepHandshake3; } @@ -158,9 +158,9 @@ private bool HandShake(CancellationToken cancellationToken) break; case Step.StepHandshake3: - if (port.BytesToRead >= 16) + if (port.BytesToReadFromCache >= 16) { - port.Read(rxBuffer, 0, 16); + port.ReadByte(rxBuffer, 0, 16); timer.Stop(); resetRetryCount(); progressVal = 0; @@ -190,7 +190,7 @@ private bool HandShake(CancellationToken cancellationToken) timesOfRetry--; flagRetry = false; - port.Write(array, 0, array.Length); + port.WriteByte(array, 0, array.Length); } } @@ -346,7 +346,7 @@ private bool Write(CancellationToken cancellationToken) } array = helper.LoadPackage(87, num, array2, (byte)array2.Length); - port.Write(array, 0, array.Length); + port.WriteByte(array, 0, array.Length); timer.Start(); progressVal = num * 100 / 45056; if (progressVal > 100) @@ -358,12 +358,12 @@ private bool Write(CancellationToken cancellationToken) step = Step.StepWrite2; break; case Step.StepWrite2: - if (port.BytesToRead < 1) + if (port.BytesToReadFromCache < 1) { break; } - port.Read(rxBuffer, 0, 1); + port.ReadByte(rxBuffer, 0, 1); if (rxBuffer[0] == 6) { timer.Stop(); @@ -408,7 +408,7 @@ private bool Write(CancellationToken cancellationToken) timesOfRetry--; flagRetry = false; - port.Write(array, 0, array.Length); + port.WriteByte(array, 0, array.Length); } } @@ -701,7 +701,7 @@ private bool Read(CancellationToken cancellationToken) (byte)num, 64 }; - port.Write(array2, 0, array2.Length); + port.WriteByte(array2, 0, array2.Length); progressVal = num * 100 / 45056; if (progressVal > 100) { @@ -716,14 +716,14 @@ private bool Read(CancellationToken cancellationToken) break; case Step.StepRead2: { - if (port.BytesToRead < 68) + if (port.BytesToReadFromCache < 68) { break; } timer.Stop(); resetRetryCount(); - port.Read(rxBuffer, 0, port.BytesToRead); + port.ReadByte(rxBuffer, 0, port.BytesToReadFromCache); byte b = (byte)(num >> 8); byte b2 = (byte)num; if (rxBuffer[1] != b || rxBuffer[2] != b2) @@ -889,7 +889,7 @@ private bool Read(CancellationToken cancellationToken) progressCont = "完成"; statusQueue.Enqueue(new ProgressBarValue(progressVal,progressCont)); array2 = new byte[1] { 69 }; - port.Write(array2, 0, array2.Length); + port.WriteByte(array2, 0, array2.Length); flagTransmitting = false; return true; } @@ -906,7 +906,7 @@ private bool Read(CancellationToken cancellationToken) timesOfRetry--; flagRetry = false; - port.Write(array2, 0, array2.Length); + port.WriteByte(array2, 0, array2.Length); } } diff --git a/Views/Shx8x00/PortSelectionWindow.axaml b/Views/Common/PortSelectionWindow.axaml similarity index 88% rename from Views/Shx8x00/PortSelectionWindow.axaml rename to Views/Common/PortSelectionWindow.axaml index 25288d4..ecb6c51 100644 --- a/Views/Shx8x00/PortSelectionWindow.axaml +++ b/Views/Common/PortSelectionWindow.axaml @@ -1,9 +1,9 @@  diff --git a/Views/Shx8x00/PortSelectionWindow.axaml.cs b/Views/Common/PortSelectionWindow.axaml.cs similarity index 97% rename from Views/Shx8x00/PortSelectionWindow.axaml.cs rename to Views/Common/PortSelectionWindow.axaml.cs index b120d7a..6f7e19b 100644 --- a/Views/Shx8x00/PortSelectionWindow.axaml.cs +++ b/Views/Common/PortSelectionWindow.axaml.cs @@ -4,7 +4,7 @@ using Avalonia.Interactivity; using SenhaixFreqWriter.Utils.Serial; -namespace SenhaixFreqWriter.Views.Shx8x00; +namespace SenhaixFreqWriter.Views.Common; public partial class PortSelectionWindow : Window { diff --git a/Views/Shx8800Pro/MainWindow.axaml b/Views/Shx8800Pro/MainWindow.axaml index 426b834..a46e030 100644 --- a/Views/Shx8800Pro/MainWindow.axaml +++ b/Views/Shx8800Pro/MainWindow.axaml @@ -76,6 +76,18 @@ + + + + + + + + + + + + diff --git a/Views/Shx8800Pro/MainWindow.axaml.cs b/Views/Shx8800Pro/MainWindow.axaml.cs index 0f4f46c..5ab0007 100644 --- a/Views/Shx8800Pro/MainWindow.axaml.cs +++ b/Views/Shx8800Pro/MainWindow.axaml.cs @@ -19,9 +19,6 @@ using SenhaixFreqWriter.DataModels.Shx8800Pro; using SenhaixFreqWriter.Views.Common; using SenhaixFreqWriter.Views.Plugin; -#if WINDOWS -using SenhaixFreqWriter.Utils.BLE.Platforms.Windows; -#endif namespace SenhaixFreqWriter.Views.Shx8800Pro; @@ -499,4 +496,8 @@ private void DebugWindowMenuItem_OnClick(object? sender, RoutedEventArgs e) { DebugWindow.GetInstance().Show(); } + private void portSel_OnClick(object? sender, RoutedEventArgs e) + { + new PortSelectionWindow().ShowDialog(this); + } } \ No newline at end of file diff --git a/Views/Shx8800Pro/ProgressBarWindow.axaml.cs b/Views/Shx8800Pro/ProgressBarWindow.axaml.cs index 727c24e..24dbb6c 100644 --- a/Views/Shx8800Pro/ProgressBarWindow.axaml.cs +++ b/Views/Shx8800Pro/ProgressBarWindow.axaml.cs @@ -26,11 +26,14 @@ public partial class ProgressBarWindow : Window private Thread _threadProgress; + private MySerialPort port; + public ProgressBarWindow(OpType op) { _operation = op; InitializeComponent(); - _com = new WriFreq8800Pro(op); + port = MySerialPort.GetInstance(); + _com = new WriFreq8800Pro(port,op); } private async void StartButton_OnClick(object? sender, RoutedEventArgs e) @@ -48,6 +51,7 @@ private async void StartButton_OnClick(object? sender, RoutedEventArgs e) return; } + port.OpenSerial(); _cancelSource = new CancellationTokenSource(); StartButton.IsEnabled = false; CloseButton.IsEnabled = true; @@ -71,6 +75,10 @@ private void Task_Communication(CancellationToken token) DebugWindow.GetInstance().updateDebugContent(a.Message); // Console.Write(a); } + finally + { + port.CloseSerial(); + } // DebugWindow.GetInstance().updateDebugContent("We've done write!"); Dispatcher.UIThread.Invoke(() => HandleResult(flag));