ConfigItemBase.cs
11.6 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlineStore.LoadCSVLibrary
{
/// <summary>
/// 基础的属性配置
/// </summary>
public class ConfigBase
{
public string DataStr = "";
// protected static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// DI=输入IO,DO=输出IO,PRO=属性,AXIS=轴
/// </summary>
[CSVAttribute("类型")]
public string ProType { get; set; }
/// <summary>
/// 说明
/// </summary>
[CSVAttribute("说明")]
public string Explain { get; set; }
/// <summary>
/// 名称
/// </summary>
[CSVAttribute("名称")]
public string ProName { get; set; }
/// <summary>
/// 属性值
/// </summary>
[CSVAttribute("属性值")]
public string ProVale { get; set; }
public ushort GetIOAddr()
{
ushort value = 0;
try
{
value = (ushort)Convert.ToInt32(ProVale);
}
catch (Exception ex)
{
LogUtil.error("出错:", ex);
}
return value;
}
public virtual int GetValue()
{
if (ProVale.Equals(""))
{
return -1;
}
return Convert.ToInt32(ProVale);
}
public override string ToString()
{
return "ConfigBase。" + "类型:" + ProType + ",说明:" + Explain + ",名称:" + ProName + ",属性值:" + ProVale;
}
public virtual void CheckField()
{
if (String.IsNullOrEmpty(ProType) || String.IsNullOrEmpty(ProName) || String.IsNullOrEmpty(ProVale))
{
throw new CVSFieldNotMatchingExection("["+ToString() + "],【类型:ProType】【名称:ProName】【属性值:ProVale】必须配置值!");
}
}
}
/// <summary>
/// 运动轴配置
/// </summary>
public class ConfigMoveAxis : ConfigBase
{
/// <summary>
/// 使用AC伺服时表示串口号,使用康泰克运动版表示板卡名称
/// </summary>
[CSVAttribute("设备名称")]
public string DeviceName { get; set; }
// 目标速度 加速时间 减速时间 原点低速度 原点高速 原点加速度 脉冲最小误差 脉冲最大误差 脉冲最小限位 脉冲最大限位
/// <summary>
/// 待机位置
/// </summary>
//[CSVAttribute("默认值")]
public int DefaultPosition { get; set; }
/// <summary>
/// 目标速度
/// </summary>
[CSVAttribute("目标速度")]
public int TargetSpeed { get; set; }
/// <summary>
/// 加速度
/// </summary>
[CSVAttribute("加速时间")]
public short AddSpeed { get; set; }
/// <summary>
/// 减速度
/// </summary>
[CSVAttribute("减速时间")]
public short DelSpeed { get; set; }
[CSVAttribute("原点低速度")]
public int HomeLowSpeed { get; set; }
[CSVAttribute("原点高速")]
public int HomeHighSpeed { get; set; }
[CSVAttribute("原点加速度")]
public int HomeAddSpeed { get; set; }
/// <summary>
/// 可以误差的脉冲范围的最小值
/// </summary>
[CSVAttribute("脉冲最小误差")]
public int CanErrorCountMin { get; set; }
/// <summary>
/// 可以误差的脉冲范围的最大值
/// </summary>
[CSVAttribute("脉冲最大误差")]
public int CanErrorCountMax { get; set; }
/// <summary>
/// 出入库目标值(只有出入库过程中才会有效)
/// </summary>
public int TargetPosition { get; set; }
/// <summary>
/// 最小位置
/// </summary>
[CSVAttribute("脉冲最小限位")]
public int PositionMin { get; set; }
/// <summary>
/// 最大位置
/// </summary>
[CSVAttribute("脉冲最大限位")]
public int PositionMax { get; set; }
public string Axis_Brake_DO = "";
public string Axis_Run_DO = "";
public string GetNameStr()
{
return DeviceName + "_" + GetAxisValue();
}
public bool IsSameAxis(string portName, int slv)
{
if (DeviceName.Equals(portName) && slv.Equals(GetAxisValue()))
{
return true;
}
return false;
}
public bool PositionIsHasLimit()
{
if (PositionMin.Equals(PositionMax))
{
return false;
}
return true;
}
/// <summary>
/// 下拉列表显示
/// </summary>
public string DisplayStr
{
get {
return Explain + "(" + ProName + ")";
}
set
{
}
}
public override int GetValue()
{
return GetAxisValue();
}
/// <summary>
/// 使用康泰克板卡表示轴编号,使用Ac伺服电机表示伺服地址
/// </summary>
/// <returns></returns>
public short GetAxisValue()
{
if (ProVale.Equals("") || ProVale.Equals("-1"))
{
return -1;
}
return (short)Convert.ToInt32(ProVale);
}
public override string ToString()
{
return "ConfigMoveAxis。" + "类型:" + ProType + ",说明:" + Explain + ",名称:" + ProName + ",属性值:" + ProVale + ",设备名称:" + DeviceName;
}
public override void CheckField()
{
if (String.IsNullOrEmpty( ProType) || String.IsNullOrEmpty( ProName ) || String.IsNullOrEmpty( DeviceName ) || String.IsNullOrEmpty( ProVale ))
{
throw new CVSFieldNotMatchingExection(ToString() + ",【类型:ProType】【名称:ProName】【属性值:ProVale】【设备名称:DeviceName】必须配置值!");
}
}
public bool IsMyAxis(string DeviceName, int AxisNo)
{
int AxisValue = GetAxisValue();
if (DeviceName.Equals(DeviceName) && AxisValue.Equals(AxisNo))
{
return true;
}
return false;
}
public void SetParam(int targetSpeed,short addSpeed, short delSpeed,int homeAddSpeed,int homeHighSpeed,int homeLowSpeed,int defP1)
{
TargetSpeed = addSpeed;
AddSpeed = addSpeed;
DelSpeed = delSpeed;
HomeAddSpeed = homeAddSpeed;
HomeHighSpeed = homeHighSpeed;
HomeLowSpeed = homeLowSpeed;
DefaultPosition = defP1;
}
}
/// <summary>
/// io配置
/// </summary>
public class ConfigIO : ConfigBase
{
public ConfigIO()
{
SlaveID = 0;
}
/// <summary>
/// 设备名称
/// </summary>
[CSVAttribute("设备名称")]
public string DeviceName { get; set; }
/// <summary>
/// 描述
/// </summary>
[CSVAttribute("描述")]
public string Describe { get; set; }
/// <summary>
/// 电器定义
/// </summary>
[CSVAttribute("电器定义")]
public string ElectricalDefinition { get; set; }
/// <summary>
/// 代码定义
/// </summary>
[CSVAttribute("代码定义")]
public string CodeDefinition { get; set; }
public byte SlaveID = 0;
private int IoValue = -10;
public string DisplayStr
{
get
{
return ElectricalDefinition + "_" + Explain + "(" + ProName+")";
}
set
{
}
}
public override int GetValue()
{
return GetIOValue();
}
public string IO_IP
{
get
{
return DeviceName;
}
}
public int GetIOValue()
{
if (IoValue >= -1)
{
return IoValue;
}
try
{
if (ProVale.Equals("") || ProVale.Equals("-1"))
{
IoValue = -1;
}
else if (ProType.Equals(ConfigItemType.DI))
{
IoValue = Convert.ToInt32(ProVale, 8);
}
else if (ProType.Equals(ConfigItemType.DO))
{
if (ProVale.Length == 2)
{
int a = Convert.ToInt32(ProVale.Substring(0, 1), 16) - 8;
string str =a+ProVale.Substring(1,1);
IoValue = Convert.ToInt32( str, 8);
//IoValue = a + b;
}
else
{
IoValue = Convert.ToInt32(ProVale, 16) - Convert.ToInt32("80", 16);
}
}
//LOGGER.Info("IO转换:(" + ElectricalDefinition + ")" + ProVale + "=" + IoValue);
}
catch (Exception ex)
{
LogUtil.error ("出错了:", ex);
return -1;
}
return IoValue;
}
public override string ToString()
{
return "ConfigIO。" + ProType + "," + Explain + "," + ProName + ",属性值:" + ProVale + ",设备名称:" + DeviceName + ",描述:" + Describe + ",电器定义:" + ElectricalDefinition + ",代码定义:" + CodeDefinition + "";
}
public override void CheckField()
{
if (String.IsNullOrEmpty(ProType) || String.IsNullOrEmpty(ProName) || String.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(ProVale))
{
throw new CVSFieldNotMatchingExection(ToString() + ",【类型:ProType】【名称:ProName】【属性值:ProVale】【设备名称:DeviceName】必须配置值!");
}
}
}
public static class ConfigItemType
{
public static string DI = "DI";
public static string DO = "DO";
public static string AXIS = "AXIS";
public static string PRO = "PRO";
}
public static class ConfigItemName
{
/// <summary>
/// 上下转动轴
/// </summary>
public static string UpDown_Axis = "UpDown_Axis";
/// <summary>
/// 中转伝动轴 Middle_Axis
/// </summary>
public static string Middle_Axis = "Middle_Axis";
/// <summary>
/// 中轴移动速度 MiddleAxis_Move_Speed
/// </summary>
public static string MiddleAxis_Move_Speed = "MiddleAxis_Move_Speed";
/// <summary>
/// 上下轴普通速度 Updown_Move_Speed
/// </summary>
public static string Updown_Move_Speed = "Updown_Move_Speed";
/// <summary>
/// 上下轴慢速度 Updown_Move_Speed_Low
/// </summary>
public static string Updown_Move_Speed_Low = "Updown_Move_Speed_Low";
/// <summary>
/// 温湿度传感器地址 Temperate_ServerAddress
/// </summary>
public static string Temperate_ServerAddress = "Temperate_ServerAddress";
}
}