| | |
| | | /// <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) |
| | | try |
| | | { |
| | | Console.WriteLine($"DeptId={deptId} æªæ¾å°è®¾å¤ï¼è·³è¿"); |
| | | continue; |
| | | var devices = GetDevicesByDeptId(deptId); |
| | | if (devices == null) |
| | | { |
| | | messages.Add($"DeptId={deptId} æªæ¾å°è®¾å¤ï¼è·³è¿"); |
| | | continue; |
| | | } |
| | | |
| | | var para = BaseDal.QueryData() |
| | | .Where(x => x.Deptid == deptId) |
| | | .OrderByDescending(x => x.CreateDate) |
| | | .FirstOrDefault(); |
| | | |
| | | if (para == null) |
| | | { |
| | | messages.Add($"DeptId={deptId} æªæ¾å°åæ°é
ç½®ï¼è·³è¿"); |
| | | continue; |
| | | } |
| | | |
| | | int ext = (int)para.ExtendSpeed; |
| | | int ret = (int)para.RetractionSpeed; |
| | | int liftPos = (int)para.LeftPosition; |
| | | int rightPos = (int)para.RightPosition; |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.left.Communicator.Read<bool>("M117")) |
| | | { |
| | | |
| | | return new WebResponseContent { Status = false, Message = "ç°å¨æ£å¨è¿è¡ä¸ï¼çå¾
æä½å®æ" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | try |
| | | { |
| | | if (devices.Value.right.Communicator.Read<bool>("M117")) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "ç°å¨æ£å¨è¿è¡ä¸ï¼çå¾
æä½å®æ" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | |
| | | if (extendedState == "伸åº") |
| | | { |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.left.Communicator.Read<float>("D80")>= liftPos-5)//å°è¾¾æå¤§ä½ç½®) |
| | | { |
| | | messages.Add($"轨éç«{deptId}左伸缩æå·²å°æå¤§ä½ç½®"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1022", liftPos);//伸åºä½ç½® |
| | | devices.Value.left.Communicator.Write<int>("D1002", ext);//å·¦PLCèªå¨å¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M102", true);//ä¼¸åºæé® |
| | | |
| | | } |
| | | } |
| | | catch { } |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.left.Communicator.Read<float>("D80") >=rightPos-5) |
| | | { |
| | | messages.Add($"轨éç«{deptId}å³ä¼¸ç¼©æå·²å°æå¤§ä½ç½®"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1022", rightPos); |
| | | devices.Value.right.Communicator.Write<int>("D1002", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M102", true); |
| | | |
| | | } } |
| | | catch { } |
| | | |
| | | } |
| | | else if (extendedState == "缩å") |
| | | { |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.left.Communicator.Read<bool>("M115")) //å°è¾¾åç¹ä½ |
| | | { |
| | | messages.Add($"轨éç«{deptId}左伸缩æå·²å°åç¹"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1022", liftPos);//伸åºä½ç½® |
| | | devices.Value.left.Communicator.Write<int>("D1002", ext);//å·¦PLCèªå¨ä¼¸=缩ååºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M103", true);//å·¦plc缩åæé® |
| | | |
| | | } |
| | | } |
| | | catch { } |
| | | |
| | | |
| | | var para = BaseDal.QueryData() |
| | | .Where(x => x.Deptid == deptId) |
| | | .OrderByDescending(x => x.CreateDate) |
| | | .FirstOrDefault(); |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.right.Communicator.Read<bool>("M115")) |
| | | { |
| | | messages.Add($"轨éç«{deptId}å³ä¼¸ç¼©æå·²å°åç¹"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1022", rightPos); |
| | | devices.Value.right.Communicator.Write<int>("D1002", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M103", true); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | catch { } |
| | | |
| | | } |
| | | else |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "æªç¥æä½å½ä»¤" }; |
| | | } |
| | | |
| | | 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;//å³ä¼¸åºä½ç½® |
| | | |
| | | |
| | | |
| | | if (extendedState == "伸åº") |
| | | catch (Exception exDept) |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1001", ext);//å·¦PLCèªå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M102", true);//ä¼¸åºæé® |
| | | devices.Value.right.Communicator.Write<int>("D1002", liftPosition);//左伸åºä½ç½® |
| | | |
| | | |
| | | 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);//å³ä¼¸åºä½ç½® |
| | | |
| | | Console.WriteLine($"DeptId={deptId} ï¼å·¦é度={ext}ï¼å³é度={ret}"); |
| | | } |
| | | else if (extendedState == "缩å") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1001", ext);//缩åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M103", true);//缩åæé® |
| | | |
| | | devices.Value.right.Communicator.Write<int>("D1001", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M103", true); |
| | | |
| | | Console.WriteLine($"DeptId={deptId} 缩åæä½ï¼å·¦é度={ext}ï¼å³é度={ret}"); |
| | | } |
| | | else |
| | | { |
| | | 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}" |
| | | }; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | /// <param name="DeptId">è¡éå·</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent ManualOperation(string position, string ExtendedState,int DeptId) |
| | | { |
| | | { |
| | | try |
| | | { |
| | | if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid)) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "é
置项 DepartmentID æ æ³è½¬æ¢ä¸ºæ´æ°" }; |
| | | } |
| | | var devices = GetDevicesByDeptId(deid); |
| | | |
| | | var devices = GetDevicesByDeptId(DeptId); |
| | | if (devices == null) |
| | | return new WebResponseContent { Status = false, Message = "è®¾å¤æªæ¾å°" }; |
| | | //俩个plcå·¦å³åä¸ä¸ª |
| | | //OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001"); |
| | | //OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002"); |
| | | |
| | | var para = BaseDal.QueryData(x=>x.Deptid== DeptId).OrderByDescending(x => x.CreateDate).FirstOrDefault(); |
| | | if (para == null) |
| | | return new WebResponseContent { Status = false, Message = "åæ°æªé
ç½®" }; |
| | | |
| | | //æ¾å°Dt_Parametersä¸çææ°ä¸æ¡æ°æ®æ ¹æ®å½åçdeid |
| | | var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault(); |
| | | 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 |
| | | { |
| | | if (devices.Value.left.Communicator.Read<bool>("M117")) //é»è®¤æ¯flase |
| | | { |
| | | |
| | | return new WebResponseContent { Status = true, Message = "ç°å¨æ£å¨è¿è¡ä¸ï¼çå¾
æä½å®æ" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | try |
| | | { |
| | | if (devices.Value.right.Communicator.Read<bool>("M117")) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "ç°å¨æ£å¨è¿è¡ä¸ï¼çå¾
æä½å®æ" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | if (position == "å·¦" && ExtendedState == "伸åº") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1000", ext);//å·¦PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//ä¼¸åºæé® |
| | | Console.WriteLine($"{position}å·¦PLCèªå¨ä¼¸åºç¼©åé度{ext}"); |
| | | if (devices.Value.left.Communicator.Read<float>("D80") >= liftPosition - 5) //å°è¾¾ç®æ ä½ç½® |
| | | { |
| | | message += "左伸缩æå°è¾¾ç®æ ä½ç½®ï¼"; |
| | | } |
| | | else |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1004", liftPosition);//左伸åºä½ç½® |
| | | 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); // éæ¾æé® |
| | | |
| | | |
| | | 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); |
| | | Console.WriteLine($"{position}å·¦PLCèªå¨ä¼¸åºç¼©åé度{ext}"); |
| | | if (devices.Value.left.Communicator.Read<bool>("M115"))//缩åçæ¶å夿) |
| | | { |
| | | message += "å·¦PLCå·²å°åç¹ï¼"; |
| | | } |
| | | else |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D1004", liftPosition);//伸åºä½ç½® |
| | | 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 (position == "å³" && ExtendedState == "伸åº") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1000", ret);//å³PLCæå¨ä¼¸åºç¼©åé度 |
| | | devices.Value.right.Communicator.Write<bool>("M100", true); |
| | | Console.WriteLine($"{position}å³PLCèªå¨ä¼¸åºç¼©åé度{ext}"); |
| | | if (devices.Value.right.Communicator.Read<float>("D80") >= rigtpostition - 5) |
| | | { |
| | | message += "å³ä¼¸ç¼©æå°è¾¾ç®æ ä½ç½®ï¼"; |
| | | } |
| | | else |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1004", rigtpostition);//å³ä¼¸åºä½ç½® |
| | | 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); // éæ¾æé® |
| | | 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); |
| | | Console.WriteLine($"{position}å³PLCèªå¨ä¼¸åºç¼©åé度{ret}"); |
| | | if (devices.Value.right.Communicator.Read<bool>("M115")) |
| | | { |
| | | message += "å³ä¼¸ç¼©æå·²å°åç¹ï¼"; |
| | | } |
| | | else |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D1004", rigtpostition);//伸åºä½ç½® |
| | | 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 |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "ç¶æåæ°é误" }; |
| | | } |
| | | |
| | | return new WebResponseContent { Status = true, Message = "æå", |
| | | Status = true, |
| | | Message = string.IsNullOrEmpty(message) ? "æ§è¡æå" : $"{message}", |
| | | Data = new |
| | | { |
| | | ManualExtend = ext, |
| | | ManualRetraction = ret |
| | | ManualRetraction = ret, |
| | | message |
| | | } |
| | | |
| | | }; |
| | | |
| | | } |
| | | |
| | | |
| | | catch (Exception ex) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | //æ ¹æ®int.TryParse(AppSettings.Get("DepartmentID")读åå°å½åæ¯è½¨éå ï¼ææäººé½åªè½æä½å½å |
| | | var devices = GetDevicesByDeptId(deptid); |
| | | devices.Value.left.Communicator.Write<bool>("M104", true); |
| | | devices.Value.right.Communicator.Write<bool>("M104", true); |
| | | try |
| | | { |
| | | devices.Value.left.Communicator.Write<bool>("M104", true); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | try |
| | | { |
| | | devices.Value.right.Communicator.Write<bool>("M104", true); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | return new WebResponseContent { Status = true, Message = "æåæå", Data = devices }; |
| | | } |
| | | catch (Exception ex) |
| | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 伸缩æå½åä½ç½® |
| | | /// 伸缩æå½åä½ç½®(è¿ä¸ªæ²¡æç¨) |
| | | /// <param name="deptid">轨éç«å·</param> |
| | | public WebResponseContent CurrentLocation(int deptid) |
| | | { |