| | |
| | | /// <returns></returns> |
| | | public WebResponseContent automation(string extendedState) |
| | | { |
| | | var messages = new List<string>(); |
| | | //string message = ""; |
| | | try |
| | | { |
| | | for (int deptId = 1; deptId <= 5; deptId++) |
| | | { |
| | | var devices = GetDevicesByDeptId(deptId); |
| | | if (devices == null) |
| | | { |
| | | Console.WriteLine($"DeptId={deptId} æªæ¾å°è®¾å¤ï¼è·³è¿"); |
| | | continue; |
| | | } |
| | | |
| | | var para = BaseDal.QueryData() |
| | | .Where(x => x.Deptid == deptId) |
| | | .OrderByDescending(x => x.CreateDate) |
| | | .FirstOrDefault(); |
| | | |
| | | if (para == null) |
| | | { |
| | | Console.WriteLine($"DeptId={deptId} æªæ¾å°åæ°é
ç½®ï¼è·³è¿"); |
| | | continue; |
| | | } |
| | | |
| | | int ext = (int)para.ExtendSpeed;//å·¦PLCèªå¨ä¼¸åºç¼©åé度 |
| | | int ret = (int)para.RetractionSpeed;//å³PLCèªå¨ä¼¸åºç¼©åé度 |
| | | int liftPosition = (int)para.LeftPosition;//左伸åºä½ç½® |
| | | int rigtpostition = (int)para.RightPosition;//å³ä¼¸åºä½ç½® |
| | | |
| | | try |
| | | { |
| | | var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");//å·¦plcå°åç¹ä½ç½®ä¿¡å· |
| | | var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//å³plcå°è¾¾åç¹ä½ç½®ä¿¡å· |
| | | if (leftorigin == true || rightorigin == true) |
| | | var devices = GetDevicesByDeptId(deptId); |
| | | if (devices == null) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "å·²å°åå§ç¹" }; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | |
| | | } |
| | | try |
| | | { |
| | | var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//å·¦plcå°è¾¾ç®æ ä½ç½® |
| | | var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//å³plcå°è¾¾ç®æ ä½ç½® |
| | | if (lefttarget == true || righttarget == true) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "已尿大å¼" }; |
| | | messages.Add($"DeptId={deptId} æªæ¾å°è®¾å¤ï¼è·³è¿"); |
| | | continue; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | var para = BaseDal.QueryData() |
| | | .Where(x => x.Deptid == deptId) |
| | | .OrderByDescending(x => x.CreateDate) |
| | | .FirstOrDefault(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | if (extendedState == "伸åº") |
| | | { |
| | | try |
| | | if (para == null) |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1001", ext);//å·¦PLCèªå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M102", true);//ä¼¸åºæé® |
| | | devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//左伸åºä½ç½® |
| | | messages.Add($"DeptId={deptId} æªæ¾å°åæ°é
ç½®ï¼è·³è¿"); |
| | | continue; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | |
| | | } |
| | | int ext = (int)para.ExtendSpeed; |
| | | int ret = (int)para.RetractionSpeed; |
| | | int liftPos = (int)para.LeftPosition; |
| | | int rightPos = (int)para.RightPosition; |
| | | |
| | | // ç¬ç«å¤æå·¦/峿¯å¦å¯æ§è¡ |
| | | bool canLeft = true, canRight = true; |
| | | |
| | | try |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1001", ret); //å³PLCèªå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.right.Communicator.Write<bool>("M102", true); |
| | | devices.Value.right.Communicator.Write<int>("D1002", rigtpostition);//å³ä¼¸åºä½ç½® |
| | | var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");//å°è¾¾åç¹ |
| | | if (leftOrigin) |
| | | { |
| | | messages.Add($"{deptId}轨éå·¦PLCå·²å°åç¹"); |
| | | canLeft = false; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | |
| | | |
| | | Console.WriteLine($"DeptId={deptId} ï¼å·¦é度={ext}ï¼å³é度={ret}"); |
| | | } |
| | | else if (extendedState == "缩å") |
| | | { |
| | | { } |
| | | try |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1001", ext);//缩åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M103", true);//缩åæé® |
| | | var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115"); |
| | | if (rightOrigin) |
| | | { |
| | | messages.Add($"{deptId}轨éå³PLCå·²å°åç¹"); |
| | | canRight = false; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | |
| | | try |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1001", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M103", true); |
| | | var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//å·¦plcå°è¾¾ç®æ ä½ç½® |
| | | if (lefttarget) |
| | | { |
| | | messages.Add($"{deptId}轨éå·¦plcå°è¾¾ç®æ ä½ç½®"); |
| | | canLeft = false; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | Console.WriteLine($"DeptId={deptId} 缩åæä½ï¼å·¦é度={ext}ï¼å³é度={ret}"); |
| | | try |
| | | { |
| | | var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//å³plcå°è¾¾ç®æ ä½ç½® |
| | | if (righttarget) |
| | | { |
| | | messages.Add($"{deptId}轨éå³plcå°è¾¾ç®æ ä½ç½®"); |
| | | canRight = false; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | |
| | | if (extendedState == "伸åº") |
| | | { |
| | | if (canLeft) |
| | | { |
| | | try |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1001", ext); |
| | | devices.Value.left.Communicator.Write<bool>("M102", true); |
| | | devices.Value.left.Communicator.Write<int>("D1002", liftPos); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | if (canRight) |
| | | { |
| | | try |
| | | { |
| | | |
| | | devices.Value.right.Communicator.Write<int>("D1001", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M102", true); |
| | | devices.Value.right.Communicator.Write<int>("D1002", rightPos); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | else if (extendedState == "缩å") |
| | | { |
| | | if (canLeft) |
| | | { |
| | | try |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1001", ext); |
| | | devices.Value.left.Communicator.Write<bool>("M103", true); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | if (canRight) |
| | | { |
| | | try |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1001", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M103", true); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "æªç¥æä½å½ä»¤" }; |
| | | } |
| | | |
| | | |
| | | } |
| | | else |
| | | catch (Exception exDept) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "æªç¥çæä½å½ä»¤" }; |
| | | messages.Add($"DeptId={deptId} å¼å¸¸ï¼{exDept.Message}"); |
| | | } |
| | | } |
| | | |
| | | return new WebResponseContent { Status = true, Message = "å
¨é¨è®¾å¤æä½å®æ", |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Message = messages.Count == 0 ? "æ§è¡æå" : "é¨åæ§è¡å¤±è´¥ï¼" + string.Join("ï¼", messages), |
| | | Data = messages |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = $"æä½å¼å¸¸ï¼{ex.Message}" }; |
| | | return new WebResponseContent |
| | | { |
| | | Status = false, |
| | | Message = $"èªå¨æ§å¶å¼å¸¸ï¼{ex.Message}" |
| | | }; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | |
| | | int ext = (int)para.ManualExtend;//å·¦PLCæå¨ä¼¸åºç¼©åé度 |
| | | int ret = (int)para.ManualRetraction;//å³PLCæå¨ä¼¸åºç¼©åé度 |
| | | int liftPosition = (int)para.LeftPosition;//左伸åºä½ç½® |
| | | int rigtpostition = (int)para.RightPosition;//å³ä¼¸åºä½ç½® |
| | | bool canLeft = true, |
| | | canRight = true; |
| | | string message = ""; |
| | | |
| | | try |
| | | { |
| | | var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");//å·¦plcå°åç¹ä½ç½®ä¿¡å· |
| | | var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//å³plcå°è¾¾åç¹ä½ç½®ä¿¡å· |
| | | if (leftorigin == true || rightorigin == true) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "å·²å°åå§ç¹" }; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115"); |
| | | |
| | | |
| | | } |
| | | try |
| | | { |
| | | var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//å·¦plcå°è¾¾ç®æ ä½ç½® |
| | | var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//å³plcå°è¾¾ç®æ ä½ç½® |
| | | if (lefttarget == true || righttarget == true) |
| | | if (leftOrigin) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "已尿大å¼" }; |
| | | message += "å·¦PLCå·²å°åç¹ï¼"; |
| | | canLeft = false; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { } |
| | | try |
| | | { |
| | | |
| | | |
| | | var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115"); |
| | | if (rightOrigin) |
| | | { |
| | | message += "å³PLCå·²å°åç¹ï¼"; |
| | | canRight = false; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | |
| | | |
| | | try |
| | | { |
| | | var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//å·¦plcå°è¾¾ç®æ ä½ç½® |
| | | if (lefttarget) |
| | | { |
| | | message += "å·¦plcå°è¾¾ç®æ ä½ç½®ï¼"; |
| | | canLeft = false; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | try |
| | | { |
| | | var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//å³plcå°è¾¾ç®æ ä½ç½® |
| | | if (righttarget) |
| | | { |
| | | message += "å³plcå°è¾¾ç®æ ä½ç½®ï¼"; |
| | | canRight = false; |
| | | } |
| | | |
| | | if (position == "å·¦" && ExtendedState == "伸åº") |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | |
| | | |
| | | if (canLeft) |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1000", ext);//å·¦PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//ä¼¸åºæé® |
| | | Console.WriteLine($"{position}å·¦PLCèªå¨ä¼¸åºç¼©åé度{ext}"); |
| | | if (position == "å·¦" && ExtendedState == "伸åº") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1000", ext);//å·¦PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//ä¼¸åºæé® |
| | | Thread.Sleep(100); // çå¾
100msï¼æ¨¡ææé®æä¸ï¼ |
| | | devices.Value.left.Communicator.Write<bool>("M100", false); // éæ¾æé® |
| | | devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//左伸åºä½ç½® |
| | | Console.WriteLine($"{position}伸缩ææå¨ä¼¸åº{ext}"); |
| | | } |
| | | else if (position == "å·¦" && ExtendedState == "缩å") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1000", ext);//å·¦PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M101", true); |
| | | Thread.Sleep(100); // çå¾
100msï¼æ¨¡ææé®æä¸ï¼ |
| | | devices.Value.left.Communicator.Write<bool>("M101", false); // éæ¾æé® |
| | | Console.WriteLine($"{position}伸缩ææå¨ç¼©å{ext}"); |
| | | } |
| | | } |
| | | else if (position == "å·¦" && ExtendedState == "缩å") |
| | | if (canRight) |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1000", ext);//å·¦PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}å·¦PLCèªå¨ä¼¸åºç¼©åé度{ext}"); |
| | | } |
| | | else if (position == "å³" && ExtendedState == "伸åº") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1000", ret);//å³PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.right.Communicator.Write<bool>("M100", true); |
| | | Console.WriteLine($"{position}å³PLCèªå¨ä¼¸åºç¼©åé度{ext}"); |
| | | } |
| | | else if (position == "å³" && ExtendedState == "缩å") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1000", ret);//å³PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.right.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}å³PLCèªå¨ä¼¸åºç¼©åé度{ret}"); |
| | | if (position == "å³" && ExtendedState == "伸åº") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1000", ret);//å³PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.right.Communicator.Write<bool>("M100", true); |
| | | Thread.Sleep(100); // çå¾
100msï¼æ¨¡ææé®æä¸ï¼ |
| | | devices.Value.right.Communicator.Write<bool>("M100", false); // éæ¾æé® |
| | | devices.Value.right.Communicator.Write<int>("D1002", liftPosition);//左伸åºä½ç½® |
| | | Console.WriteLine($"{position}伸缩ææå¨ä¼¸åº{ret}"); |
| | | } |
| | | else if (position == "å³" && ExtendedState == "缩å") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1000", ret);//å³PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.right.Communicator.Write<bool>("M101", true); |
| | | Thread.Sleep(100); // çå¾
100msï¼æ¨¡ææé®æä¸ï¼ |
| | | devices.Value.right.Communicator.Write<bool>("M101", false); // éæ¾æé® |
| | | Console.WriteLine($"{position}伸缩ææå¨ç¼©å{ret}"); |
| | | } |
| | | } |
| | | |
| | | else |
| | |
| | | return new WebResponseContent { Status = false, Message = "ç¶æåæ°é误" }; |
| | | } |
| | | |
| | | return new WebResponseContent { Status = true, Message = "æå", |
| | | return new WebResponseContent { Status = true, |
| | | Message = string.IsNullOrEmpty(message) ? "æ§è¡æå" : $"æ§è¡å¤±è´¥ï¼{message}", |
| | | Data = new |
| | | { |
| | | ManualExtend = ext, |
| | | ManualRetraction = ret |
| | | ManualRetraction = ret, |
| | | message |
| | | } |
| | | |
| | | }; |