HamBook – Diff between revs 7 and 9
?pathlinks?
Rev 7 | Rev 9 | |||
---|---|---|---|---|
Line 6... | Line 6... | |||
6 | using System.Text; |
6 | using System.Text; |
|
7 | using System.Text.RegularExpressions; |
7 | using System.Text.RegularExpressions; |
|
8 | using System.Threading; |
8 | using System.Threading; |
|
9 | using System.Threading.Tasks; |
9 | using System.Threading.Tasks; |
|
10 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
10 | using static HamBook.Radios.Yaesu.FT_891.Constants; |
|
- | 11 | using RJCP.IO.Ports; |
||
Line 11... | Line 12... | |||
11 | |
12 | |
|
12 | namespace HamBook.Radios.Yaesu.FT_891 |
13 | namespace HamBook.Radios.Yaesu.FT_891.CAT |
|
13 | { |
14 | { |
|
14 | [Radio("Yaesu FT-891")] |
15 | [Radio("Yaesu FT-891")] |
|
15 | public class ID : Generic.CAT.ID |
16 | public class ID : Generic.CAT.ID |
|
16 | { |
17 | { |
|
Line -... | Line 18... | |||
- | 18 | private readonly Regex readRegex; |
||
17 | private static readonly Regex readRegex = new Regex(@"^ID(?<id>[0-9]{4})$", RegexOptions.Compiled); |
19 | |
|
18 | |
20 | public override CatLength CatLength => new CatLength { Answer = 7, Read = 3 }; |
|
- | 21 | public ID(SerialPortStream serialPort) : base(serialPort) |
||
19 | public ID(SerialPort serialPort) : base(serialPort) |
22 | { |
|
Line 20... | Line 23... | |||
20 | { |
23 | readRegex = new Regex($"^{Name}(?<id>[0-9]{{4}}){Generic.Constants.EOT}$", RegexOptions.Compiled); |
|
21 | } |
24 | } |
|
22 | |
25 | |
|
- | 26 | public override bool Read() |
||
- | 27 | { |
||
- | 28 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
||
- | 29 | var buffer = new byte[CatLength.Answer]; |
||
- | 30 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
||
- | 31 | { |
||
23 | public override bool Read() |
32 | throw new ArgumentException(); |
|
24 | { |
33 | } |
|
- | 34 | |
||
- | 35 | var answer = Encoding.ASCII.GetString(buffer); |
||
- | 36 | var match = readRegex.Match(answer); |
||
- | 37 | if (!match.Success) |
||
25 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
38 | { |
|
26 | var result = SerialPort.ReadTo(Generic.Constants.EOT); |
39 | throw new ArgumentException(); |
|
27 | var match = readRegex.Match(result); |
40 | } |
|
28 | return int.Parse(match.Result("${id}")) == int.Parse(Constants.ID); |
41 | return int.Parse(match.Result("${id}")) == int.Parse(Constants.ID); |