增加报警信息代码
This commit is contained in:
@@ -60,5 +60,48 @@ namespace JY.DAL
|
||||
{ "CCDI5", "左面凹坑数量" },
|
||||
{ "CCDI6", "右面凹坑数量" }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 报警地址信息: 起始地址-长度(分组数,每个分组10个寄存器)
|
||||
/// </summary>
|
||||
public static readonly Dictionary<int, ushort> AlarmAddressDic = new Dictionary<int, ushort>()
|
||||
{
|
||||
{ 10010, 15 }
|
||||
};
|
||||
|
||||
// 展开后的平铺映射表:Key为连续的位索引(0, 1, 2...),Value为实际的物理地址
|
||||
public static readonly Dictionary<int, int> FlatAddressMap = new Dictionary<int, int>();
|
||||
|
||||
/// <summary>
|
||||
/// 根据数组索引获取对应的物理地址
|
||||
/// </summary>
|
||||
public static int GetAddressByIndex(int index)
|
||||
{
|
||||
if (FlatAddressMap.TryGetValue(index, out int address))
|
||||
{
|
||||
return address;
|
||||
}
|
||||
throw new IndexOutOfRangeException($"索引 {index} 超出了地址字典的映射范围。");
|
||||
}
|
||||
|
||||
static ConstValue()
|
||||
{
|
||||
FlatAddressMap = new Dictionary<int, int>();
|
||||
int bitIndex = 0;
|
||||
|
||||
// 按起始地址排序,确保映射顺序正确
|
||||
foreach (var kvp in AlarmAddressDic.OrderBy(x => x.Key))
|
||||
{
|
||||
int startAddress = kvp.Key;
|
||||
ushort length = kvp.Value;
|
||||
|
||||
// 将当前段的每一位索引映射到具体的物理地址
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
FlatAddressMap[bitIndex] = startAddress + i;
|
||||
bitIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user