HamBook – Diff between revs 11 and 46
?pathlinks?
Rev 11 | Rev 46 | |||
---|---|---|---|---|
Line 18... | Line 18... | |||
18 | private readonly Regex readRegex; |
18 | private readonly Regex readRegex; |
|
Line 19... | Line 19... | |||
19 | |
19 | |
|
20 | public override CatLength CatLength => new CatLength { Answer = 7, Read = 3 }; |
20 | public override CatLength CatLength => new CatLength { Answer = 7, Read = 3 }; |
|
21 | public ID(SerialPortStream serialPort) : base(serialPort) |
21 | public ID(SerialPortStream serialPort) : base(serialPort) |
|
22 | { |
22 | { |
|
23 | readRegex = new Regex($"^{Name}(?<id>[0-9]{{4}}){Generic.Constants.EOT}$", RegexOptions.Compiled); |
23 | readRegex = new Regex($"^{Name}(?<id>[0-9]{{4}}){Constants.EOT}$", RegexOptions.Compiled); |
|
Line 24... | Line 24... | |||
24 | } |
24 | } |
|
25 | |
25 | |
|
26 | public override bool Read() |
26 | public override bool Read() |
|
27 | { |
27 | { |
|
28 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
28 | SerialPort.Write($"{Name}{Constants.EOT}"); |
|
29 | var buffer = new byte[CatLength.Answer]; |
29 | var buffer = new byte[CatLength.Answer]; |
|
30 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
30 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
|
31 | { |
31 | { |
|
Line 41... | Line 41... | |||
41 | return int.Parse(match.Result("${id}")) == int.Parse(Constants.ID); |
41 | return int.Parse(match.Result("${id}")) == int.Parse(Constants.ID); |
|
42 | } |
42 | } |
|
Line 43... | Line 43... | |||
43 | |
43 | |
|
44 | public override async Task<bool> ReadAsync(CancellationToken cancellationToken) |
44 | public override async Task<bool> ReadAsync(CancellationToken cancellationToken) |
|
45 | { |
45 | { |
|
46 | var payload = Constants.Encoding.GetBytes($"{Name}{Generic.Constants.EOT}"); |
46 | var payload = Constants.Encoding.GetBytes($"{Name}{Constants.EOT}"); |
|
47 | await SerialPort.WriteAsync(payload, 0, payload.Length); |
47 | await SerialPort.WriteAsync(payload, 0, payload.Length); |
|
48 | var buffer = new byte[CatLength.Answer]; |
48 | var buffer = new byte[CatLength.Answer]; |
|
49 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer) != CatLength.Answer) |
49 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer) != CatLength.Answer) |
|
50 | { |
50 | { |