GetConfig.cs
5.8 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
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
using System;
using System.Collections.Generic;
using CameraVisionLib.Model;
namespace Asa.Camera
{
public partial class VisionLib : IDisposable
{
private void GetConfig(string path)
{
Common.log.Debug("GetConfig Path=" + path);
scanParam = new();
regionLists = new();
ipCameraInfos = new();
if (!System.IO.File.Exists(path)) return;
string json = System.IO.File.ReadAllText(path);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new();
Dictionary<string, object> dic = (Dictionary<string, object>)serializer.DeserializeObject(json);
if (dic.TryGetValue("CodeOrder", out object value))
GetConfig_CodeOrder(value);
if (dic.TryGetValue("Halcon", out value))
GetConfig_Halcon(value);
if (dic.TryGetValue("EyemLib", out value))
GetConfig_EyemLib(value);
if (dic.TryGetValue("Region", out value))
GetConfig_Region(value);
if (dic.TryGetValue("HIKIPCamera", out value))
GetConfig_HIKIPCamera(value);
}
private void GetConfig_CodeOrder(object param)
{
Common.log.Debug("GetConfig_CodeOrder");
scanParam.CodeOrder = (ScanCodeOrder)Enum.Parse(typeof(ScanCodeOrder), param.ToString());
}
private void GetConfig_Halcon(object param)
{
Common.log.Debug("GetConfig_Halcon");
Dictionary<string, object> dict = (Dictionary<string, object>)param;
if (dict.TryGetValue("CodeType", out object value))
scanParam.HalconType = (CodeType)Enum.Parse(typeof(CodeType), value.ToString());
if (dict.TryGetValue("Zoom1DCode", out value))
scanParam.Zoom1D = Convert.ToSingle(value);
if (dict.TryGetValue("Zoom2DCode", out value))
scanParam.Zoom2D = Convert.ToSingle(value);
}
private void GetConfig_EyemLib(object param)
{
Common.log.Debug("GetConfig_EyemLib");
Dictionary<string, object> dict = (Dictionary<string, object>)param;
if (dict.TryGetValue("CodeType", out object value))
scanParam.EyemType = (CodeType)Enum.Parse(typeof(CodeType), value.ToString());
if (dict.TryGetValue("BlockSize", out value))
scanParam.EyemBlockSize = Convert.ToInt32(value);
if (dict.TryGetValue("RangeC", out value))
scanParam.EyemRangeC = Convert.ToInt32(value);
if (dict.TryGetValue("SymbolMin", out value))
scanParam.EyemSymbolMin = Convert.ToInt32(value);
if (dict.TryGetValue("SymbolMax", out value))
scanParam.EyemSymbolMax = Convert.ToInt32(value);
}
private void GetConfig_Region(object param)
{
Common.log.Debug("GetConfig_Region");
Dictionary<string, object> dict = (Dictionary<string, object>)param;
foreach (string cameraKey in dict.Keys)
{
List<RegionPlan> planList = new();
Dictionary<string, object> list = (Dictionary<string, object>)dict[cameraKey];
foreach (string listKey in list.Keys)
{
List<RegionInfo> infoLists = new();
object[] obj = (object[])list[listKey];
for (int i = 0; i < obj.Length; i++)
{
Dictionary<string, object> regionParam = (Dictionary<string, object>)obj[i];
string name = "";
int x = 0, y = 0, w = 0, h = 0;
double r = 0;
if (regionParam.TryGetValue("RegionName", out object value))
name = value.ToString();
if (regionParam.TryGetValue("X", out value))
int.TryParse(value.ToString(), out x);
if (regionParam.TryGetValue("Y", out value))
int.TryParse(value.ToString(), out y);
if (regionParam.TryGetValue("Width", out value))
int.TryParse(value.ToString(), out w);
if (regionParam.TryGetValue("Height", out value))
int.TryParse(value.ToString(), out h);
if (regionParam.TryGetValue("Ratio", out value))
double.TryParse(value.ToString(), out r);
infoLists.Add(new RegionInfo(name, x, y, w, h, r));
}
planList.Add(new RegionPlan(listKey, infoLists));
}
regionLists.Add(cameraKey, planList);
}
}
private void GetConfig_HIKIPCamera(object param)
{
Common.log.Debug("GetConfig_HIKIPCamera");
object[] obj = (object[])param;
for (int i = 0; i < obj.Length; i++)
{
Dictionary<string, object> dict = (Dictionary<string, object>)obj[i];
IPCameraInfo item = new();
System.Reflection.PropertyInfo[] info = item.GetType().GetProperties();
for (int j = 0; j < info.Length; j++)
{
if (dict.TryGetValue(info[j].Name, out object value))
{
if (info[j].PropertyType == typeof(string))
info[j].SetValue(item, value.ToString());
else if (info[j].PropertyType == typeof(int))
info[j].SetValue(item, Convert.ToInt32(value));
}
}
ipCameraInfos.Add(item);
}
}
}
}