Browse Source

io表更新

user_zyx 11 months ago
parent
commit
b46a8fa765

+ 152 - 28
B20UVLog/LogPcTask_Biz.cs

@@ -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);
@@ -1143,6 +1196,9 @@ namespace B20UVLog
 
         private void IOLogTask()
         {
+          
+            List<IONewModel> ioNewModelList = new List<IONewModel>();
+            DateTime recordTime;
             taskList.Add(Task.Factory.StartNew(() =>
             {
                 while (true)
@@ -1156,8 +1212,7 @@ namespace B20UVLog
                     {
                         continue;
                     }
-                    OperateResult<bool> isLampUse = melsec_net.ReadBool(IOPLC.ReportFlagAddress);
-                    if (isLampUse.IsSuccess && isLampUse.Content)
+       
                     {
                         OperateResult<short[]> ioRet = melsec_net.ReadInt16(IOPLC.PlcItemAddressType + IOPLC.PlcItemStartAddress, (ushort)IOPLC.PlcItemAddressLength);
                         List<PlcItemModel> ioItemLst = DbHelper.Db.Queryable<PlcItemModel>().Where(x => x.PlcItemType == IOPLC.PlcItemType).ToList();
@@ -1165,27 +1220,45 @@ namespace B20UVLog
                         {
                             continue;
                         }
+                        recordTime = DateTime.Now;
+                        ioNewModelList.Clear();
                         foreach (PlcItemModel plcItem in ioItemLst)
                         {
                             ParsePlcItemData(plcItem, ioRet.Content, 0);
+                            //转化为
+                            IONewModel ioNewModel = new IONewModel();
+                            ioNewModel.IOName = plcItem.PlcItemCode;
+                            if (plcItem.PlcItemCode.Contains("Stage"))
+                            {
+                                ioNewModel.IOType = "Stage";
+                            }
+                            else
+                            {
+                                if (plcItem.PlcItemCode.Contains("IrradiatorInput"))
+                                {
+                                    ioNewModel.IOType = "IrradiatorInput";
+                                }
+                                else
+                                {
+                                    if (plcItem.PlcItemCode.Contains("IrradiatorOutput"))
+                                    {
+                                        ioNewModel.IOType = "IrradiatorOutput";
+                                    }
+                                }
+                            }
+                            ioNewModel.IOValue = Convert.ToInt32(plcItem.Value);
+                            ioNewModel.RecordTime = recordTime;
+                            ioNewModelList.Add(ioNewModel);
                         }
-
+                   
+             
                         //ToDo:把PLC数据插入到数据库中
-                        IOModel axisData = MapPlcItemToObjectProperty<IOModel>(ioItemLst);
-
-                        axisData.RecordTime = DateTime.Now;
-                        DbHelper.Db.Insertable(axisData).ExecuteCommand();
-                        melsec_net.Write(IOPLC.ReplyFlagAddress, true);
-                    }
-                    else
-                    {
-                        OperateResult<bool> isJobEventReply = melsec_net.ReadBool(IOPLC.ReplyFlagAddress);
-                        if (isJobEventReply.IsSuccess && isJobEventReply.Content)
-                        {
-                            melsec_net.Write(IOPLC.ReplyFlagAddress, false);
-                        }
+                       
+                        DbHelper.Db.Insertable(ioNewModelList).ExecuteCommand();
+                
                     }
-                    Task.Delay(TaskDelayTime).Wait();
+            
+                    Task.Delay(500).Wait();
                 }
             }, tokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default));
         }
@@ -1420,6 +1493,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
     }
 }

+ 5 - 3
B20UVLog/Models/DictModel.cs

@@ -1,4 +1,5 @@
-using System;
+using SqlSugar;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -6,13 +7,14 @@ using System.Threading.Tasks;
 
 namespace B20UVLog.Models
 {
-    class DictModel
+    [SugarTable("dict")]
+    public class DictModel
     {
         public int Id { get; set; }
         public string Type { get; set; }
         public string Code { get; set; }
         public string Key { get; set; }
         public string Value { get; set; }
-        public string Mask { get; set; }
+       
     }
 }

+ 44 - 0
B20UVLog/Models/IONewModel.cs

@@ -0,0 +1,44 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace B20UVLog.Models
+{
+    [SugarTable("io_new")]
+    public class IONewModel
+    {
+        public IONewModel()
+        {
+
+
+        }
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public int Id { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string EquId { get; set; }
+        public string IOName { get; set; }
+
+        public string IOType { get; set; }
+
+        public int IOValue { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public DateTime? RecordTime { get; set; }
+    }
+}

+ 45 - 0
B20UVLog/Models/ServoAxisStautsOriginal.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace B20UVLog.Models
+{
+    public class ServoAxisStautsOriginal
+    {
+        public int WSZ1AlarmCode { set; get; }
+        public int WSZ1WarningCode { set; get; }
+        public  int WSZ2AlarmCode { set; get; }
+        public int WSZ2WarningCode { set; get; }
+        public int WSZ3AlarmCode { set; get; }
+        public int WSZ3WarningCode { set; get; }
+        public int WSZ4AlarmCode { set; get; }
+        public int WSZ4WarningCode { set; get; }
+        public int WSX1AlarmCode { set; get; }
+        public int WSX1WarningCode { set; get; }
+        public int WSX2AlarmCode { set; get; }
+        public int WSX2WarningCode { set; get; }
+        public int WSY1AlarmCode { set; get; }
+        public int WSY1WarningCode { set; get; }
+        public int WSY2AlarmCode { set; get; }
+        public int WSY2WarningCode { set; get; }
+        public int CSXLAlarmCode { set; get; }
+        public int CSXLWarningCode { set; get; }
+        public int CSYLAlarmCode { set; get; }
+        public int CSYLWarningCode { set; get; }
+        public int CSZLAlarmCode { set; get; }
+        public int CSZLWarningCode { set; get; }
+        public int CSXRAlarmCode { set; get; }
+        public int CSXRWarningCode { set; get; }
+        public int CSYRAlarmCode { set; get; }
+        public int CSYRWarningCode { set; get; }
+        public int CSZRAlarmCode { set; get; }
+        public int CSZRWarningCode { set; get; }
+        public int WSLLAMPAlarmCode { set; get; }
+        public int WSLLAMPWarningCode { set; get; }
+        public int WSSSHUTTERAlarmCode { set; get; }
+        public int WSSSHUTTERWarningCode { set; get; }
+
+    }
+}

BIN
B20UVLog/ViewModels/MainWindowViewModel.cs