HamBook – Blame information for rev 39

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using HamBook.Radios;
2 using HamBook.Utilities;
3 using HamBook.Utilities.Serialization;
4 using NetSparkleUpdater.Enums;
5 using NetSparkleUpdater.SignatureVerifiers;
6 using NetSparkleUpdater.UI.WinForms;
7 using NetSparkleUpdater;
8 using Serilog;
9 using System;
10 using System.ComponentModel;
11 using System.Drawing;
12 using System.IO;
13 using System.IO.Ports;
14 using System.Reflection;
15 using System.Threading;
16 using System.Threading.Tasks;
17 using System.Windows.Forms;
18 using HamBook.Properties;
19 using HamBook.Radios.Generic;
20 using PowerState = HamBook.Radios.Generic.PowerState;
5 office 21 using System.Media;
7 office 22 using HamBook.Utilities.Controls;
9 office 23 using RJCP.IO.Ports;
24 using System.Text;
12 office 25 using System.Collections.ObjectModel;
26 using Configuration;
27 using System.Collections.Generic;
15 office 28 using NAudio.Utils;
29 using System.Linq;
30 using static System.Net.Mime.MediaTypeNames;
25 office 31 using System.Diagnostics;
32 using Newtonsoft.Json.Linq;
26 office 33 using System.Collections.Concurrent;
34 using Org.BouncyCastle.Math.Field;
38 office 35 using System.Runtime.Remoting.Channels;
1 office 36  
37 namespace HamBook
38 {
39 public partial class Form1 : Form
40 {
41 private ScheduledContinuation _changedConfigurationContinuation;
25 office 42 private ScheduledContinuation _squelchScheduledContinuation;
43 private ScheduledContinuation _powerScheduledContinuation;
44  
1 office 45 private Configuration.Configuration Configuration { get; set; }
9 office 46 private SerialPortStream _serialPort;
1 office 47 private LogMemorySink _memorySink;
48 private ViewLogsForm _viewLogsForm;
49 private AboutForm _aboutForm;
50 private SettingsForm _settingsForm;
51 private SparkleUpdater _sparkle;
52 private readonly CancellationToken _cancellationToken;
53 private readonly CancellationTokenSource _cancellationTokenSource;
54 private CatAssemblies _catAssemblies;
3 office 55 private BandScan _bandScan;
10 office 56 private SpectrogramForm _spectrogramForm;
15 office 57 private MemoryOrganizerForm _memoryOrganizerForm;
1 office 58  
15 office 59 private CancellationTokenSource _tagTickerCancellationTokenSource;
60 private CancellationToken _tagTickerCancellationToken;
61 private string _storedMemoryChannelTagText;
62 private string _storedMemoryChannelLocation;
63 private MemoryChannel _tickerTextMemoryChannel;
64 private Task _tickerTask;
65 private volatile bool _tickerTaskRunning;
66  
26 office 67 private ConcurrentDictionary<int, MemoryChannel> _memoryChannelStore = new ConcurrentDictionary<int, MemoryChannel>();
39 office 68 private MemoryTune _memoryTune;
26 office 69  
1 office 70 public bool MemorySinkEnabled { get; set; }
71  
72 private Form1()
73 {
74 _cancellationTokenSource = new CancellationTokenSource();
75 _cancellationToken = _cancellationTokenSource.Token;
76  
77 _changedConfigurationContinuation = new ScheduledContinuation();
3 office 78  
25 office 79 _squelchScheduledContinuation = new ScheduledContinuation();
80 _powerScheduledContinuation = new ScheduledContinuation();
81  
1 office 82 }
83  
84 public Form1(Mutex mutex) : this()
85 {
86 InitializeComponent();
87  
88 _memorySink = new LogMemorySink();
89  
90 Log.Logger = new LoggerConfiguration()
91 .MinimumLevel.Debug()
92 .WriteTo.Conditional(condition => MemorySinkEnabled, configureSink => configureSink.Sink(_memorySink))
93 .WriteTo.File(Path.Combine(Constants.UserApplicationDirectory, "Logs", $"{Constants.AssemblyName}.log"),
94 rollingInterval: RollingInterval.Day)
95 .CreateLogger();
96  
97 // Start application update.
98 var manifestModuleName = Assembly.GetEntryAssembly().ManifestModule.FullyQualifiedName;
99 var icon = Icon.ExtractAssociatedIcon(manifestModuleName);
100  
101 _sparkle = new SparkleUpdater("https://hambook.grimore.org/update/appcast.xml",
102 new Ed25519Checker(SecurityMode.Strict, "LonrgxVjSF0GnY4hzwlRJnLkaxnDn2ikdmOifILzLJY="))
103 {
104 UIFactory = new UIFactory(icon),
105 RelaunchAfterUpdate = true
106 };
107 }
108  
109 private async void Form1_Load(object sender, EventArgs e)
110 {
13 office 111 _sparkle.StartLoop(true, true);
112  
1 office 113 Configuration = await LoadConfiguration();
114  
7 office 115 _serialPort = InitializeSerialPort(Configuration);
1 office 116  
7 office 117 _catAssemblies = InitializeAssemblies(_serialPort);
1 office 118  
119 try
120 {
9 office 121 switch (await _catAssemblies.CatReadAsync<PowerState>("PS", new object[] { }, _cancellationToken))
1 office 122 {
123 case PowerState.ON:
7 office 124 Log.Information(Resources.Attempting_to_initialize_radio);
9 office 125 if(!await InitializeRadio())
7 office 126 {
127 return;
128 }
129  
130 Log.Information(Resources.Initializing_GUI);
1 office 131 break;
132 }
133 }
134 catch(Exception exception)
135 {
136 Log.Error(exception, Resources.Failed_to_read_power_state);
137 }
26 office 138  
139 var memoryBankQueue = new ConcurrentQueue<int>();
140 var memoryBankTaskCompletionSource = new TaskCompletionSource<bool>();
141  
142 async void IdleHandler(object idleHandlerSender, EventArgs idleHandlerArgs)
143 {
144 await memoryBankTaskCompletionSource.Task;
145  
146 try
147 {
148 if (!memoryBankQueue.TryDequeue(out var memoryBank))
149 {
150 System.Windows.Forms.Application.Idle -= IdleHandler;
151  
152 return;
153 }
154  
155 var location = $"{memoryBank:000}";
156  
38 office 157 scrollableToolStripComboBox12.Items.Add(location);
158  
26 office 159 MemoryChannel memoryChannel = new MemoryChannel();
160  
161 try
162 {
163 memoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { location }, _cancellationToken);
38 office 164  
26 office 165 scrollableToolStripComboBox5.Items.Add(location);
166  
167 }
168 catch(Exception exception)
169 {
170 Log.Warning(exception, Resources.Could_not_read_memory_bank);
171  
172 return;
173 }
174  
175 _memoryChannelStore.TryAdd(memoryBank, memoryChannel);
176  
177 }
178 catch (Exception exception)
179 {
180 Log.Error(exception, Resources.Could_not_update_data_grid_view);
181 }
182 }
183  
184 System.Windows.Forms.Application.Idle += IdleHandler;
185 try
186 {
187 foreach (var memoryBank in Enumerable.Range(1, 99))
188 {
189 memoryBankQueue.Enqueue(memoryBank);
190 }
191  
192 memoryBankTaskCompletionSource.TrySetResult(true);
193 }
194 catch (Exception exception)
195 {
196 System.Windows.Forms.Application.Idle -= IdleHandler;
197  
38 office 198 Log.Error(exception, Resources.Unable_to_read_memory_banks);
26 office 199 }
1 office 200 }
201  
9 office 202 private async void quitToolStripMenuItem_Click(object sender, EventArgs e)
1 office 203 {
9 office 204 if(_bandScan != null)
205 {
39 office 206 _bandScan.Stop();
9 office 207 _bandScan = null;
208 }
209  
39 office 210 if (_memoryTune != null)
211 {
212 _memoryTune.Stop();
213 _memoryTune = null;
214 }
215  
14 office 216 // Save configuration on quit.
217 await SaveConfiguration();
218  
1 office 219 Close();
220 }
221  
222 private void viewLogsToolStripMenuItem_Click(object sender, EventArgs e)
223 {
224 if (_viewLogsForm != null)
225 {
226 return;
227 }
228  
229 _viewLogsForm = new ViewLogsForm(this, _memorySink, _cancellationToken);
230 _viewLogsForm.Closing += ViewLogsForm_Closing;
231 _viewLogsForm.Show();
232 }
233  
234 private void ViewLogsForm_Closing(object sender, CancelEventArgs e)
235 {
236 if (_viewLogsForm == null)
237 {
238 return;
239 }
240  
241 _viewLogsForm.Closing -= ViewLogsForm_Closing;
242 _viewLogsForm.Close();
243 _viewLogsForm = null;
244 }
245  
246 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
247 {
248 if (_aboutForm != null)
249 {
250 return;
251 }
252  
253 _aboutForm = new AboutForm(_cancellationToken);
254 _aboutForm.Closing += AboutForm_Closing;
255 _aboutForm.Show();
256 }
257  
258 private void AboutForm_Closing(object sender, CancelEventArgs e)
259 {
260 if (_aboutForm == null)
261 {
262 return;
263 }
264  
265 _aboutForm.Dispose();
266 _aboutForm = null;
267 }
268  
269 private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
270 {
271 if (_settingsForm != null)
272 {
273 return;
274 }
275  
276 _settingsForm = new SettingsForm(Configuration, _cancellationToken);
277 _settingsForm.Closing += SettingsForm_Closing;
278 _settingsForm.Show();
279 }
280  
281 private void SettingsForm_Closing(object sender, CancelEventArgs e)
282 {
283 if (_settingsForm == null)
284 {
285 return;
286 }
287  
288 if(_settingsForm.SaveOnClose)
289 {
290 // Commit the configuration.
291 _changedConfigurationContinuation.Schedule(TimeSpan.FromSeconds(1),
292 async () => {
293 await SaveConfiguration();
294  
11 office 295 if(_bandScan != null)
296 {
39 office 297 _bandScan.Stop();
11 office 298 _bandScan = null;
299 }
300  
39 office 301 if (_memoryTune != null)
302 {
303 _memoryTune.Stop();
304 _memoryTune = null;
305 }
11 office 306  
1 office 307 Miscellaneous.LaunchOnBootSet(Configuration.LaunchOnBoot);
308  
7 office 309 _serialPort = InitializeSerialPort(Configuration);
1 office 310  
7 office 311 _catAssemblies = InitializeAssemblies(_serialPort);
312  
313 try
314 {
9 office 315 switch (await _catAssemblies.CatReadAsync<PowerState>("PS", new object[] { }, _cancellationToken))
7 office 316 {
317 case PowerState.ON:
318 Log.Information(Resources.Attempting_to_initialize_radio);
9 office 319 if (!await InitializeRadio())
7 office 320 {
321 return;
322 }
323 Log.Information(Resources.Initializing_GUI);
324 break;
325 }
326 }
327 catch (Exception exception)
328 {
329 Log.Error(exception, Resources.Failed_to_read_power_state);
330 }
331  
1 office 332 }, _cancellationToken);
333 }
334  
335 _settingsForm.Dispose();
336 _settingsForm = null;
337 }
338  
339 public async Task SaveConfiguration()
340 {
341 if (!Directory.Exists(Constants.UserApplicationDirectory))
342 {
343 Directory.CreateDirectory(Constants.UserApplicationDirectory);
344 }
345  
346 switch (await Serialization.Serialize(Configuration, Constants.ConfigurationFile, "Configuration",
347 "<!ATTLIST Configuration xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>",
348 CancellationToken.None))
349 {
3 office 350 case SerializationSuccess<Configuration.Configuration> configuration:
16 office 351 Log.Information(Resources.Configuration_serialized_successfully);
1 office 352 break;
353 case SerializationFailure serializationFailure:
16 office 354 Log.Warning(serializationFailure.Exception.Message, Resources.Configuration_failed_to_serialize);
1 office 355 break;
356 }
357 }
358  
359 public static async Task<Configuration.Configuration> LoadConfiguration()
360 {
361 if (!Directory.Exists(Constants.UserApplicationDirectory))
362 {
363 Directory.CreateDirectory(Constants.UserApplicationDirectory);
364 }
365  
366 var deserializationResult =
367 await Serialization.Deserialize<Configuration.Configuration>(Constants.ConfigurationFile,
368 Constants.ConfigurationNamespace, Constants.ConfigurationXsd, CancellationToken.None);
369  
370 switch (deserializationResult)
371 {
372 case SerializationSuccess<Configuration.Configuration> serializationSuccess:
373 return serializationSuccess.Result;
374 case SerializationFailure serializationFailure:
16 office 375 Log.Warning(serializationFailure.Exception, Resources.Configuration_failed_to_deserialize);
1 office 376 return new Configuration.Configuration();
377 default:
378 return new Configuration.Configuration();
379 }
380 }
381  
9 office 382 private async Task<bool> InitializeRadio()
1 office 383 {
384 try
385 {
9 office 386 await _catAssemblies.CatWriteAsync<InformationState>("AI", new object[] { InformationState.OFF }, _cancellationToken);
387  
11 office 388 return await _catAssemblies.CatReadAsync<bool>("ID", new object[] { }, _cancellationToken);
1 office 389 }
390 catch(Exception exception)
391 {
7 office 392 Log.Error(exception, Resources.Unable_to_initialize_radio);
11 office 393  
7 office 394 return false;
1 office 395 }
7 office 396 }
397  
9 office 398 private CatAssemblies InitializeAssemblies(SerialPortStream serialPort)
7 office 399 {
400 if(_catAssemblies != null)
1 office 401 {
7 office 402 _catAssemblies.Dispose();
403 _catAssemblies = null;
1 office 404 }
405  
7 office 406 return new CatAssemblies(serialPort, Configuration.Radio);
407 }
408  
9 office 409 private SerialPortStream InitializeSerialPort(Configuration.Configuration configuration)
7 office 410 {
411 if (_serialPort != null)
1 office 412 {
7 office 413 if (_serialPort.IsOpen)
414 {
415 _serialPort.Close();
416 }
26 office 417  
7 office 418 _serialPort.Dispose();
419 _serialPort = null;
1 office 420 }
421  
7 office 422 // Set up serial connection.
9 office 423 var serialPort = new SerialPortStream(configuration.Port, configuration.Speed, configuration.DataBits, configuration.Parity, configuration.StopBits);
7 office 424 serialPort.ReadTimeout = configuration.SerialPortTimeout.Read;
425 serialPort.WriteTimeout = configuration.SerialPortTimeout.Write;
426 serialPort.Handshake = configuration.Handshake;
9 office 427 serialPort.Encoding = Encoding.ASCII;
1 office 428  
7 office 429 Log.Information($"{Resources.Initialized_serial_port} {configuration.Port} {configuration.Speed} {configuration.Parity} {configuration.DataBits} {configuration.StopBits}");
430  
431 return serialPort;
1 office 432 }
433  
434 private async void updateToolStripMenuItem_Click(object sender, EventArgs e)
435 {
436 // Manually check for updates, this will not show a ui
437 var result = await _sparkle.CheckForUpdatesQuietly();
438 if (result.Status == NetSparkleUpdater.Enums.UpdateStatus.UpdateAvailable)
439 {
440 // if update(s) are found, then we have to trigger the UI to show it gracefully
441 _sparkle.ShowUpdateNeededUI();
442 return;
443 }
444  
445 MessageBox.Show(Resources.No_updates_available_at_this_time, Resources.HamBook, MessageBoxButtons.OK,
446 MessageBoxIcon.Asterisk,
447 MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
448 }
449  
450 private async void onToolStripMenuItem_Click(object sender, EventArgs e)
451 {
452 try
453 {
15 office 454 await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.ON }, _cancellationToken);
1 office 455 }
456 catch(Exception exception)
457 {
458 Log.Error(exception, Resources.Failed_to_set_power_state);
459 }
460 }
461  
462 private async void offToolStripMenuItem_Click(object sender, EventArgs e)
463 {
464 try
465 {
15 office 466 await _catAssemblies.CatSetAsync<PowerState, bool>("PS", new object[] { PowerState.OFF }, _cancellationToken);
1 office 467 }
468 catch(Exception exception)
469 {
470 Log.Error(exception, Resources.Failed_to_set_power_state);
471 }
472 }
473  
29 office 474 private async void scrollableToolStripComboBox2_MouseWheel(object sender, MouseEventArgs e)
1 office 475 {
27 office 476 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
477 if (int.TryParse(toolStripComboBox.Text, out var frequency))
1 office 478 {
27 office 479 switch (Math.Sign(e.Delta))
3 office 480 {
27 office 481 case -1:
482 frequency = frequency - Configuration.Navigation.FrequencyStep;
483 break;
484 case 1:
485 frequency = frequency + Configuration.Navigation.FrequencyStep;
486 break;
487 }
5 office 488  
27 office 489 try
3 office 490 {
27 office 491 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav")))
492 {
29 office 493 if (await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency }, _cancellationToken))
494 {
495 toolStripComboBox.Text = $"{frequency}";
27 office 496  
32 office 497 if (Configuration.Navigation.MouseScrollSound)
498 {
499 soundPlayer.Play();
500 }
29 office 501 }
27 office 502 }
3 office 503 }
504 catch (Exception exception)
505 {
27 office 506 Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency);
3 office 507 }
1 office 508 }
509 }
510  
29 office 511 private async void scrollableToolStripComboBox2_KeyPress(object sender, KeyPressEventArgs e)
1 office 512 {
29 office 513 switch (e.KeyChar)
1 office 514 {
29 office 515 case (char)Keys.Enter:
516 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
27 office 517  
29 office 518 if (int.TryParse(toolStripComboBox.Text, out var frequency))
27 office 519 {
29 office 520 try
521 {
522 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav")))
523 {
524 if (await _catAssemblies.CatSetAsync<int, bool>("FB", new object[] { frequency }, _cancellationToken))
525 {
526 e.Handled = true;
27 office 527  
32 office 528 if (Configuration.Navigation.MouseScrollSound)
529 {
530 soundPlayer.Play();
531 }
29 office 532 }
533 }
534 }
535 catch (Exception exception)
536 {
537 Log.Error(exception, Resources.Failed_to_set_VFO_B_frequency);
538 }
539 }
540 break;
27 office 541 }
3 office 542 }
543  
39 office 544 private void toolStripMenuItem1_Click(object sender, EventArgs e)
3 office 545 {
546 if (_bandScan == null)
547 {
1 office 548 return;
549 }
550  
39 office 551 _bandScan.Stop();
3 office 552 _bandScan = null;
1 office 553 }
3 office 554  
39 office 555 private void toolStripMenuItem38_Click(object sender, EventArgs e)
3 office 556 {
39 office 557 if (_memoryTune != null)
558 {
559 _memoryTune.Stop();
560 _memoryTune = null;
561 }
562  
563 _memoryTune = new MemoryTune(_catAssemblies, _serialPort, Configuration);
564 _memoryTune.Start();
565 }
566  
567 private void stopToolStripMenuItem_Click(object sender, EventArgs e)
568 {
569 if (_memoryTune == null)
570 {
571 return;
572 }
573  
574 _memoryTune.Stop();
575 _memoryTune = null;
576 }
577  
578 private void scanToolStripMenuItem_Click(object sender, EventArgs e)
579 {
5 office 580 if (!(sender is ToolStripMenuItem toolStripMenuItem) ||
581 !int.TryParse(toolStripMenuItem.Tag.ToString(), out var meters))
3 office 582 {
5 office 583 return;
3 office 584 }
585  
5 office 586 if (!int.TryParse(scrollableToolStripComboBox3.Text, out var pause))
3 office 587 {
5 office 588 pause = 5;
3 office 589 }
590  
5 office 591 if(!int.TryParse(scrollableToolStripComboBox4.Text, out var step))
3 office 592 {
5 office 593 step = 5000;
3 office 594 }
595  
21 office 596 if(!int.TryParse(scrollableToolStripComboBox6.Text, out var scanDetectPause))
597 {
598 scanDetectPause = 10;
599 }
600  
5 office 601 if (!Configuration.Definitions.TryGetBand(meters, out var band))
3 office 602 {
5 office 603 return;
3 office 604 }
605  
606 if (_bandScan != null)
607 {
39 office 608 _bandScan.Stop();
9 office 609 _bandScan = null;
3 office 610 }
611  
21 office 612 _bandScan = new BandScan(_catAssemblies, (int)band.Min, (int)band.Max, _serialPort, Configuration);
9 office 613  
21 office 614 if (toolStripMenuItem14.Checked)
615 {
23 office 616 _bandScan.Start(step, pause, scanDetectPause, toolStripMenuItem16.Checked);
21 office 617  
618 return;
619 }
620  
36 office 621 _bandScan.Start(step, pause, 0, toolStripMenuItem16.Checked);
3 office 622 }
623  
36 office 624 private async void modeToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
3 office 625 {
36 office 626 try
7 office 627 {
36 office 628 var mode = await _catAssemblies.CatReadAsync<RadioMode>("MD", new object[] { }, _cancellationToken);
7 office 629  
36 office 630 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
11 office 631 {
36 office 632 toolStripComboBox1.Text = mode;
633 });
634 }
635 catch (Exception exception)
636 {
637 Log.Error(exception, Resources.Failed_to_read_radio_mode);
638 }
7 office 639  
36 office 640 try
641 {
642 var fa = await _catAssemblies.CatReadAsync<int>("FA", new object[] { }, _cancellationToken);
643  
644 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
11 office 645 {
36 office 646 scrollableToolStripComboBox1.Text = $"{fa}";
7 office 647  
36 office 648 });
11 office 649  
36 office 650 }
651 catch (Exception exception)
652 {
653 Log.Error(exception, Resources.Failed_to_read_VFO_A);
654 }
11 office 655  
36 office 656 try
657 {
658 var fb = await _catAssemblies.CatReadAsync<int>("FB", new object[] { }, _cancellationToken);
659  
660 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
11 office 661 {
36 office 662 scrollableToolStripComboBox2.Text = $"{fb}";
11 office 663  
36 office 664 });
665 }
666 catch (Exception exception)
667 {
668 Log.Error(exception, Resources.Failed_to_read_VFO_B);
669 }
11 office 670  
36 office 671 try
672 {
673 var mc = await _catAssemblies.CatReadAsync<int>("MC", new object[] { }, _cancellationToken);
19 office 674  
36 office 675 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
19 office 676 {
36 office 677 scrollableToolStripComboBox5.Text = $"{mc:000}";
19 office 678  
36 office 679 if (_memoryChannelStore.TryGetValue(mc, out var memoryChannel))
19 office 680 {
36 office 681 toolStripMenuItem27.Text = memoryChannel.Text;
682 }
19 office 683  
36 office 684 });
685 }
686 catch (Exception exception)
687 {
688 Log.Error(exception, Resources.Failed_to_read_memory_channel);
689 }
26 office 690  
36 office 691 try
692 {
693 var pc = await _catAssemblies.CatReadAsync<int>("PC", new object[] { }, _cancellationToken);
24 office 694  
36 office 695 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
24 office 696 {
36 office 697 scrollableToolStripComboBox7.Text = $"{pc}";
24 office 698  
36 office 699 });
700 }
701 catch (Exception exception)
702 {
703 Log.Error(exception, Resources.Failed_to_read_power_state);
704 }
24 office 705  
36 office 706 try
707 {
708 var sq = await _catAssemblies.CatReadAsync<int>("SQ", new object[] { }, _cancellationToken);
35 office 709  
36 office 710 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
35 office 711 {
36 office 712 scrollableToolStripComboBox11.Text = $"{sq}";
35 office 713  
36 office 714 });
715 }
716 catch (Exception exception)
717 {
718 Log.Error(exception, Resources.Failed_to_read_squelch);
719 }
37 office 720  
721 try
722 {
723 var st = await _catAssemblies.CatReadAsync<SplitState>("ST", new object[] { }, _cancellationToken);
724  
725 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
726 {
727 scrollableToolStripComboBox8.Text = $"{(string)st}";
728  
729 });
730 }
731 catch (Exception exception)
732 {
733 Log.Error(exception, Resources.Failed_to_read_split_state);
734 }
3 office 735 }
10 office 736  
737 private void spectrogramToolStripMenuItem_Click(object sender, EventArgs e)
738 {
739 if (_spectrogramForm != null)
740 {
741 return;
742 }
743  
744 _spectrogramForm = new SpectrogramForm(Configuration, _cancellationToken);
745 _spectrogramForm.Closing += SpectrogramForm_Closing;
746 _spectrogramForm.Show();
747 }
748  
749 private void SpectrogramForm_Closing(object sender, CancelEventArgs e)
750 {
751 if (_spectrogramForm == null)
752 {
753 return;
754 }
755  
756 _spectrogramForm.Dispose();
757 _spectrogramForm = null;
14 office 758  
759 // Commit the configuration.
760 _changedConfigurationContinuation.Schedule(TimeSpan.FromSeconds(1),
761 async () =>
762 {
763 await SaveConfiguration();
764 }, _cancellationToken);
10 office 765 }
15 office 766  
767 private void toolStripMenuItem3_Click(object sender, EventArgs e)
768 {
769 if (_memoryOrganizerForm != null)
770 {
771 return;
772 }
773  
774 _memoryOrganizerForm = new MemoryOrganizerForm(Configuration, _catAssemblies, _cancellationToken);
775 _memoryOrganizerForm.Closing += MemoryOrganizerForm_Closing;
776 _memoryOrganizerForm.Show();
777 }
778  
779 private void MemoryOrganizerForm_Closing(object sender, CancelEventArgs e)
780 {
781 if (_memoryOrganizerForm == null)
782 {
783 return;
784 }
785  
786 _memoryOrganizerForm.Dispose();
787 _memoryOrganizerForm = null;
788  
789 }
790  
791 private async void toolStripMenuItem4_Click(object sender, EventArgs e)
792 {
793 if (_tickerTaskRunning)
794 {
795 return;
796 }
797  
798 var toolStripTextBox = (ToolStripTextBox)toolStripTextBox6;
799  
800 try
801 {
802 var result = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { "001" }, _cancellationToken);
803  
804 _tickerTextMemoryChannel = await _catAssemblies.CatReadAsync<MemoryChannel>("MT", new object[] { $"{result.CurrentLocation}" }, _cancellationToken);
805  
806 _storedMemoryChannelTagText = _tickerTextMemoryChannel.Text;
807 _storedMemoryChannelLocation = _tickerTextMemoryChannel.CurrentLocation;
808 }
809 catch(Exception exception)
810 {
811 Log.Error(exception, Resources.Could_not_read_memory_bank);
812 }
813  
814 var tickerText = $"{toolStripTextBox.Text,-12}";
815  
816 _tagTickerCancellationTokenSource = new CancellationTokenSource();
817 _tagTickerCancellationToken = _tagTickerCancellationTokenSource.Token;
818  
819 var characterQueue = new Queue<char>(12);
820 foreach(var i in Enumerable.Range(0, 12))
821 {
822 var x = tickerText.ElementAtOrDefault(i);
823  
824 if(x == default)
825 {
826 characterQueue.Enqueue(' ');
827 continue;
828 }
829  
830 characterQueue.Enqueue(x);
831 }
832  
833 #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
834 _tickerTask = Task.Run(() => CycleText(characterQueue), _cancellationToken);
835 #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
836 }
837  
838 private async void toolStripMenuItem5_Click(object sender, EventArgs e)
839 {
840 if(!_tickerTaskRunning)
841 {
842 return;
843 }
844  
845 _tagTickerCancellationTokenSource.Cancel();
846 if (_tickerTask != null)
847 {
848 await _tickerTask;
849 _tickerTask = null;
850 }
851  
852 try
853 {
854 _tickerTextMemoryChannel.CurrentLocation = $"{_storedMemoryChannelLocation:000}";
17 office 855 _tickerTextMemoryChannel.Text = $"{_storedMemoryChannelTagText, -12}";
15 office 856  
857 var success = await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT", new object[] { _tickerTextMemoryChannel }, _cancellationToken);
858 if (!success)
859 {
860 Log.Error(Resources.Error_while_restoring_memory_text);
861  
862 return;
863 }
864 }
865 catch(Exception exception)
866 {
867 Log.Error(exception, Resources.Error_while_restoring_memory_text);
868 }
17 office 869 finally
870 {
871 _tickerTaskRunning = false;
872 }
15 office 873 }
874  
875 private async Task CycleText(Queue<char> characterQueue)
876 {
877 _tickerTaskRunning = true;
878 try
879 {
880 do
881 {
882 var text = string.Join("", characterQueue.OfType<char>());
883  
884 _tickerTextMemoryChannel.Text = text;
885  
886 await _catAssemblies.CatWriteAsync<MemoryChannel>("MT", new object[] { _tickerTextMemoryChannel }, _cancellationToken);
887  
888 var x = characterQueue.Dequeue();
889 characterQueue.Enqueue(x);
890  
891 await Task.Delay(250);
892  
893 } while (!_tagTickerCancellationToken.IsCancellationRequested);
894 }
895 catch(Exception exception)
896 {
897 Log.Error(exception, Resources.Error_while_cycling_text);
898 }
899 }
19 office 900  
27 office 901 private async void scrollableToolStripComboBox5_SelectedIndexChanged(object sender, EventArgs e)
19 office 902 {
38 office 903 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
904  
905 if (int.TryParse(toolStripComboBox.Text, out var channel))
19 office 906 {
38 office 907 if (_memoryChannelStore.TryGetValue(channel, out var memoryChannel))
19 office 908 {
38 office 909 try
27 office 910 {
38 office 911 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav")))
27 office 912 {
913 await _catAssemblies.CatWriteAsync<int>("MC", new object[] { channel }, _cancellationToken);
19 office 914  
27 office 915 scrollableToolStripComboBox1.Text = $"{memoryChannel.Frequency}";
24 office 916  
27 office 917 toolStripMenuItem27.Text = memoryChannel.Text;
24 office 918  
27 office 919 soundPlayer.Play();
920 }
26 office 921 }
38 office 922 catch (Exception exception)
923 {
924 Log.Error(exception, Resources.Failed_to_set_memory_channel);
925 }
19 office 926 }
927 }
928 }
20 office 929  
35 office 930 private async void powerToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
20 office 931 {
932 var toolStripMenuItem = toolStripMenuItem11;
933  
934 try
935 {
936 switch (await _catAssemblies.CatReadAsync<PowerState>("PS", new object[] { }, _cancellationToken))
937 {
938 case PowerState.ON:
939 toolStripMenuItem.Text = Resources.On;
940 break;
941 case PowerState.OFF:
942 toolStripMenuItem.Text = Resources.Off;
943 break;
944 }
945 }
946 catch (Exception exception)
947 {
948 Log.Error(exception, Resources.Failed_to_read_power_state);
949 }
950 }
23 office 951  
952 private async void toolStripMenuItem17_Click(object sender, EventArgs e)
953 {
954 try
955 {
956 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON }, _cancellationToken);
957  
958 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNING_START }, _cancellationToken);
959 }
960 catch (Exception exception)
961 {
962 Log.Error(exception, Resources.Failed_tuning_current_frequency);
963 }
964 }
24 office 965  
966 private async void toolStripMenuItem22_CheckStateChanged(object sender, EventArgs e)
967 {
968 var toolStripMenuItem = (ToolStripMenuItem)sender;
969 try
970 {
971 if (toolStripMenuItem.Checked)
972 {
973 await _catAssemblies.CatWriteAsync<IpoState>("PA", new object[] { IpoState.IPO }, _cancellationToken);
974 return;
975 }
976  
977 await _catAssemblies.CatWriteAsync<IpoState>("PA", new object[] { IpoState.AMP }, _cancellationToken);
978 }
979 catch (Exception exception)
980 {
981 Log.Error(exception, Resources.Failed_setting_IPO);
982 }
983 }
984  
985 private async void toolStripMenuItem23_CheckStateChanged(object sender, EventArgs e)
986 {
987 var toolStripMenuItem = (ToolStripMenuItem)sender;
988  
989 try
990 {
991 if (toolStripMenuItem.Checked)
992 {
993 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON }, _cancellationToken);
994  
995 return;
996 }
997  
998 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_OFF }, _cancellationToken);
999 }
1000 catch (Exception exception)
1001 {
1002 Log.Error(exception, Resources.Failed_setting_the_tuner_state);
1003 }
1004 }
1005  
1006 private async void toolStripMenuItem24_Click(object sender, EventArgs e)
1007 {
1008 try
1009 {
39 office 1010 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNER_ON }, _cancellationToken);
1011  
1012 do
1013 {
1014 await Task.Delay(TimeSpan.FromSeconds(1), _cancellationToken);
1015  
1016 try
1017 {
1018 var tuneState = await _catAssemblies.CatReadAsync<TunerState>("AC", new object[] { }, _cancellationToken);
1019  
1020 if (tuneState == TunerState.TUNER_ON)
1021 {
1022 break;
1023 }
1024 }
1025 catch (Exception)
1026 {
1027 // retry
1028 }
1029  
1030 } while (!_cancellationToken.IsCancellationRequested);
1031  
24 office 1032 await _catAssemblies.CatWriteAsync<TunerState>("AC", new object[] { TunerState.TUNING_START }, _cancellationToken);
1033 }
1034 catch(Exception exception)
1035 {
39 office 1036 Log.Error(exception, Resources.Could_not_start_tuning);
24 office 1037 }
1038 }
25 office 1039  
35 office 1040 private void toolStripMenuItem21_DropDownOpening(object sender, EventArgs e)
25 office 1041 {
1042 Task.Delay(TimeSpan.FromSeconds(1), _cancellationToken).ContinueWith(async task =>
1043 {
1044 try
1045 {
1046 var ac = await _catAssemblies.CatReadAsync<TunerState>("AC", new object[] { }, _cancellationToken);
1047  
1048 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
1049 {
1050 switch (ac)
1051 {
1052 case TunerState.TUNING_START:
1053 case TunerState.TUNER_ON:
1054 toolStripMenuItem23.Checked = true;
1055 break;
1056 case TunerState.TUNER_OFF:
1057 toolStripMenuItem23.Checked = false;
1058 break;
1059 }
1060  
1061  
1062 });
1063 }
1064 catch (Exception exception)
1065 {
1066 Log.Error(exception, Resources.Failed_to_read_the_tuner_state);
1067 }
1068  
1069 try
1070 {
1071 var pa = await _catAssemblies.CatReadAsync<IpoState>("PA", new object[] { }, _cancellationToken);
1072  
1073 contextMenuStrip1.InvokeIfRequired(contextMenuStrip =>
1074 {
1075 switch (pa)
1076 {
1077 case IpoState.AMP:
1078 toolStripMenuItem22.Checked = false;
1079 break;
1080 case IpoState.IPO:
1081 toolStripMenuItem22.Checked = true;
1082 break;
1083 }
1084  
1085  
1086 });
1087 }
1088 catch (Exception exception)
1089 {
1090 Log.Error(exception, Resources.Failed_to_read_IPO);
1091 }
1092 }, _cancellationToken);
1093 }
1094  
29 office 1095 private async void scrollableToolStripComboBox1_MouseWheel(object sender, MouseEventArgs e)
25 office 1096 {
1097 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
27 office 1098 if (int.TryParse(toolStripComboBox.Text, out var frequency))
1099 {
1100 switch (Math.Sign(e.Delta))
1101 {
1102 case -1:
1103 frequency = frequency - Configuration.Navigation.FrequencyStep;
1104 break;
1105 case 1:
1106 frequency = frequency + Configuration.Navigation.FrequencyStep;
1107 break;
1108 }
25 office 1109  
27 office 1110 try
1111 {
29 office 1112 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav")))
25 office 1113 {
29 office 1114 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency }, _cancellationToken))
1115 {
1116 toolStripComboBox.Text = $"{frequency}";
25 office 1117  
32 office 1118 if (Configuration.Navigation.MouseScrollSound)
1119 {
1120 soundPlayer.Play();
1121 }
29 office 1122 }
25 office 1123 }
27 office 1124 }
1125 catch (Exception exception)
1126 {
1127 Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency);
1128 }
1129 }
1130 }
25 office 1131  
29 office 1132 private async void scrollableToolStripComboBox1_KeyPress(object sender, KeyPressEventArgs e)
27 office 1133 {
29 office 1134 switch (e.KeyChar)
27 office 1135 {
29 office 1136 case (char)Keys.Enter:
32 office 1137  
25 office 1138  
29 office 1139 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
27 office 1140  
29 office 1141 if (int.TryParse(toolStripComboBox.Text, out var frequency))
27 office 1142 {
29 office 1143 try
1144 {
1145 using (var soundPlayer = new SoundPlayer(Assembly.GetExecutingAssembly().GetManifestResourceStream("HamBook.Effects.pot.wav")))
1146 {
1147 if (await _catAssemblies.CatSetAsync<int, bool>("FA", new object[] { frequency }, _cancellationToken))
1148 {
32 office 1149 e.Handled = true;
1150  
1151 if (Configuration.Navigation.MouseScrollSound)
1152 {
1153 soundPlayer.Play();
1154 }
29 office 1155 }
1156 }
1157 }
1158 catch (Exception exception)
1159 {
1160 Log.Error(exception, Resources.Failed_to_set_VFO_A_frequency);
1161 }
1162 }
1163 break;
27 office 1164 }
25 office 1165 }
1166  
37 office 1167 private void scrollableToolStripComboBox11_SelectedIndexChanged(object sender, EventArgs e)
25 office 1168 {
1169 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
1170  
1171 _squelchScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () =>
1172 {
1173 contextMenuStrip1.InvokeIfRequired(async contextMenuStrip1 =>
1174 {
1175 if (int.TryParse(toolStripComboBox.Text, out var squelch))
1176 {
1177  
1178 try
1179 {
1180 await _catAssemblies.CatWriteAsync<int>("SQ", new object[] { squelch }, _cancellationToken);
1181  
1182 toolStripComboBox.Text = $"{squelch}";
1183  
27 office 1184 Log.Information($"{Resources.Squelch_set} {squelch}");
25 office 1185 }
1186 catch (Exception exception)
1187 {
1188 Log.Error(exception, Resources.Failed_to_set_squelch);
1189 }
1190 }
1191 });
1192 }, _cancellationToken);
1193 }
27 office 1194  
1195 private async void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
1196 {
1197 var toolStripComboBox = (ToolStripComboBox)sender;
1198 if (RadioMode.TryParse(toolStripComboBox.Text, out var radioMode))
1199 {
1200 try
1201 {
1202 await _catAssemblies.CatSetAsync<RadioMode, bool>("MD", new object[] { radioMode }, _cancellationToken);
1203 }
1204 catch (Exception exception)
1205 {
1206 Log.Error(exception, Resources.Failed_to_set_radio_mode, radioMode);
1207 }
1208 }
1209 }
1210  
34 office 1211 private async void scrollableToolStripComboBox7_SelectedIndexChanged(object sender, EventArgs e)
27 office 1212 {
1213 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
1214  
34 office 1215 if (int.TryParse(toolStripComboBox.Text, out var amplification))
27 office 1216 {
34 office 1217  
1218 try
27 office 1219 {
34 office 1220 if (await _catAssemblies.CatSetAsync<int, bool>("PC", new object[] { amplification }, _cancellationToken))
1221 {
1222  
1223 toolStripComboBox.Text = $"{amplification}";
1224  
1225 Log.Information($"{Resources.Amplification_set} {amplification}W");
1226 }
1227 }
1228 catch (Exception exception)
1229 {
1230 Log.Error(exception, Resources.Failed_to_set_amplification);
1231 }
1232 }
1233 }
1234  
1235 private async void scrollableToolStripComboBox7_KeyPress(object sender, KeyPressEventArgs e)
1236 {
1237 switch (e.KeyChar)
1238 {
1239 case (char)Keys.Enter:
1240 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
1241  
27 office 1242 if (int.TryParse(toolStripComboBox.Text, out var amplification))
1243 {
1244  
1245 try
1246 {
34 office 1247 if (await _catAssemblies.CatSetAsync<int, bool>("PC", new object[] { amplification }, _cancellationToken))
1248 {
27 office 1249  
34 office 1250 toolStripComboBox.Text = $"{amplification}";
27 office 1251  
34 office 1252 Log.Information($"{Resources.Amplification_set} {amplification}W");
1253  
1254 e.Handled = true;
1255 }
27 office 1256 }
1257 catch (Exception exception)
1258 {
1259 Log.Error(exception, Resources.Failed_to_set_amplification);
1260 }
1261 }
34 office 1262 break;
1263 }
27 office 1264 }
1265  
39 office 1266 private void toolStripMenuItem30_Click(object sender, EventArgs e)
33 office 1267 {
1268 if (!int.TryParse(scrollableToolStripComboBox9.Text, out var start)
1269 || !int.TryParse(scrollableToolStripComboBox10.Text, out var stop))
1270 {
1271 return;
1272 }
29 office 1273  
33 office 1274 if (!int.TryParse(scrollableToolStripComboBox3.Text, out var pause))
1275 {
1276 pause = 5;
1277 }
1278  
1279 if (!int.TryParse(scrollableToolStripComboBox4.Text, out var step))
1280 {
1281 step = 5000;
1282 }
1283  
1284 if (!int.TryParse(scrollableToolStripComboBox6.Text, out var scanDetectPause))
1285 {
1286 scanDetectPause = 10;
1287 }
1288  
1289 if (_bandScan != null)
1290 {
39 office 1291 _bandScan.Stop();
33 office 1292 _bandScan = null;
1293 }
1294  
1295 _bandScan = new BandScan(_catAssemblies, start, stop, _serialPort, Configuration);
1296  
1297 if (toolStripMenuItem14.Checked)
1298 {
1299 _bandScan.Start(step, pause, scanDetectPause, toolStripMenuItem16.Checked);
1300  
1301 return;
1302 }
1303  
36 office 1304 _bandScan.Start(step, pause, 0, toolStripMenuItem16.Checked);
33 office 1305 }
35 office 1306  
1307 private async void toolStripMenuItem32_Click(object sender, EventArgs e)
1308 {
1309 var toolStripMenuItem = toolStripMenuItem31;
1310  
1311 try
1312 {
1313 if (await _catAssemblies.CatSetAsync<TxState, bool>("TX", new object[] { TxState.ON }, _cancellationToken))
1314 {
1315 toolStripMenuItem.Text = Resources.On;
1316 return;
1317 }
1318 }
1319 catch (Exception exception)
1320 {
1321 Log.Error(exception, Resources.Failed_to_set_PTT_state);
1322 }
1323 }
1324  
1325 private async void toolStripMenuItem33_Click(object sender, EventArgs e)
1326 {
1327 var toolStripMenuItem = toolStripMenuItem31;
1328  
1329 try
1330 {
1331 if (await _catAssemblies.CatSetAsync<TxState, bool>("TX", new object[] { TxState.OFF }, _cancellationToken))
1332 {
1333 toolStripMenuItem.Text = Resources.Off;
1334 return;
1335 }
1336 }
1337 catch (Exception exception)
1338 {
1339 Log.Error(exception, Resources.Failed_to_set_PTT_state);
1340 }
1341 }
1342  
1343 private async void toolStripMenuItem26_DropDownOpening(object sender, EventArgs e)
1344 {
1345 var toolStripMenuItem = toolStripMenuItem31;
1346  
1347 try
1348 {
1349 switch (await _catAssemblies.CatReadAsync<TxState>("TX", new object[] { }, _cancellationToken))
1350 {
1351 case TxState.ON:
1352 toolStripMenuItem.Text = Resources.On;
1353 break;
1354 case TxState.OFF:
1355 toolStripMenuItem.Text = Resources.Off;
1356 break;
1357 }
1358 }
1359 catch (Exception exception)
1360 {
1361 Log.Error(exception, Resources.Failed_to_read_PTT_state);
1362 }
1363 }
37 office 1364  
1365 private async void scrollableToolStripComboBox8_SelectedIndexChanged(object sender, EventArgs e)
1366 {
1367 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
1368  
1369 if (SplitState.TryParse(toolStripComboBox.Text, out var splitState))
1370 {
1371 try
1372 {
1373 if (await _catAssemblies.CatSetAsync<int, bool>("ST", new object[] { splitState }, _cancellationToken))
1374 {
1375 Log.Information($"{Resources.Split_state_set} {splitState}W");
1376 }
1377 }
1378 catch (Exception exception)
1379 {
1380 Log.Error(exception, Resources.Failed_to_set_split_state);
1381 }
1382 }
1383 }
38 office 1384  
1385 private async void toolStripMenuItem35_Click(object sender, EventArgs e)
1386 {
1387 var scrollableToolStripComboBox = scrollableToolStripComboBox12;
1388  
1389 if (int.TryParse(scrollableToolStripComboBox.Text, out var channel))
1390 {
1391 if (!_memoryChannelStore.TryGetValue(channel, out var memoryChannel))
1392 {
1393 memoryChannel = new MemoryChannel();
1394 memoryChannel.CurrentLocation = $"{channel:000}";
1395 memoryChannel.MemoryRadioMode = toolStripComboBox1.Text;
1396 }
1397  
1398 if (memoryChannel.Tag = !string.IsNullOrEmpty(toolStripTextBox1.Text))
1399 {
1400 memoryChannel.Text = $"{toolStripTextBox1.Text, -12}";
1401 }
1402  
1403 if (int.TryParse(scrollableToolStripComboBox1.Text, out var frequency))
1404 {
1405 memoryChannel.Frequency = frequency;
1406  
1407 try
1408 {
1409 if (await _catAssemblies.CatSetAsync<MemoryChannel, bool>("MT", new object[] { memoryChannel }, _cancellationToken))
1410 {
1411 Log.Information(Resources.Stored_VFO_A_to_memory);
1412 }
1413 }
1414 catch (Exception exception)
1415 {
1416 Log.Error(exception, Resources.Failed_to_save_VFO_A_to_memory);
1417 }
1418 }
1419 }
1420 }
1421  
1422 private void scrollableToolStripComboBox12_SelectedIndexChanged(object sender, EventArgs e)
1423 {
1424 var toolStripComboBox = (ScrollableToolStripComboBox)sender;
1425  
1426 if (int.TryParse(toolStripComboBox.Text, out var channel))
1427 {
1428 if (_memoryChannelStore.TryGetValue(channel, out var memoryChannel))
1429 {
1430 toolStripTextBox1.Text = memoryChannel.Text;
1431 return;
1432 }
1433  
1434 toolStripTextBox1.Text = string.Empty;
1435 }
1436 }
1437  
1438 private async void toolStripMenuItem20_Click(object sender, EventArgs e)
1439 {
1440 try
1441 {
1442 var frequency = await _catAssemblies.CatReadAsync<int>("FA", new object[] { }, _cancellationToken);
1443  
1444 await _catAssemblies.CatWriteAsync<int>("FA", new object[] { frequency }, _cancellationToken);
1445  
1446 await _catAssemblies.CatWriteAsync("SV", new object[] { }, _cancellationToken);
1447 }
1448 catch (Exception exception)
1449 {
1450 Log.Error(exception, Resources.Unable_to_swap_VFO_A_and_VFO_B);
1451 }
1452 }
1 office 1453 }
1454 }