Browse Source

机床状态推送

zhuhao 2 years ago
parent
commit
9ea780b0e6
1 changed files with 61 additions and 21 deletions
  1. 61 21
      IMCS_CCS/Service/Impl/TaskJobService.cs

+ 61 - 21
IMCS_CCS/Service/Impl/TaskJobService.cs

@@ -54,6 +54,8 @@ namespace IMCS.CCS.Service.Impl
 
         private Dictionary<String, int> syncStatusMap = new Dictionary<String, int>();
 
+        private Dictionary<String, String> jcAddressDict = new Dictionary<String, String>();
+
         private string LOG_TITLE_OPCUA = "OPCUA采集";
 
         private string LOG_TITLE_FUNC = "发那科采集";
@@ -104,6 +106,14 @@ namespace IMCS.CCS.Service.Impl
             //在线状态默认传参后台空闲状态
             syncStatusMap.Add("在线", 1);
             syncStatusMap.Add("掉线", -1);
+            //机床对应加工状态
+            jcAddressDict.Add("192.168.11.186", "DB200.402");
+            jcAddressDict.Add("192.168.11.187", "DB200.404");
+            jcAddressDict.Add("192.168.11.188", "DB200.406");
+            jcAddressDict.Add("192.168.11.189", "DB200.408");
+            jcAddressDict.Add("192.168.11.190", "DB200.410");
+            jcAddressDict.Add("192.168.11.191", "DB200.412");
+            jcAddressDict.Add("192.168.11.192", "DB200.414");
         }
 
         /// <summary>
@@ -1272,6 +1282,30 @@ namespace IMCS.CCS.Service.Impl
                 foreach (EquipmentMonitor equipment in equipmentMonitors)
                 {
                     Device device = devices.Where(x => x.Ip == equipment.IP).FirstOrDefault();
+
+                    //缓存取PLC tagvalue 值
+                    List<CcsTagValue> tagValues = new List<CcsTagValue>();
+                    string tag_value_redis_key = imcs_redis_key + device.Ip + ":" + device.ProtocolType;
+                    var tagData = await _redisService.Database.StringGetAsync(tag_value_redis_key);
+                    if (tagData.IsNullOrEmpty)
+                    {
+
+                        CcsTagValue tagQuery = new CcsTagValue();
+                        tagQuery.ProtocolType = device.ProtocolType;
+                        tagQuery.Ip = device.Ip;
+                        tagValues = _ccsTagValueService.GetList(tagQuery);
+                        //首次设置redis
+                        if (tagValues != null && tagValues.Count > 0)
+                        {
+                            await _redisService.Database.StringSetAsync(tag_value_redis_key, JsonConvert.SerializeObject(tagValues));
+                        }
+                    }
+                    else
+                    {
+                        tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(tagData);
+                    }
+                    
+                    CcsTagValue ccsTagValue = tagValues.Where(x => x.Ip == equipment.IP && x.Address == equipment.Address).FirstOrDefault();
                     if (device != null && !device.UseState)
                     {
                         if (equipment.Status != "离线")
@@ -1290,31 +1324,37 @@ namespace IMCS.CCS.Service.Impl
                         }
 
                         continue;
-                    } 
-                    else if (device != null && (equipment.Name == "机械手" || equipment.Name == "保障中心_伺服舵机"))
+                    }
+                    else if (device != null && device.State && device.UseState && (equipment.Type == "HEIDEHAIN" || equipment.Type == "FANUC"))
                     {
-                        //缓存取PLC tagvalue 值
-                        List<CcsTagValue> tagValues = new List<CcsTagValue>();
-                        string tag_value_redis_key = imcs_redis_key + device.Ip + ":" + device.ProtocolType;
-                        var tagData = await _redisService.Database.StringGetAsync(tag_value_redis_key);
-                        if (tagData.IsNullOrEmpty)
+                        string plcAddress = jcAddressDict[device.Ip];
+                        ccsTagValue = tagValues.Where(x => x.Ip == "192.168.11.170" && x.Address == plcAddress).FirstOrDefault();
+                        if(ccsTagValue != null)
                         {
-                           
-                            CcsTagValue tagQuery = new CcsTagValue();
-                            tagQuery.ProtocolType = device.ProtocolType;
-                            tagQuery.Ip = device.Ip;
-                            tagValues = _ccsTagValueService.GetList(tagQuery);
-                            //首次设置redis
-                            if (tagValues != null && tagValues.Count > 0)
+                            if (ccsTagValue.TagValue == "1")
                             {
-                                await _redisService.Database.StringSetAsync(tag_value_redis_key, JsonConvert.SerializeObject(tagValues));
+                                if (equipment.Status != "生产中")
+                                {
+                                    equipment.Status = "生产中";
+                                    changeEquipmentMonitors.Add(equipment);
+                                }
+                                continue;
                             }
-                        }
-                        else
-                        {
-                            tagValues = JsonConvert.DeserializeObject<List<CcsTagValue>>(tagData);
-                        }
-                        CcsTagValue ccsTagValue = tagValues.Where(x => x.Ip == equipment.IP && x.Address == equipment.Address).FirstOrDefault();
+                            if (ccsTagValue.TagValue == "2")
+                            {
+                                if (equipment.Status != "空闲")
+                                {
+                                    equipment.Status = "空闲";
+                                    changeEquipmentMonitors.Add(equipment);
+                                }
+                                continue;
+                            }
+                        } 
+                    }
+                    else if (device != null && (equipment.Name == "机械手" || equipment.Name == "保障中心_伺服舵机"))
+                    {
+                       
+                        ccsTagValue = tagValues.Where(x => x.Ip == equipment.IP && x.Address == equipment.Address).FirstOrDefault();
                         if (ccsTagValue != null)
                         {
                             if (ccsTagValue.TagValue == "3")