HamBook – Blame information for rev 9

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