/
DigitalDefinitionBase.cs
executable file
·139 lines (127 loc) · 5.79 KB
/
DigitalDefinitionBase.cs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//******************************************************************************************************
// DigitalDefinitionBase.cs - Gbtc
//
// Copyright © 2012, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
//
// http://www.opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 02/18/2005 - J. Ritchie Carroll
// Generated original version of source code.
// 09/15/2009 - Stephen C. Wills
// Added new header and license agreement.
// 10/5/2012 - Gavin E. Holden
// Added new header and license agreement.
// 12/17/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
namespace GSF.PhasorProtocols
{
/// <summary>
/// Represents the common implementation of the protocol independent definition of a <see cref="IDigitalValue"/>.
/// </summary>
[Serializable]
public abstract class DigitalDefinitionBase : ChannelDefinitionBase, IDigitalDefinition
{
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="DigitalDefinitionBase"/>.
/// </summary>
/// <param name="parent">The <see cref="IConfigurationCell"/> parent of this <see cref="DigitalDefinitionBase"/>.</param>
protected DigitalDefinitionBase(IConfigurationCell parent)
: base(parent)
{
ScalingValue = 1;
Offset = 0.0D;
}
/// <summary>
/// Creates a new <see cref="DigitalDefinitionBase"/> from specified parameters.
/// </summary>
/// <param name="parent">The <see cref="IConfigurationCell"/> parent of this <see cref="DigitalDefinitionBase"/>.</param>
/// <param name="label">The label of this <see cref="DigitalDefinitionBase"/>.</param>
protected DigitalDefinitionBase(IConfigurationCell parent, string label)
: base(parent, label, 1, 0.0D)
{
}
/// <summary>
/// Creates a new <see cref="DigitalDefinitionBase"/> from serialization parameters.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> with populated with data.</param>
/// <param name="context">The source <see cref="StreamingContext"/> for this deserialization.</param>
protected DigitalDefinitionBase(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets the <see cref="PhasorProtocols.DataFormat"/> of this <see cref="DigitalDefinitionBase"/>.
/// </summary>
/// <remarks>
/// Data format for digital values will always be <see cref="DataFormat.FixedInteger"/>.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed override DataFormat DataFormat => DataFormat.FixedInteger;
/// <summary>
/// Gets or sets the offset of this <see cref="DigitalDefinitionBase"/>.
/// </summary>
/// <remarks>
/// Offset for digital values will always be 0; assigning a value other than 0 will thrown an exception.
/// </remarks>
/// <exception cref="NotImplementedException">Digital values represent bit flags and thus do not support an offset.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed override double Offset
{
get => base.Offset;
set
{
if (value == 0)
base.Offset = value;
else
throw new NotImplementedException("Digital values represent bit flags and thus do not support an offset");
}
}
/// <summary>
/// Gets or sets the integer scaling value of this <see cref="DigitalDefinitionBase"/>.
/// </summary>
/// <remarks>
/// Scaling value for digital values will always be 1; assigning a value other than 1 will thrown an exception.
/// </remarks>
/// <exception cref="NotImplementedException">Digital values represent bit flags and thus are not scaled.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed override uint ScalingValue
{
get => base.ScalingValue;
set
{
if (value == 1)
base.ScalingValue = value;
else
throw new NotImplementedException("Digital values represent bit flags and thus are not scaled");
}
}
/// <summary>
/// Gets the scale/bit for the <see cref="ScalingValue"/> of this <see cref="DigitalDefinitionBase"/>.
/// </summary>
/// <remarks>
/// Scale/bit for digital values will always be 1.0.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed override double ScalePerBit => 1.0D;
#endregion
}
}