HamBook – Diff between revs 11 and 34
?pathlinks?
Rev 11 | Rev 34 | |||
---|---|---|---|---|
Line 9... | Line 9... | |||
9 | using System.Text.RegularExpressions; |
9 | using System.Text.RegularExpressions; |
|
10 | using System.Threading.Tasks; |
10 | using System.Threading.Tasks; |
|
11 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
11 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
|
12 | using RJCP.IO.Ports; |
12 | using RJCP.IO.Ports; |
|
13 | using System.Threading; |
13 | using System.Threading; |
|
- | 14 | using System.Diagnostics; |
||
Line 14... | Line 15... | |||
14 | |
15 | |
|
15 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
16 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
|
16 | { |
17 | { |
|
17 | [Radio("Yaesu FT-891")] |
18 | [Radio("Yaesu FT-891")] |
|
Line 26... | Line 27... | |||
26 | readRegex = new Regex($"^{Name}(?<state>[01]){Generic.Constants.EOT}$", RegexOptions.Compiled); |
27 | readRegex = new Regex($"^{Name}(?<state>[01]){Generic.Constants.EOT}$", RegexOptions.Compiled); |
|
27 | } |
28 | } |
|
Line 28... | Line 29... | |||
28 | |
29 | |
|
29 | public override async Task<bool> SetAsync(PowerState state, CancellationToken cancellationToken) |
30 | public override async Task<bool> SetAsync(PowerState state, CancellationToken cancellationToken) |
|
30 | { |
- | ||
31 | var taskCompletionSource = new TaskCompletionSource<bool>(); |
- | ||
32 | |
31 | { |
|
33 | var id = new ID(SerialPort); |
- | ||
34 | try |
- | ||
35 | { |
32 | SerialPort.Write(new byte[1] { 0 }, 0, 1); |
|
36 | await id.ReadAsync(cancellationToken); |
- | ||
37 | } |
- | ||
38 | catch |
- | ||
Line 39... | Line 33... | |||
39 | { |
33 | SerialPort.Read(new byte[2] { 0, 0 }, 0, 2); |
|
Line 40... | Line 34... | |||
40 | |
34 | |
|
41 | } |
35 | var taskCompletionSource = new TaskCompletionSource<bool>(); |
|
42 | |
36 | |
|
43 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
37 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
|
Line 67... | Line 61... | |||
67 | return await ReadAsync(cancellationToken) == state; |
61 | return await ReadAsync(cancellationToken) == state; |
|
68 | } |
62 | } |
|
Line 69... | Line 63... | |||
69 | |
63 | |
|
70 | public override async Task<PowerState> ReadAsync(CancellationToken cancellationToken) |
64 | public override async Task<PowerState> ReadAsync(CancellationToken cancellationToken) |
|
71 | { |
65 | { |
|
- | 66 | SerialPort.Write(new byte[1] { 0 }, 0, 1); |
||
Line 72... | Line -... | |||
72 | var taskCompletionSource = new TaskCompletionSource<int>(); |
- | ||
73 | |
- | ||
74 | var id = new ID(SerialPort); |
- | ||
75 | try |
67 | SerialPort.Read(new byte[2] { 0, 0 }, 0, 2); |
|
76 | { |
- | ||
77 | await id.ReadAsync(cancellationToken); |
- | ||
78 | } |
- | ||
79 | catch |
- | ||
80 | { |
- | ||
Line 81... | Line 68... | |||
81 | |
68 | |
|
82 | } |
69 | var taskCompletionSource = new TaskCompletionSource<int>(); |
|
83 | |
70 | |
|
84 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
71 | #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed |
|
Line 89... | Line 76... | |||
89 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
76 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
Line 90... | Line 77... | |||
90 | |
77 | |
|
91 | var buffer = new byte[CatLength.Answer]; |
78 | var buffer = new byte[CatLength.Answer]; |
|
92 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer) |
79 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer) |
|
- | 80 | { |
||
- | 81 | taskCompletionSource.TrySetResult(-1); |
||
93 | { |
82 | |
|
94 | throw new UnexpectedRadioResponseException(Name, buffer); |
83 | throw new UnexpectedRadioResponseException(Name, buffer); |
|
95 | } |
84 | } |
|
96 | var answer = Constants.Encoding.GetString(buffer); |
85 | var answer = Constants.Encoding.GetString(buffer); |
|
97 | var match = readRegex.Match(answer); |
86 | var match = readRegex.Match(answer); |
|
98 | if (!match.Success) |
87 | if (!match.Success) |
|
- | 88 | { |
||
- | 89 | taskCompletionSource.TrySetResult(-1); |
||
99 | { |
90 | |
|
100 | throw new UnmatchedRadioResponseException(Name, answer); |
91 | throw new UnmatchedRadioResponseException(Name, answer); |
|
Line 101... | Line 92... | |||
101 | } |
92 | } |
|
102 | |
93 | |