|
@@ -1,5 +1,6 @@
|
|
|
using B20UVLog.Models;
|
|
|
using B20UVLog.Pages;
|
|
|
+using NetTaste;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Configuration;
|
|
@@ -78,7 +79,12 @@ namespace B20UVLog
|
|
|
private PlcItemTypeModel AlarmPLC;
|
|
|
private PlcItemTypeModel WarnPLC;
|
|
|
private PlcItemTypeModel IOPLC;
|
|
|
-
|
|
|
+
|
|
|
+ //字典字段
|
|
|
+ private List<DictModel> axleAlarm=new List<DictModel>();
|
|
|
+ private List<DictModel> axleWarn = new List<DictModel>();
|
|
|
+ private List<DictModel> deviceAlarm = new List<DictModel>();
|
|
|
+ private List<DictModel> deviceWarn = new List<DictModel>();
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
@@ -109,7 +115,11 @@ namespace B20UVLog
|
|
|
AlarmPLC = DbHelper.Db.Queryable<PlcItemTypeModel>().First(x => x.PlcItemType == "Alarm");
|
|
|
WarnPLC = DbHelper.Db.Queryable<PlcItemTypeModel>().First(x => x.PlcItemType == "Warn");
|
|
|
IOPLC = DbHelper.Db.Queryable<PlcItemTypeModel>().First(x => x.PlcItemType == "IO");
|
|
|
-
|
|
|
+ //获取字典中的所有字段
|
|
|
+ axleAlarm = DbHelper.Db.Queryable<DictModel>().ToList().FindAll(x=>x.Type=="Alarm"&&x.Code=="Axle");
|
|
|
+ axleWarn = DbHelper.Db.Queryable<DictModel>().ToList().FindAll(x => x.Type == "Warn" && x.Code == "Axle");
|
|
|
+ deviceAlarm = DbHelper.Db.Queryable<DictModel>().ToList().FindAll(x => x.Type == "Alarm" && x.Code == "Device");
|
|
|
+ deviceWarn = DbHelper.Db.Queryable<DictModel>().ToList().FindAll(x => x.Type == "Warn" && x.Code == "Warn");
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 连接PLC
|
|
@@ -179,6 +189,7 @@ namespace B20UVLog
|
|
|
AxisData3LogTask();
|
|
|
AxisData4LogTask();
|
|
|
AxisData5LogTask();
|
|
|
+ ServoAxisStatusLogTask();
|
|
|
GlassInformationLogTask();
|
|
|
LampUserTimeLogTask();
|
|
|
RecipeBodyLogTask();
|
|
@@ -476,11 +487,37 @@ namespace B20UVLog
|
|
|
}
|
|
|
|
|
|
//ToDo:把PLC数据插入到数据库中
|
|
|
- ServoAxisStatusModel axisData = MapPlcItemToObjectProperty<ServoAxisStatusModel>(servoAxisPlcItemLst);
|
|
|
-
|
|
|
- axisData.RecordTime = DateTime.Now;
|
|
|
- DbHelper.Db.Insertable(axisData).ExecuteCommand();
|
|
|
- melsec_net.Write(ServoAxisStautsPLC.ReplyFlagAddress, true);
|
|
|
+ ServoAxisStautsOriginal servoOrignal = MapPlcItemToObjectProperty<ServoAxisStautsOriginal>(servoAxisPlcItemLst);
|
|
|
+
|
|
|
+ //ServoAxisStautsOriginal 将不为0的字段转为ServoAxisStautsModel
|
|
|
+ var nonZeroProperties = GetNonZeroProperties(servoOrignal);
|
|
|
+
|
|
|
+ foreach (var property in nonZeroProperties)
|
|
|
+ {
|
|
|
+ string name = property.Key;
|
|
|
+ int value = property.Value;
|
|
|
+ ServoAxisStatusModel servoAxisStatusModel = new ServoAxisStatusModel();
|
|
|
+ if(name.Contains("Warn"))
|
|
|
+ {
|
|
|
+ servoAxisStatusModel.AxisName = name.Substring(0, 4);
|
|
|
+ servoAxisStatusModel.WarningCode = value;
|
|
|
+ servoAxisStatusModel.WarningDescribe =axleWarn?.FirstOrDefault(x=>x.Key==value.ToString().Trim())?.Value;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (name.Contains("Alarm"))
|
|
|
+ {
|
|
|
+ servoAxisStatusModel.AxisName = name.Substring(0, 4);
|
|
|
+ servoAxisStatusModel.AlarmCode = value;
|
|
|
+ servoAxisStatusModel.AlarmDescribe = axleAlarm?.FirstOrDefault(x => x.Key == value.ToString().Trim())?.Value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ servoAxisStatusModel.RecordTime = DateTime.Now;
|
|
|
+ DbHelper.Db.Insertable(servoAxisStatusModel).ExecuteCommand();
|
|
|
+ melsec_net.Write(ServoAxisStautsPLC.ReplyFlagAddress, true);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -526,8 +563,24 @@ namespace B20UVLog
|
|
|
|
|
|
//ToDo:把PLC数据插入到数据库中
|
|
|
GlassInformationModel glassInfoData = MapPlcItemToObjectProperty<GlassInformationModel>(servoAxisPlcItemLst);
|
|
|
- glassInfoData.LordingTime = DateTime.Now;
|
|
|
- glassInfoData.UnlordingTime = DateTime.Now;
|
|
|
+
|
|
|
+ //读取时间
|
|
|
+ OperateResult<short[]> glassInfoRetTime = melsec_net.ReadInt16("D16100", 6);
|
|
|
+ if (!glassInfoRetTime.IsSuccess || glassInfoRetTime.Content.Length <= 0)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Convert16BitBCDToTwoInts(glassInfoRetTime.Content[0], out int yy1, out int mm1);
|
|
|
+ Convert16BitBCDToTwoInts(glassInfoRetTime.Content[1], out int dd1, out int hh1);
|
|
|
+ Convert16BitBCDToTwoInts(glassInfoRetTime.Content[2], out int ff1, out int ss1);
|
|
|
+
|
|
|
+
|
|
|
+ Convert16BitBCDToTwoInts(glassInfoRetTime.Content[3], out int yy2, out int mm2);
|
|
|
+ Convert16BitBCDToTwoInts(glassInfoRetTime.Content[4], out int dd2, out int hh2);
|
|
|
+ Convert16BitBCDToTwoInts(glassInfoRetTime.Content[5], out int ff2, out int ss2);
|
|
|
+
|
|
|
+ glassInfoData.LordingTime = new DateTime(yy1, mm1, dd1, hh1, ff1, ss1);
|
|
|
+ glassInfoData.UnlordingTime = new DateTime(yy2, mm2, dd2, hh2, ff2, ss2);
|
|
|
glassInfoData.RecordTime = DateTime.Now;
|
|
|
DbHelper.Db.Insertable(glassInfoData).ExecuteCommand();
|
|
|
melsec_net.Write(GlassInformationPLC.ReplyFlagAddress, true);
|
|
@@ -1072,7 +1125,7 @@ namespace B20UVLog
|
|
|
|
|
|
//ToDo:把PLC数据插入到数据库中
|
|
|
AlarmModel alarmData = MapPlcItemToObjectProperty<AlarmModel>(alarmItemLst);
|
|
|
- alarmData.AlarmDescribe = "测试报警";
|
|
|
+ alarmData.AlarmDescribe = deviceAlarm?.FirstOrDefault(x=>x.Key.Trim()==alarmData.AlarmCode.ToString())?.Value;
|
|
|
alarmData.RecordTime = DateTime.Now;
|
|
|
DbHelper.Db.Insertable(alarmData).ExecuteCommand();
|
|
|
melsec_net.Write(AlarmPLC.ReplyFlagAddress, true);
|
|
@@ -1122,7 +1175,7 @@ namespace B20UVLog
|
|
|
|
|
|
//ToDo:把PLC数据插入到数据库中
|
|
|
WarnModel warnData = MapPlcItemToObjectProperty<WarnModel>(warnItemLst);
|
|
|
- warnData.WarnDescribe = "测试警告";
|
|
|
+ warnData.WarnDescribe = deviceWarn?.FirstOrDefault(x => x.Key.Trim() == warnData.WarnCode.ToString())?.Value;
|
|
|
warnData.RecordTime = DateTime.Now;
|
|
|
DbHelper.Db.Insertable(warnData).ExecuteCommand();
|
|
|
melsec_net.Write(WarnPLC.ReplyFlagAddress, true);
|
|
@@ -1420,6 +1473,57 @@ namespace B20UVLog
|
|
|
}
|
|
|
return tmp;
|
|
|
}
|
|
|
+
|
|
|
+ private Dictionary<string, int> GetNonZeroProperties(object obj)
|
|
|
+ {
|
|
|
+ Dictionary<string, int> nonZeroProperties = new Dictionary<string, int>();
|
|
|
+
|
|
|
+ PropertyInfo[] properties = obj.GetType().GetProperties();
|
|
|
+ foreach (PropertyInfo property in properties)
|
|
|
+ {
|
|
|
+ if (property.PropertyType == typeof(int))
|
|
|
+ {
|
|
|
+ int value = (int)property.GetValue(obj);
|
|
|
+ if (value != 0)
|
|
|
+ {
|
|
|
+ nonZeroProperties.Add(property.Name, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return nonZeroProperties;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将8位BCD码转化为整数
|
|
|
+ private int BCDToInt(byte bcdValue)
|
|
|
+ {
|
|
|
+ int result = 0;
|
|
|
+ int multiplier = 1;
|
|
|
+
|
|
|
+ while (bcdValue > 0)
|
|
|
+ {
|
|
|
+ int digit = bcdValue & 0xF;
|
|
|
+ result += digit * multiplier;
|
|
|
+ bcdValue >>= 4;
|
|
|
+ multiplier *= 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将16位BCD码转化为两个整数
|
|
|
+ private void Convert16BitBCDToTwoInts(short bcdValue, out int int1, out int int2)
|
|
|
+ {
|
|
|
+ // 高8位BCD码
|
|
|
+ byte highByte = (byte)((bcdValue >> 8) & 0xFF);
|
|
|
+ // 低8位BCD码
|
|
|
+ byte lowByte = (byte)(bcdValue & 0xFF);
|
|
|
+
|
|
|
+ // 分别转换高8位和低8位
|
|
|
+ int1 = BCDToInt(highByte);
|
|
|
+ int2 = BCDToInt(lowByte);
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
}
|
|
|
}
|