| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using AutoMapper; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using SqlSugar; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | |
| | | /// <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; |
| | | int ret = (int)para.RetractionSpeed; |
| | | |
| | | if (extendedState == "伸åº") |
| | | catch (Exception exDept) |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D500", ext);//伸åºé度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//ä¼¸åºæé® |
| | | |
| | | devices.Value.right.Communicator.Write<int>("D500", ext); |
| | | devices.Value.right.Communicator.Write<bool>("M100", true); |
| | | |
| | | Console.WriteLine($"DeptId={deptId} ä¼¸åºæä½ï¼é度={ext}"); |
| | | } |
| | | else if (extendedState == "缩å") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D501", ret);//伸åºé度 |
| | | devices.Value.left.Communicator.Write<bool>("M101", true);//ä¼¸åºæé® |
| | | |
| | | devices.Value.right.Communicator.Write<int>("D501", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M101", true); |
| | | |
| | | Console.WriteLine($"DeptId={deptId} 缩åæä½ï¼é度={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}" |
| | | }; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æå¨æ§å¶ï¼ä¼¸ç¼©æç缩åå伸åºé度 |
| | | /// </summary> |
| | | /// <param name="position">伸缩æçä½ç½®ï¼å·¦å³ï¼</param> |
| | | /// <param name="ExtendedState">伸/ç¼©ç¶æ</param> |
| | | /// <returns></returns> |
| | | /// |
| | | //public WebResponseContent ManualOperation(string position, string ExtendedState) |
| | | //{ |
| | | // try |
| | | // { |
| | | // //俩个plcå·¦å³åä¸ä¸ª |
| | | // OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001"); |
| | | // OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002"); |
| | | // //æ¾å°Dt_Parametersä¸çææ°ä¸æ¡æ°æ® |
| | | // var para = BaseDal.QueryData().OrderBy(x => x.CreateDate).FirstOrDefault(); |
| | | // int ext = (int)para.ManualExtend;//èªå¨ä¼¸åºé度 |
| | | // int ret = (int)para.ManualRetraction;//èªå¨ç¼©åé度 |
| | | // if (position == "å·¦" && ExtendedState == "伸åº") |
| | | // { |
| | | // var values = liftotherDevice.Communicator.Write<int>("D500", ext);//é度 |
| | | // var button = liftotherDevice.Communicator.Write<bool>("M100", true);//ä¼¸åºæé® |
| | | // Console.WriteLine($"{position}伸缩æä¼¸åº{ext}"); |
| | | // } |
| | | // if (position == "å·¦" && ExtendedState == "缩å") |
| | | // { |
| | | // var values = liftotherDevice.Communicator.Write<int>("D501", ret); |
| | | //var button = liftotherDevice.Communicator.Write<bool>("M101", true);//缩åæé® |
| | | //Console.WriteLine($"{position}伸缩æç¼©å{ret}"); |
| | | // } |
| | | // if (position == "å³" && ExtendedState == "伸åº") |
| | | // { |
| | | // var values = rightotherDevice.Communicator.Write<int>("D500", ext);//é度 |
| | | // var button = rightotherDevice.Communicator.Write<bool>("M100", true);//ä¼¸åºæé® |
| | | // Console.WriteLine($"{position}伸缩æä¼¸åº{ext}"); |
| | | // } |
| | | // if (position == "å³" && ExtendedState == "缩å") |
| | | // { |
| | | // var values = rightotherDevice.Communicator.Write<int>("D501", ret); |
| | | // var button = rightotherDevice.Communicator.Write<bool>("M101", true);//缩åæé® |
| | | // Console.WriteLine($"{position}伸缩æç¼©å{ret}"); |
| | | // } |
| | | // return new WebResponseContent { Status = true, Message = "æå" }; |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // 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 = ""; |
| | | |
| | | int ext = (int)para.ExtendSpeed; |
| | | int ret = (int)para.RetractionSpeed; |
| | | 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>("D500", ext);//伸åºé度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//ä¼¸åºæé® |
| | | Console.WriteLine($"{position}伸缩ææå¨ä¼¸åº{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>("D501", ret);//缩åé度 |
| | | devices.Value.left.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}伸缩ææå¨ç¼©å{ret}"); |
| | | 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>("D500", ext); |
| | | devices.Value.right.Communicator.Write<bool>("M100", true); |
| | | Console.WriteLine($"{position}伸缩ææå¨ä¼¸åº{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>("D501", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}伸缩ææå¨ç¼©å{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, |
| | | message |
| | | } |
| | | }; |
| | | } |
| | | |
| | | |
| | | catch (Exception ex) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | ///å½èªå¨ä¼¸åºéè¦æåæ¶ï¼æåæé® |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent PauseButton(int deptid) |
| | | { |
| | | try |
| | | { |
| | | //æ ¹æ®int.TryParse(AppSettings.Get("DepartmentID")读åå°å½åæ¯è½¨éå ï¼ææäººé½åªè½æä½å½å |
| | | var devices = GetDevicesByDeptId(deptid); |
| | | 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) |
| | | { |
| | | |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 伸缩æå½åä½ç½®(è¿ä¸ªæ²¡æç¨) |
| | | /// <param name="deptid">轨éç«å·</param> |
| | | public WebResponseContent CurrentLocation(int deptid) |
| | | { |
| | | try |
| | | { |
| | | var devices = GetDevicesByDeptId(deptid); |
| | | if (devices == null) |
| | | return new WebResponseContent { Status = false, Message = "è®¾å¤æªæ¾å°" }; |
| | | var deviceslift = devices.Value.left.Communicator.Read<float>("D80"); |
| | | var devicesright = devices.Value.right.Communicator.Read<float>("D80"); |
| | | Console.WriteLine($"å½åå·¦å³ä¼¸ç¼©æè¿åé度åå«ä¸ºä¸º{deviceslift}"); |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Data = new { lift = deviceslift, Right = devicesright } |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | return new WebResponseContent { Status=false,Message=ex.Message}; |
| | | } |
| | | } |
| | | |
| | |
| | | return (left, right); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |