HamBook – Diff between revs 24 and 46
?pathlinks?
Rev 24 | Rev 46 | |||
---|---|---|---|---|
Line 20... | Line 20... | |||
20 | |
20 | |
|
Line 21... | Line 21... | |||
21 | public override CatLength CatLength => new CatLength { Set = 6, Read = 3, Answer = 6 }; |
21 | public override CatLength CatLength => new CatLength { Set = 6, Read = 3, Answer = 6 }; |
|
22 | |
22 | |
|
23 | public PC(SerialPortStream serialPort) : base(serialPort) |
23 | public PC(SerialPortStream serialPort) : base(serialPort) |
|
24 | { |
24 | { |
|
Line 25... | Line 25... | |||
25 | readRegex = new Regex($"^{Name}(?<power>[0-9]{{3}}){HamBook.Radios.Generic.Constants.EOT}$", RegexOptions.Compiled); |
25 | readRegex = new Regex($"^{Name}(?<power>[0-9]{{3}}){Constants.EOT}$", RegexOptions.Compiled); |
|
26 | } |
26 | } |
|
27 | |
27 | |
|
28 | public override int Read() |
28 | public override int Read() |
|
29 | { |
29 | { |
|
30 | SerialPort.Write($"{Name}{Generic.Constants.EOT}"); |
30 | SerialPort.Write($"{Name}{Constants.EOT}"); |
|
31 | var buffer = new byte[CatLength.Answer]; |
31 | var buffer = new byte[CatLength.Answer]; |
|
32 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
32 | if (SerialPort.Read(buffer, 0, CatLength.Answer) != CatLength.Answer) |
|
Line 43... | Line 43... | |||
43 | return int.Parse(match.Result("${power}")); |
43 | return int.Parse(match.Result("${power}")); |
|
44 | } |
44 | } |
|
Line 45... | Line 45... | |||
45 | |
45 | |
|
46 | public override async Task<int> ReadAsync(CancellationToken cancellationToken) |
46 | public override async Task<int> ReadAsync(CancellationToken cancellationToken) |
|
47 | { |
47 | { |
|
48 | var payload = Constants.Encoding.GetBytes($"{Name}{Generic.Constants.EOT}"); |
48 | var payload = Constants.Encoding.GetBytes($"{Name}{Constants.EOT}"); |
|
49 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
49 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
50 | var buffer = new byte[CatLength.Answer]; |
50 | var buffer = new byte[CatLength.Answer]; |
|
51 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer) |
51 | if (await SerialPort.ReadAsync(buffer, 0, CatLength.Answer, cancellationToken) != CatLength.Answer) |
|
52 | { |
52 | { |
|
Line 63... | Line 63... | |||
63 | return int.Parse(match.Result("${power}")); |
63 | return int.Parse(match.Result("${power}")); |
|
64 | } |
64 | } |
|
Line 65... | Line 65... | |||
65 | |
65 | |
|
66 | public override bool Set(int power) |
66 | public override bool Set(int power) |
|
67 | { |
67 | { |
|
Line 68... | Line 68... | |||
68 | var payload = Constants.Encoding.GetBytes($"{Name}{power:000}{Generic.Constants.EOT}"); |
68 | var payload = Constants.Encoding.GetBytes($"{Name}{power:000}{Constants.EOT}"); |
|
Line 69... | Line 69... | |||
69 | |
69 | |
|
70 | SerialPort.Write(payload, 0, payload.Length); |
70 | SerialPort.Write(payload, 0, payload.Length); |
|
Line 71... | Line 71... | |||
71 | |
71 | |
|
72 | return Read() == power; |
72 | return Read() == power; |
|
73 | } |
73 | } |
|
Line 74... | Line 74... | |||
74 | |
74 | |
|
Line 75... | Line 75... | |||
75 | public override async Task<bool> SetAsync(int power, CancellationToken cancellationToken) |
75 | public override async Task<bool> SetAsync(int power, CancellationToken cancellationToken) |
|
Line 76... | Line 76... | |||
76 | { |
76 | { |
|
77 | var payload = Constants.Encoding.GetBytes($"{Name}{power:000}{Generic.Constants.EOT}"); |
77 | var payload = Constants.Encoding.GetBytes($"{Name}{power:000}{Constants.EOT}"); |
|
Line 78... | Line 78... | |||
78 | |
78 | |
|
79 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
79 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
80 | |
80 | |
|
81 | var result = await ReadAsync(cancellationToken); |
81 | var result = await ReadAsync(cancellationToken); |
|
Line 82... | Line 82... | |||
82 | |
82 | |
|
83 | return result == power; |
83 | return result == power; |
|
84 | } |
84 | } |
|
Line 85... | Line 85... | |||
85 | |
85 | |
|
86 | public override void Write(int power) |
86 | public override void Write(int power) |
|
87 | { |
87 | { |
|
88 | SerialPort.Write($"{Name}{power:000}{Generic.Constants.EOT}"); |
88 | SerialPort.Write($"{Name}{power:000}{Constants.EOT}"); |