Files
1440WGJ/JY.DAL/ConstValue.cs
T
2026-09-08 08:54:09 +08:00

108 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JY.DAL
{
public class ConstValue
{
/// <summary>
/// CCD的OK/NG数量
/// </summary>
//public const int CCD_SCount = 16;
public const string CCD_OK = "OK";
public const string CCD_NG = "NG";
public static readonly Dictionary<string, string> CCD_SDict = new Dictionary<string, string>()
{
{ "CCD1", "正面侧面_3D" },
{ "CCD2", "正面侧面_2D" },
{ "CCD3", "正面底面棱_3D" },
{ "CCD4", "后面右侧面_2D" },
{ "CCD5", "后面底面棱_3D" },
{ "CCD6", "极柱面_3D" },
{ "CCD7", "极柱面_2D" },
{ "CCD8", "底面_3D" },
{ "CCD9", "底面_2D" },
{ "CCD10", "左中间棱_3D" },
{ "CCD11", "右中间棱_3D" },
{ "CCD12", "防爆阀_2D" },
{ "CCD13", "左右极柱_2D" },
{ "CCD14", "L胶检测结果" },
{ "CCD15", "二维码等级判定结果" }
};
/// <summary>
/// CCD的浮点数数量
/// </summary>
//public const int CCD_FCount = 3;
public static readonly Dictionary<string, string> CCD_FDict = new Dictionary<string, string>()
{
{ "CCDF1", "大面平面度" },
{ "CCDF2", "侧面平面度" },
{ "CCDF3", "底面平面度" }
};
/// <summary>
/// CCD的整数数量
/// </summary>
//public const int CCD_ICount = 6;
public static readonly Dictionary<string, string> CCD_IDict = new Dictionary<string, string>()
{
{ "CCDI1", "通道" },
{ "CCDI2", "下面凹坑数量" },
{ "CCDI3", "前面凹坑数量" },
{ "CCDI4", "后面凹坑数量" },
{ "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++;
}
}
}
}
}