HamBook – Diff between revs 1 and 3
?pathlinks?
Rev 1 | Rev 3 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | using HamBook.Radios.Generic; |
1 | using HamBook.Radios.Generic; |
|
- | 2 | using HamBook.Radios.Generic.CAT; |
||
2 | using System; |
3 | using System; |
|
3 | using System.Collections.Generic; |
4 | using System.Collections.Generic; |
|
4 | using System.Drawing; |
5 | using System.Drawing; |
|
5 | using System.IO.Ports; |
6 | using System.IO.Ports; |
|
6 | using System.Linq; |
7 | using System.Linq; |
|
Line 10... | Line 11... | |||
10 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
11 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
|
Line 11... | Line 12... | |||
11 | |
12 | |
|
12 | namespace HamBook.Radios.Yaesu.FT_891 |
13 | namespace HamBook.Radios.Yaesu.FT_891 |
|
13 | { |
14 | { |
|
14 | [Radio("Yaesu FT-891")] |
15 | [Radio("Yaesu FT-891")] |
|
15 | public class PS : Generic.PS |
16 | public class PS : HamBook.Radios.Generic.CAT.PS |
|
16 | { |
17 | { |
|
Line 17... | Line 18... | |||
17 | private static readonly Regex readRegex = new Regex(@"^PS(?<state>[0,1])$", RegexOptions.Compiled); |
18 | private static readonly Regex readRegex = new Regex(@"^PS(?<state>[0,1])$", RegexOptions.Compiled); |
|
18 | |
19 | |
|
Line 27... | Line 28... | |||
27 | Task.Delay(Constants.POWER_ON_DELAY).ContinueWith(ca => |
28 | Task.Delay(Constants.POWER_ON_DELAY).ContinueWith(ca => |
|
28 | { |
29 | { |
|
29 | switch(state) |
30 | switch(state) |
|
30 | { |
31 | { |
|
31 | case PowerState.ON: |
32 | case PowerState.ON: |
|
32 | SerialPort.Write($"{Name}1{EOT}"); |
33 | SerialPort.Write($"{Name}1{Generic.Constants.EOT}"); |
|
33 | Task.Delay(Constants.TIME_TO_WARM).ContinueWith(cb => |
34 | Task.Delay(Constants.TIME_TO_WARM).ContinueWith(cb => |
|
34 | { |
35 | { |
|
35 | taskCompletionSource.TrySetResult(true); |
36 | taskCompletionSource.TrySetResult(true); |
|
36 | }); |
37 | }); |
|
37 | return; |
38 | return; |
|
38 | case PowerState.OFF: |
39 | case PowerState.OFF: |
|
39 | SerialPort.Write($"{Name}0{EOT}"); |
40 | SerialPort.Write($"{Name}0{Generic.Constants.EOT}"); |
|
40 | break; |
41 | break; |
|
41 | } |
42 | } |
|
42 | taskCompletionSource.TrySetResult(true); |
43 | taskCompletionSource.TrySetResult(true); |
|
43 | }); |
44 | }); |
|
44 | #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
45 | #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
|
Line 51... | Line 52... | |||
51 | { |
52 | { |
|
52 | var taskCompletionSource = new TaskCompletionSource<int>(); |
53 | var taskCompletionSource = new TaskCompletionSource<int>(); |
|
53 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
54 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
|
54 | Task.Delay(Constants.POWER_ON_DELAY).ContinueWith(_ => |
55 | Task.Delay(Constants.POWER_ON_DELAY).ContinueWith(_ => |
|
55 | { |
56 | { |
|
56 | SerialPort.Write($"{Name}{EOT}"); |
57 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
|
57 | var result = SerialPort.ReadTo(EOT); |
58 | var result = SerialPort.ReadTo(Generic.Constants.EOT); |
|
58 | var match = readRegex.Match(result); |
59 | var match = readRegex.Match(result); |
|
59 | var state = int.Parse(match.Result("${state}")); |
60 | var state = int.Parse(match.Result("${state}")); |
|
Line 60... | Line 61... | |||
60 | |
61 | |
|
61 | taskCompletionSource.TrySetResult(state); |
62 | taskCompletionSource.TrySetResult(state); |