HamBook – Diff between revs 7 and 9

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 7 Rev 9
Line 6... Line 6...
6 using System.Linq; 6 using System.Linq;
7 using System.Text; 7 using System.Text;
8 using System.Text.RegularExpressions; 8 using System.Text.RegularExpressions;
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 SC : HamBook.Radios.Generic.CAT.SC 16 public class SC : HamBook.Radios.Generic.CAT.SC
16 { 17 {
Line -... Line 18...
-   18 private readonly Regex readRegex;
-   19  
17 private static readonly Regex readRegex = new Regex(@"^SC(?<state>[0,1,2])$", RegexOptions.Compiled); 20 public override CatLength CatLength => new CatLength { Set = 4, Answer = 4, Read = 3 };
18   21  
-   22 public SC(SerialPortStream serialPort) : base(serialPort)
19 public SC(SerialPort serialPort) : base(serialPort) 23 {
Line 20... Line 24...
20 { 24 readRegex = new Regex($"^{Name}(?<state>[012]){Generic.Constants.EOT}$", RegexOptions.Compiled);
21 } 25 }
22   26  
-   27 public override ScanState Read()
-   28 {
-   29 SerialPort.Write($"{Name}{Generic.Constants.EOT}");
-   30 var buffer = new byte[CatLength.Answer];
-   31 if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer)
-   32 {
23 public override ScanState Read() 33 throw new ArgumentException();
24 { 34 }
-   35  
-   36 var answer = Encoding.ASCII.GetString(buffer);
-   37 var match = readRegex.Match(answer);
-   38 if (!match.Success)
25 SerialPort.Write($"{Name}{Generic.Constants.EOT}"); 39 {
26 var result = SerialPort.ReadTo(Generic.Constants.EOT); 40 throw new ArgumentException();
27 var match = readRegex.Match(result); 41 }
28 var state = char.Parse(match.Result("${state}")); 42 var state = char.Parse(match.Result("${state}"));
29 switch(state) 43 switch(state)