-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathReadBitsEventArgs.cs
More file actions
76 lines (67 loc) · 2.2 KB
/
ReadBitsEventArgs.cs
File metadata and controls
76 lines (67 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections;
namespace Waher.Networking.Modbus
{
/// <summary>
/// Event arguments for read bits event.
/// </summary>
public class ReadBitsEventArgs : EventArgs
{
/// <summary>
/// Event arguments for read bits event.
/// </summary>
/// <param name="UnitAddress">Request was made for device at this unit address.</param>
/// <param name="ReferenceNr">Read is to start at this reference number.</param>
/// <param name="NrBits">This number of bits has been requested to be read.</param>
/// <param name="Bits">Bits read is to be placed in this array.</param>
public ReadBitsEventArgs(ushort UnitAddress, ushort ReferenceNr, ushort NrBits,
BitArray Bits)
{
this.UnitAddress = UnitAddress;
this.ReferenceNr = ReferenceNr;
this.NrBits = NrBits;
this.Bits = Bits;
}
/// <summary>
/// Request was made for device at this unit address.
/// </summary>
public ushort UnitAddress { get; }
/// <summary>
/// Read is to start at this reference number.
/// </summary>
public ushort ReferenceNr { get; }
/// <summary>
/// This number of bits has been requested to be read.
/// </summary>
public ushort NrBits { get; }
/// <summary>
/// Bits read is to be placed in this array.
/// </summary>
public BitArray Bits { get; }
/// <summary>
/// Access to register values.
/// </summary>
/// <param name="RegisterNr">Register number.</param>
/// <returns>Boolean value of corresponding register.</returns>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="RegisterNr"/> is below
/// <see cref="ReferenceNr"/> or greater or equal to <see cref="ReferenceNr"/> +
/// <see cref="NrBits"/>.</exception>
public bool this[int RegisterNr]
{
get
{
RegisterNr -= this.ReferenceNr;
if (RegisterNr < 0 || RegisterNr >= this.Bits.Length)
throw new ArgumentOutOfRangeException(nameof(RegisterNr), "Register index out of range.");
return this.Bits[RegisterNr];
}
set
{
RegisterNr -= this.ReferenceNr;
if (RegisterNr < 0 || RegisterNr >= this.Bits.Length)
throw new ArgumentOutOfRangeException(nameof(RegisterNr), "Register index out of range.");
this.Bits[RegisterNr] = value;
}
}
}
}