HamBook – Diff between revs 35 and 46
?pathlinks?
Rev 35 | Rev 46 | |||
---|---|---|---|---|
Line 20... | Line 20... | |||
20 | |
20 | |
|
Line 21... | Line 21... | |||
21 | public override CatLength CatLength => new CatLength { Set = 4, Read = 3, Answer = 4 }; |
21 | public override CatLength CatLength => new CatLength { Set = 4, Read = 3, Answer = 4 }; |
|
22 | |
22 | |
|
23 | public TX(SerialPortStream serialPort) : base(serialPort) |
23 | public TX(SerialPortStream serialPort) : base(serialPort) |
|
24 | { |
24 | { |
|
Line 25... | Line 25... | |||
25 | readRegex = new Regex($"^{Name}(?<state>[0-9]){HamBook.Radios.Generic.Constants.EOT}$", RegexOptions.Compiled); |
25 | readRegex = new Regex($"^{Name}(?<state>[0-9]){Constants.EOT}$", RegexOptions.Compiled); |
|
26 | } |
26 | } |
|
27 | |
27 | |
|
28 | public override TxState Read() |
28 | public override TxState 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 (TxState)int.Parse(match.Result("${state}")); |
43 | return (TxState)int.Parse(match.Result("${state}")); |
|
44 | } |
44 | } |
|
Line 45... | Line 45... | |||
45 | |
45 | |
|
46 | public override async Task<TxState> ReadAsync(CancellationToken cancellationToken) |
46 | public override async Task<TxState> 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 (TxState)int.Parse(match.Result("${state}")); |
63 | return (TxState)int.Parse(match.Result("${state}")); |
|
64 | } |
64 | } |
|
Line 65... | Line 65... | |||
65 | |
65 | |
|
66 | public override bool Set(TxState state) |
66 | public override bool Set(TxState state) |
|
67 | { |
67 | { |
|
Line 68... | Line 68... | |||
68 | var payload = Constants.Encoding.GetBytes($"{Name}{(int)state}{Generic.Constants.EOT}"); |
68 | var payload = Constants.Encoding.GetBytes($"{Name}{(int)state}{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() == state; |
72 | return Read() == state; |
|
73 | } |
73 | } |
|
Line 74... | Line 74... | |||
74 | |
74 | |
|
Line 75... | Line 75... | |||
75 | public override async Task<bool> SetAsync(TxState state, CancellationToken cancellationToken) |
75 | public override async Task<bool> SetAsync(TxState state, CancellationToken cancellationToken) |
|
76 | { |
76 | { |
|
Line 77... | Line 77... | |||
77 | var payload = Constants.Encoding.GetBytes($"{Name}{(int)state}{Generic.Constants.EOT}"); |
77 | var payload = Constants.Encoding.GetBytes($"{Name}{(int)state}{Constants.EOT}"); |
|
78 | |
78 | |
|
79 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
79 | await SerialPort.WriteAsync(payload, 0, payload.Length, cancellationToken); |
|
80 | |
80 | |
|
Line 81... | Line 81... | |||
81 | return await ReadAsync(cancellationToken) == state; |
81 | return await ReadAsync(cancellationToken) == state; |
|
82 | } |
82 | } |
|
83 | |
83 | |
|
Line 84... | Line 84... | |||
84 | public override void Write(TxState state) |
84 | public override void Write(TxState state) |
|
85 | { |
85 | { |
|
86 | SerialPort.Write($"{Name}{(int)state}{Generic.Constants.EOT}"); |
86 | SerialPort.Write($"{Name}{(int)state}{Constants.EOT}"); |
|
87 | } |
87 | } |