海波 张
2025-05-09 2c28bf13ba0b985f68deb94cd85d78f588eff8e0
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static HH.WCS.ZhongCeJinTan.util.Settings;
 
namespace HH.WCS.ZhongCeJinTan.util
{
    public class Settings
    {
       
      
        public static string SqlServer { get; set; }
 
        public static string TmDeviceIp { get; set; }
 
        public static int TmDevicePort { get; set; }
 
        public static List<safetyLocation> safetyLocations { get; set; }
        public static string WcsApiAddres { get; set; }
 
        /// <summary>
        /// 空托缓存区
        /// </summary>
        public static string EmptyPalletBufferArea { get; set; }
 
        /// <summary>
        /// Mes获取物料信息接口地址
        /// </summary>
        public static string MesGetItemApi { get; set; }
        
        public static List<deviceInfo> deviceInfos { get; set; }
 
 
        public static List<TmDeviceInfo> TmDeviceInfos { get; set; }
 
        public static List<areaInfo> areaInfos { get; set; }
 
 
        public static string NDCApiUrl { get; set; }
        
 
        public static void Init() {
            LogHelper.Info("加载配置文件信息 开始");
            try {
                var jsonFile = System.AppDomain.CurrentDomain.BaseDirectory + "/config/config.json";
                using (System.IO.StreamReader file = System.IO.File.OpenText(jsonFile)) {
                    using (JsonTextReader reader = new JsonTextReader(file)) {
                        JObject o = (JObject)JToken.ReadFrom(reader);
                        foreach (Newtonsoft.Json.Linq.JProperty keyValue in o.Properties()) {
                            Console.WriteLine(keyValue.Name);
                            if (keyValue.Name == "TableName") {
                                var list = JsonConvert.DeserializeObject<List<TableName>>(keyValue.Value.ToString());
                                list.ForEach(a => STAttribute.attributes.Add(a.name, a.code));
                            }
                            if (keyValue.Name == "SqlServer") {
                                SqlServer = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "WcsApiAddres")
                            {
                                WcsApiAddres = keyValue.Value.ToString();
                            }
 
                            if (keyValue.Name == "MesGetItemApi")
                            {
                                MesGetItemApi = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "NDCApiUrl")
                            {
                                NDCApiUrl = keyValue.Value.ToString();
                            }
 
                            if (keyValue.Name == "TmDeviceIp")
                            {
                                TmDeviceIp = keyValue.Value.ToString();
                            }
 
                            if (keyValue.Name == "TmDevicePort")
                            {
                                TmDevicePort = (int)keyValue.Value;
                            }
                            if (keyValue.Name == "EmptyPalletBufferArea")
                            {
                                EmptyPalletBufferArea = keyValue.Value.ToString();
                            }
                            
 
                            if (keyValue.Name == "SafetyLocation")
                            {
                                safetyLocations = JsonConvert.DeserializeObject<List<safetyLocation>>(keyValue.Value.ToString());
                            }
 
                            if (keyValue.Name == "TmDevice")
                            {
                                TmDeviceInfos = JsonConvert.DeserializeObject<List<TmDeviceInfo>>(keyValue.Value.ToString());
                            }
                            //if (keyValue.Name == "DeviceInfo")
                            //{
                            //    deviceInfos = JsonConvert.DeserializeObject<List<deviceInfo>>(keyValue.Value.ToString());
                            //}
                            //if (keyValue.Name == "AreaInfo")
                            //{
                            //   areaInfos = JsonConvert.DeserializeObject<List<areaInfo>>(keyValue.Value.ToString());
                            //}
                        }
                    }
                }
                LogHelper.Info("加载配置文件信息 完成");
            }
            catch (Exception ex) {
                LogHelper.Error("加载配置文件失败!" + ex.Message, ex);
            }
 
        }
 
        public class TmDeviceInfo
        {
            public string deviceName { get; set; }
            public string locCode { get; set; }
            public int deviceType { get; set; }
            public int enable { get; set; }
            public int beginAddr { get; set; }
            public int writeSafetyAddr { get; set; }
            public int writeSafetyAddr1 { get; set; }
            public int readSafetyAddr { get; set; }
            public int readSafetyAddr1 { get; set; }
            public int endAddr { get; set; }
        }
 
        public class deviceInfo
        {
            public string address { get; set; }
            public string deviceName { get; set; }
            public string[] deviceNo { get; set; }
            public string[] location { get; set; }
 
            public int deviceType { get; set; }
            public int enable { get; set; }
        }
 
        public class areaInfo
        {
      
            public string[] startArea { get; set; }
            public string[] endArea { get; set; }
 
            public string carType { get; set; }
         
        }
 
   
 
 
     public class safetyLocation
        {
        public string name { get; set; }
        public List<string> Area { get; set; }
 
        public int type{ get; set; }
    }
 
    public class TableName
        {
            public string name { get; set; }
            public string code { get; set; }
        }
 
        public class EndLoc
        {
            public string[] location;
        }
 
        public class zoneInfo
        {
            public string zone { get; set; }
            public string deviceName { get; set; }
            /// <summary>
            /// </summary>
            public int zoneType { get; set; }
            public int[] rows { get; set; }
 
            public int bits { get; set; }
        }
        public class zoneInfo1
        {
            public string deviceName { get; set; }
            /// <summary>
            /// 库区列表,按数组下标顺序选择
            /// </summary>
            public string[] zone { get; set; }
 
            public int zoneType { get; set; }
        }
 
      
        public class tpZone
        {
            public string zone { get; set; }
            public string deviceName { get; set; }
            /// <summary>
            /// </summary>
            public int zoneType { get; set; }
            public int bits { get; set; }
 
            public string address { get; set; }
        }
 
    }
}