From 839cd7bba832638a5ba1fb2d3e4e0619e33651e3 Mon Sep 17 00:00:00 2001 From: zxx <Zxx@HanInfo> Date: 星期一, 19 五月 2025 17:33:28 +0800 Subject: [PATCH] 主动绑定接口 rgv安全交互 --- HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs | 20 + HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/util/Settings.cs | 11 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/api/WmsController.cs | 15 + .gitignore | 1 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/CameraMonitor.cs | 10 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/SafeInteraction.cs | 16 + HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/wms/ContainerHelper.cs | 1 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/HH.WCS.JuShi.csproj | 1 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/DeviceProcess.cs | 143 +++++++++--- HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WCSCore.cs | 2 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs | 359 +++++++++++++++++++++++-------- HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/config/config.json | 46 +++ HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/GetSubmitCheck.cs | 6 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/Program.cs | 2 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/TcpServer.cs | 13 + 15 files changed, 472 insertions(+), 174 deletions(-) diff --git a/.gitignore b/.gitignore index 932cfc1..e312a57 100644 --- a/.gitignore +++ b/.gitignore @@ -185,3 +185,4 @@ # Microsoft Fakes FakesAssemblies/ /.vs/HH.WCS.JuShi/FileContentIndex/3fc4eebc-46c2-4e7f-9d3f-1120aff520d4.vsidx +/.vs/HH.WCS.JuShi/FileContentIndex/e9cb8869-a58d-4485-bb3e-8bac64b53e74.vsidx diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/HH.WCS.JuShi.csproj b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/HH.WCS.JuShi.csproj index f84e9e5..f1a3a25 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/HH.WCS.JuShi.csproj +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/HH.WCS.JuShi.csproj @@ -219,6 +219,7 @@ <Compile Include="core\Monitor.cs" /> <Compile Include="models\BaseModel.cs" /> <Compile Include="models\Area.cs" /> + <Compile Include="models\SafeInteraction.cs" /> <Compile Include="models\SafetyInteraction.cs" /> <Compile Include="models\CntrItemDetail.cs" /> <Compile Include="models\CameraMonitor.cs" /> diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/Program.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/Program.cs index e11f435..e559db8 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/Program.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/Program.cs @@ -79,7 +79,7 @@ //鎽勫儚澶寸洃娴嬫弧鐘舵�鎵樼洏 tasks.Add(GetTask(WMSCore.MonitorFullStatus)); ////甯歌閫佹绌轰簡鑷姩浠庨�妫�紦瀛樺尯鍙栦竴涓�杩囧幓 - //tasks.Add(GetTask(WMSCore.AutoReplenish)); + tasks.Add(GetTask(WMSCore.AutoReplenish)); //S7閫氳 //tasks.Add(GetTask(S7Helper.ReadSsxPLc)); diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/api/WmsController.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/api/WmsController.cs index 1dc4537..8fbb40a 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/api/WmsController.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/api/WmsController.cs @@ -73,7 +73,20 @@ return res; } - + /// <summary> + /// 涓诲姩鐗╂枡缁戝畾 + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + public Results BindMaterial(GetSubmitCheck model) + { + LogHelper.Info("BindMaterial 鍙傛暟锛� + JsonConvert.SerializeObject(model), "WMSAPI"); + var res = TaskProcess.bindMaterial(model); + LogHelper.Info("BindMaterial 杩斿洖锛� + JsonConvert.SerializeObject(res), "WMSAPI"); + return res; + } + /// <summary> /// 鎽勫儚澶寸洃娴� /// </summary> diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/config/config.json b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/config/config.json index f605de1..4d8fa09 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/config/config.json +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/config/config.json @@ -192,26 +192,54 @@ } ], //瀹夊叏闂�- "SafeDoor": [ + "SafeInteraction": [ { - "pointCode": "闂�", + "pointCode": "RGV1", "ip": "192.168.1.133", - "port": "8080" + "type": "RGV", + "location": "RGV01" }, { - "pointCode": "闂�", + "pointCode": "RGV2", "ip": "192.168", - "port": "8888" + "type": "RGV", + "location": "RGV02" }, { - "pointCode": "闂�", + "pointCode": "RGV3", "ip": "192.168", - "port": "8888" + "type": "RGV", + "location": "RGV03" }, { - "pointCode": "闂�", + "pointCode": "RGV4", "ip": "192.168", - "port": "8888" + "type": "RGV", + "location": "RGV04" + }, + { + "pointCode": "鎷嗘墭鏈�鍏ュ彛", + "ip": "192.168", + "type": "CTJ", + "location": "CPJ01-R" + }, + { + "pointCode": "鎷嗘墭鏈�鍑哄彛", + "ip": "192.168", + "type": "CTJ", + "location": "CPJ01-C" + }, + { + "pointCode": "鎷嗘墭鏈�鍏ュ彛", + "ip": "192.168", + "type": "CTJ", + "location": "CPJ02-R" + }, + { + "pointCode": "鎷嗘墭鏈�鍑哄彛", + "ip": "192.168", + "type": "CTJ", + "location": "CPJ02-C" } ] ////鎽勫儚澶寸偣浣嶉厤缃�diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WCSCore.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WCSCore.cs index 927c934..42ef578 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WCSCore.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WCSCore.cs @@ -10,7 +10,7 @@ namespace HH.WCS.JuShi.core { internal class WCSCore - { + { public static void OperateAgvTaskStatus(AgvTaskState model) { var TN_Task = WCSHelper.GetTask(model.No); diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs index dba7843..562e821 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs @@ -233,15 +233,17 @@ var hcreservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "閫佹缂撳瓨鍖�).FirstOrDefault(); //鎵鹃�妫�紦瀛樺尯鏈夎揣鐨勮揣浣� var startloc = TaskProcess.OutWorkTransport(hcreservoirs.areaCode); - - //鍒涘缓閫佹浠诲姟 - var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == startloc.S_CODE).First(); - LogHelper.Info($"鍒涘缓浠诲姟 璧风偣:{startloc.S_CODE}缁堢偣:{endloc.S_CODE}", "鑷姩琛ヨ揣"); - var res = TaskProcess.CreateTransport(startloc.S_CODE, endloc.S_CODE, "鑷姩琛ヨ揣", locCntrRel.S_CNTR_CODE, 1, 1); - if (!res) - { - LogHelper.Info($"浠诲姟 璧风偣:{startloc.S_CODE}缁堢偣:{endloc.S_CODE}鍒涘缓澶辫触", "鑷姩琛ヨ揣"); - } + if (startloc!=null) + { + //鍒涘缓閫佹浠诲姟 + var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == startloc.S_CODE).First(); + LogHelper.Info($"鍒涘缓浠诲姟 璧风偣:{startloc.S_CODE}缁堢偣:{endloc.S_CODE}", "鑷姩琛ヨ揣"); + var res = TaskProcess.CreateTransport(startloc.S_CODE, endloc.S_CODE, "鑷姩琛ヨ揣", locCntrRel.S_CNTR_CODE, 1, 1); + if (!res) + { + LogHelper.Info($"浠诲姟 璧风偣:{startloc.S_CODE}缁堢偣:{endloc.S_CODE}鍒涘缓澶辫触", "鑷姩琛ヨ揣"); + } + } } } diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/TcpServer.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/TcpServer.cs index b9e7040..22ab780 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/TcpServer.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/TcpServer.cs @@ -82,6 +82,7 @@ var message = GetHexString(buffers[remote_ip], length);//16 10 Console.WriteLine(message); //3A 00 01 00 01 05 73 00 02 01 01 B8 + //鎸夐挳鐩� if (message.Substring(0, 2) == "3A") { //鏄剧ず娑堟伅 if (length != 24) { @@ -90,6 +91,18 @@ PlcHelper.Receive(remote_ip, message); Array.Clear(buffers[remote_ip], 0, buffers[remote_ip].Length);//娓呯┖褰撳墠IP Buffer } + //3F 00 10 20 30 40 0D 0A + //瀹夊叏浜や簰 + else if (message.Substring(0, 4) == "3F00") + { + //鏄剧ず娑堟伅 + if (length != 16) + { + message = message.Substring(0, 16); + } + PlcHelper.Receive(remote_ip, message); + Array.Clear(buffers[remote_ip], 0, buffers[remote_ip].Length);//娓呯┖褰撳墠IP Buffer + } else { Console.WriteLine($"銆怲CP淇℃伅鍗忚寮傚父銆戯細IP锛歿remote_ip},MSG锛歿message}"); } diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/CameraMonitor.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/CameraMonitor.cs index bdfdd94..f7da469 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/CameraMonitor.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/CameraMonitor.cs @@ -4,12 +4,12 @@ namespace HH.WCS.JuShi { - public class CameraMonitor : BaseModel + public class SafeInteraction : BaseModel { - //摄像头货位 - public string PointCode { get; set; } - //摄像头货位空满状态 - public int PointStatus { get; set; } + //站点ip + public string ip { get; set; } + //信号 + public string data { get; set; } } diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/GetSubmitCheck.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/GetSubmitCheck.cs index 9587876..3a8adbe 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/GetSubmitCheck.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/GetSubmitCheck.cs @@ -15,9 +15,9 @@ public string END_LOC { get; set; } //物料编号 public string S_ITEM_CODE { get; set; } - ////解绑货位 - //public string MONITOR_LOC { get; set; } + //绑定货位 + public string BIND_LOC { get; set; } - + } } diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/SafeInteraction.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/SafeInteraction.cs new file mode 100644 index 0000000..bdfdd94 --- /dev/null +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/models/SafeInteraction.cs @@ -0,0 +1,16 @@ +using HH.WCS.JuShi.models; +using System; + +namespace HH.WCS.JuShi +{ + + public class CameraMonitor : BaseModel + { + //摄像头货位 + public string PointCode { get; set; } + //摄像头货位空满状态 + public int PointStatus { get; set; } + + + } +} diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/DeviceProcess.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/DeviceProcess.cs index 688b6da..7945429 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/DeviceProcess.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/DeviceProcess.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Threading; using static HH.WCS.JuShi.LISTA.process.HttpModel; +using static HH.WCS.JuShi.util.Settings; namespace HH.WCS.JuShi.process { @@ -17,57 +18,113 @@ /// </summary> internal class DeviceProcess { + public static string rgvSafeInteraction = null; internal static void Analysis(string data, string ip) { - //鏀�- //3A 00 01 00 01 05 73 00 02 01 01 B8 - //鍙�- //2A 00 01 00 01 05 73 00 02 01 01 A8 if (data != null) { - //鏁版嵁搴忓彿 - data = data.Substring(16, 2); - //鏍规嵁ip鎵惧埌璧风偣/缁堢偣璐т綅 - var plc = Settings.deviceInfos.Where(a => a.address == ip).FirstOrDefault(); - var loc = plc.TN_Location; - //1鍏ュ簱2甯歌閫佹3绱ф�閫佹4涓夊绌烘墭5鍏绌烘墭 - bool result = false; - if (data.Equals("01")) - { - var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "RGV搴撳尯").FirstOrDefault(); - result= TaskProcess.tcpOffline(loc, reservoirs.areaCode); - } - else if (data.Equals("02")) - { - var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "甯歌閫佹鍖�).FirstOrDefault(); - result = TaskProcess.tcpOffline(loc, reservoirs.areaCode); - } - else if (data.Equals("03")) - { - var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "绱ф�閫佹鍖�).FirstOrDefault(); - result = TaskProcess.tcpOffline(loc, reservoirs.areaCode); - } - else if (data.Equals("04")) - { - var reservoirs = Settings.linePlcInfos.Where(s => s.code == "鎷嗘墭鏈�").FirstOrDefault(); - result = TaskProcess.tcpEmptyTray(reservoirs.outLoca, loc); - } - else if (data.Equals("05")) - { - var reservoirs = Settings.linePlcInfos.Where(s => s.code == "鎷嗘墭鏈�").FirstOrDefault(); - result = TaskProcess.tcpEmptyTray(reservoirs.outLoca, loc); - } + //鎸夐挳鐩�+ //鏀�+ //3A 00 01 00 01 05 73 00 02 01 01 B8 + //鍙� //2A 00 01 00 01 05 73 00 02 01 01 A8 - // 杈撳叆鐨勫崄鍏繘鍒跺瓧绗︿覆鏁扮粍 - string[] hexValues = { "2A", "00", "01", "00", "01", "05", "73", "00", "02", data, "01" }; - // 璁$畻鎬诲拰 - int sum = hexValues.Sum(hex => Convert.ToInt32(hex, 16)); - string returndata= hexValues.ToString()+ sum; - if (result) + if (data.Substring(0, 2) == "3A") { - PlcHelper.SendHex(ip, returndata); + //鏁版嵁搴忓彿 + data = data.Substring(16, 2); + //鏍规嵁ip鎵惧埌璧风偣/缁堢偣璐т綅 + var plc = Settings.deviceInfos.Where(a => a.address == ip).FirstOrDefault(); + var loc = plc.TN_Location; + //1鍏ュ簱2甯歌閫佹3绱ф�閫佹4涓夊绌烘墭5鍏绌烘墭 + bool result = false; + if (data.Equals("01")) + { + var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "RGV搴撳尯").FirstOrDefault(); + result = TaskProcess.tcpOffline(loc, reservoirs.areaCode); + } + else if (data.Equals("02")) + { + var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "甯歌閫佹鍖�).FirstOrDefault(); + result = TaskProcess.tcpOffline(loc, reservoirs.areaCode); + } + else if (data.Equals("03")) + { + var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "绱ф�閫佹鍖�).FirstOrDefault(); + result = TaskProcess.tcpOffline(loc, reservoirs.areaCode); + } + else if (data.Equals("04")) + { + var reservoirs = Settings.linePlcInfos.Where(s => s.code == "鎷嗘墭鏈�").FirstOrDefault(); + result = TaskProcess.tcpEmptyTray(reservoirs.outLoca, loc); + } + else if (data.Equals("05")) + { + var reservoirs = Settings.linePlcInfos.Where(s => s.code == "鎷嗘墭鏈�").FirstOrDefault(); + result = TaskProcess.tcpEmptyTray(reservoirs.outLoca, loc); + } + //2A 00 01 00 01 05 73 00 02 01 01 A8 + // 杈撳叆鐨勫崄鍏繘鍒跺瓧绗︿覆鏁扮粍 + string[] hexValues = { "2A", "00", "01", "00", "01", "05", "73", "00", "02", data, "01" }; + // 璁$畻鎬诲拰 + int sum = hexValues.Sum(hex => Convert.ToInt32(hex, 16)); + string returndata = hexValues.ToString() + sum; + if (result) + { + PlcHelper.SendHex(ip, returndata); + } } + //rgv瀹夊叏浜や簰 + else if (data.Substring(0, 4) == "3F00") + { + //鏃犱俊鍙蜂笉绠�+ if (data.Trim() != "3F00102030400D0A") + { + LogHelper.Info($"RGV瀹夊叏浜や簰鎺ユ敹淇″彿{data}"); + var reservoirs = Settings.SafeInteractions.Where(s => s.ip == ip).FirstOrDefault(); + //1鍏佽鍗歌揣 2鍗歌揣瀹屾垚纭 + string datastr = ""; + if (reservoirs.pointCode == "RGV1") + { + datastr = data.Substring(5, 1); + } + else if (reservoirs.pointCode == "RGV2") + { + datastr = data.Substring(7, 1); + } + else if (reservoirs.pointCode == "RGV3") + { + datastr = data.Substring(9, 1); + } + else if (reservoirs.pointCode == "RGV4") + { + datastr = data.Substring(11, 1); + } + //鎺ュ彈淇″彿瀛樺埌鍐呭瓨 + if (rgvSafeInteraction != null) + { + //string杞垚list + var jsonList = JsonConvert.DeserializeObject<List<SafeInteraction>>(rgvSafeInteraction); + var list = jsonList.Where(s => s.ip == ip).First(); + if (list != null) + { + //涓嶄负绌哄氨鍏堝垹鍐嶅姞涓�+ jsonList.Remove(list); + } + jsonList.Add(new SafeInteraction { ip = ip, data = datastr }); + rgvSafeInteraction = JsonConvert.SerializeObject(jsonList); + } + else + { + //绗竴娆¤繘 + var safeInteractions = new List<SafeInteraction>{new SafeInteraction { ip = ip, data = datastr }}; + rgvSafeInteraction = JsonConvert.SerializeObject(safeInteractions); + } + LogHelper.Info($"RGV瀹夊叏浜や簰 瀛樺叆鍐呭瓨鍙傛暟{rgvSafeInteraction}"); + } + + + } } diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs index b36f0fd..8777d39 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs @@ -20,6 +20,9 @@ using Opc.Ua; using System.Collections; using System.Xml.Linq; +using System.Threading; +using static HH.WCS.JuShi.dispatch.NDC; +using static HH.WCS.JuShi.util.Settings; namespace HH.WCS.JuShi.process { @@ -99,17 +102,121 @@ /// <param name="state"></param> internal static void OperateStatus(WCSTask mst, int state) { - if (state == 4) + if (state == 4)//鍙栬揣瀹屾垚 { CacheBitUpdate(mst, true); + //鎷嗘墭鏈哄畨鍏ㄤ氦浜�+ ctjSafe(mst); + } if (state == 6)//鍗歌揣瀹屾垚 { CacheBitUpdate(mst, false); + //rgv瀹夊叏浜や簰 + rgvSafe(mst); + //鎷嗘墭鏈哄畨鍏ㄤ氦浜�+ ctjSafe(mst); + } if (state == 7) { CacheBitCancelUpdate(mst); + } + } + //rgv瀹夊叏浜や簰 + private static void rgvSafe(WCSTask mst) + { + //rgv瀹夊叏浜や簰 鏍规嵁缁堢偣璐т綅鎵惧埌鏄摢涓猺gv + var reservoir = Settings.ReservoirAreas.Where(a => a.areaName == "RGV搴撳尯").FirstOrDefault(); + if (mst.S_END_AREA.Equals(reservoir.areaCode)) + { + var safeInteractions = Settings.SafeInteractions.Where(a => a.location == mst.S_END_LOC).FirstOrDefault(); + + var safelists = JsonConvert.DeserializeObject<List<SafeInteraction>>(DeviceProcess.rgvSafeInteraction); + + if (safelists.Any()) + { + var safelist = safelists.Where(s => s.ip == safeInteractions.ip).First(); + LogHelper.Info($"RGV瀹夊叏浜や簰鍙傛暟{safelist}"); + //涓嶇瓑浜�2鍗歌揣瀹屾垚纭淇″彿 灏辨帴鐫�彂 + if (safelist.data != "2") + { + string datastr = "3F00102030400D0A"; + // 杩斿洖淇″彿 + switch (safeInteractions.pointCode) + { + case "RGV1": + datastr = datastr.Replace("10", "11"); + break; + case "RGV2": + datastr = datastr.Replace("20", "21"); + break; + case "RGV3": + datastr = datastr.Replace("30", "31"); + break; + case "RGV4": + datastr = datastr.Replace("40", "41"); + break; + } + LogHelper.Info($"RGV瀹夊叏浜や簰鍙戦�淇″彿{safelist.ip},{datastr}"); + PlcHelper.SendHex(safelist.ip, datastr); + //浼戠湢3绉掑啀璋�+ Thread.Sleep(3000); + rgvSafe(mst); + } + else + { + LogHelper.Info($"RGV瀹夊叏浜や簰鍙戦�淇″彿{safelist.ip},3F00102030400D0A"); + //鏃犵姸鎬佷俊鍙�+ PlcHelper.SendHex(safelist.ip, "3F00102030400D0A"); + + } + } + } + } + //鎷嗘墭鏈哄畨鍏ㄤ氦浜�+ private static void ctjSafe(WCSTask mst) + { + PlcDeviceTable plcDeviceTable = null; + //鎵惧埌绾夸綋 鏍规嵁绾夸綋鎵惧唴瀛橀噷鐨勭姸鎬�+ var rkreservoirs = Settings.ConveyorLinesInfos.Where(s => s.location == mst.S_END_LOC).FirstOrDefault(); + var ckreservoirs = Settings.ConveyorLinesInfos.Where(s => s.location == mst.S_START_LOC).FirstOrDefault(); + if (rkreservoirs != null) + { + plcDeviceTable = S7Helper.plcDeviceTables.Find(a => a.DeviceNo == rkreservoirs.code); + } + else if (ckreservoirs != null) + { + plcDeviceTable = S7Helper.plcDeviceTables.Find(a => a.DeviceNo == ckreservoirs.code); + } + LogHelper.Info($"鎷嗘墭鏈哄畨鍏ㄤ氦浜掑啓鍏ュ弬鏁皗plcDeviceTable}"); + if (plcDeviceTable != null) + { + //s7鍐欏叆 + double addr = 0; //鍋忕Щ閲�+ string deviceNo = null;//鎷嗘墭鏈哄彿 + if (plcDeviceTable.DeviceNo == 1003) + { + addr = 90.1; + deviceNo = "1"; + } + else if (plcDeviceTable.DeviceNo == 1006) + { + addr = 180.1; + deviceNo = "2"; + } + else if (plcDeviceTable.DeviceNo == 1001) + { + addr = 30.0; + deviceNo = "1"; + } + else if (plcDeviceTable.DeviceNo == 1004) + { + addr = 120.0; + deviceNo = "2"; + } + LogHelper.Info($"鎷嗘墭鏈哄畨鍏ㄤ氦浜掑啓鍏deviceNo}锛寋addr}"); + S7Helper.WriteDouble(deviceNo, 9, addr, 1); } } @@ -316,70 +423,45 @@ string parmeD = "}"; string parme = parmeS + src + dst + parmeD; int res = 0; - if (mst.S_TYPE == "鍛煎彨绌烘墭" || mst.S_TYPE == "鎸夐挳鐩掕皟鐢ㄧ┖鎵� || mst.S_TYPE == "鎷嗘墭") - { - PlcDeviceTable plcDeviceTable = null; - //鎵惧埌绾夸綋 鏍规嵁绾夸綋鎵惧唴瀛橀噷鐨勭姸鎬�- var reservoirs1 = Settings.ConveyorLinesInfos.Where(s => s.location == startLoc.S_CODE).FirstOrDefault(); - plcDeviceTable = S7Helper.plcDeviceTables.Find(a => a.DeviceNo == reservoirs1.code); - if (plcDeviceTable != null) - { - if (mst.S_TYPE == "鍛煎彨绌烘墭" || mst.S_TYPE == "鎸夐挳鐩掕皟鐢ㄧ┖鎵�) - { - LogHelper.Info($"鍛煎彨绌烘墭鐘舵�鍙傛暟{JsonConvert.SerializeObject(plcDeviceTable)}", "浠诲姟"); - //0-鑴辨満鐘舵�锛�-寰呮満鐘舵�锛�-杩愯涓� 寰呮満涓旀湁鎵樼洏涓旇姹傚彇妗嗘墠璧�- if (plcDeviceTable.workMode == 1 && plcDeviceTable.lightAction == 1 && plcDeviceTable.requestTake) - { - LogHelper.Info($"鎺ㄩ�浠诲姟鍙傛暟{parme}", "浠诲姟"); - res = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, parme); - } - } - else if (mst.S_TYPE == "鎷嗘墭") - { - LogHelper.Info($"鎷嗘墭鐘舵�鍙傛暟{JsonConvert.SerializeObject(plcDeviceTable)}", "浠诲姟"); - //0-鑴辨満鐘舵�锛�-寰呮満鐘舵�锛�-杩愯涓� 寰呮満涓旀棤鎵樼洏涓斿厑璁告斁妗嗘墠璧�- if (plcDeviceTable.workMode == 1 && plcDeviceTable.lightAction == 0 && plcDeviceTable.requestPut) - { - LogHelper.Info($"鎺ㄩ�浠诲姟鍙傛暟{parme}", "浠诲姟"); - res = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, parme); - } - } - //浠诲姟瀹屾垚鍐欏叆s7 - if (res > 0) - { - //s7鍐欏叆 agv鍙栨瀹屾垚 - double addr = 0; //鍋忕Щ閲�- string deviceNo = null;//鎷嗘墭鏈哄彿 - if (plcDeviceTable.DeviceNo == 1003) - { - addr = 90.1; - deviceNo = "1"; - } - else if (plcDeviceTable.DeviceNo == 1006) - { - addr = 180.1; - deviceNo = "2"; - } - else if (plcDeviceTable.DeviceNo == 1001) - { - addr = 30.0; - deviceNo = "1"; - } - else if (plcDeviceTable.DeviceNo == 1004) - { - addr = 120.0; - deviceNo = "2"; - } - S7Helper.WriteDouble(deviceNo, 9, addr, 1); - - } - } - } - else - { - LogHelper.Info($"鎺ㄩ�浠诲姟鍙傛暟{parme}", "浠诲姟"); - res = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, parme); - } + LogHelper.Info($"鎺ㄩ�浠诲姟鍙傛暟{parme}", "浠诲姟"); + res = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, parme); + #region + //if (mst.S_TYPE == "鍛煎彨绌烘墭" || mst.S_TYPE == "鎸夐挳鐩掕皟鐢ㄧ┖鎵� || mst.S_TYPE == "鎷嗘墭") + //{ + // PlcDeviceTable plcDeviceTable = null; + // //鎵惧埌绾夸綋 鏍规嵁绾夸綋鎵惧唴瀛橀噷鐨勭姸鎬�+ // var reservoirs1 = Settings.ConveyorLinesInfos.Where(s => s.location == startLoc.S_CODE).FirstOrDefault(); + // plcDeviceTable = S7Helper.plcDeviceTables.Find(a => a.DeviceNo == reservoirs1.code); + // if (plcDeviceTable != null) + // { + // if (mst.S_TYPE == "鍛煎彨绌烘墭" || mst.S_TYPE == "鎸夐挳鐩掕皟鐢ㄧ┖鎵�) + // { + // LogHelper.Info($"鍛煎彨绌烘墭鐘舵�鍙傛暟{JsonConvert.SerializeObject(plcDeviceTable)}", "浠诲姟"); + // //0-鑴辨満鐘舵�锛�-寰呮満鐘舵�锛�-杩愯涓� 寰呮満涓旀湁鎵樼洏涓旇姹傚彇妗嗘墠璧�+ // if (plcDeviceTable.workMode == 1 && plcDeviceTable.lightAction == 1 && plcDeviceTable.requestTake) + // { + // LogHelper.Info($"鎺ㄩ�浠诲姟鍙傛暟{parme}", "浠诲姟"); + // res = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, parme); + // } + // } + // else if (mst.S_TYPE == "鎷嗘墭") + // { + // LogHelper.Info($"鎷嗘墭鐘舵�鍙傛暟{JsonConvert.SerializeObject(plcDeviceTable)}", "浠诲姟"); + // //0-鑴辨満鐘舵�锛�-寰呮満鐘舵�锛�-杩愯涓� 寰呮満涓旀棤鎵樼洏涓斿厑璁告斁妗嗘墠璧�+ // if (plcDeviceTable.workMode == 1 && plcDeviceTable.lightAction == 0 && plcDeviceTable.requestPut) + // { + // LogHelper.Info($"鎺ㄩ�浠诲姟鍙傛暟{parme}", "浠诲姟"); + // res = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, parme); + // } + // } + // } + //} + //else + //{ + // LogHelper.Info($"鎺ㄩ�浠诲姟鍙傛暟{parme}", "浠诲姟"); + // res = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, parme); + //} + #endregion if (res > 0) { //鏇存柊浠诲姟鐘舵� @@ -713,7 +795,7 @@ { //鏌ヨ杩欎釜搴撳尯鐨勭┖鎵樼洏涓庢弧鎵樼洏 var list = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == area).OrderByDescending(a => a.N_ROW).ToList(); - LogHelper.Info($"鏌ヨ杩欎釜搴撳尯鐨勭┖鎵樼洏涓庢弧鎵樼洏锛歿JsonConvert.SerializeObject(list)}"); + //LogHelper.Info($"鏌ヨ杩欎釜搴撳尯鐨勭┖鎵樼洏涓庢弧鎵樼洏锛歿JsonConvert.SerializeObject(list)}"); if (list.Count > 0) { List<string> loca = new List<string>(); @@ -1263,12 +1345,11 @@ try { var db = new SqlHelper<object>().GetInstance(); - //涓夎〃鑱旀煡鏌ュ嚭鏈夎鐗╂枡鐨勮揣浣嶇紪鍙� + //涓よ〃鑱旀煡鏌ュ嚭鏈夎鐗╂枡鐨勮揣浣嶇紪鍙� 锛堢幇鍦烘病鏈夌墿鏂欒〃锛� var locCntrs = db.Queryable<LocCntrRel>().LeftJoin<CntrItemDetail>((p, m) => p.S_CNTR_CODE == m.S_CNTR_CODE) - .LeftJoin<TN_Material>((p, m, s) => m.S_ITEM_CODE == s.S_ITEM_CODE) - .Where((p, m, s) => s.S_ITEM_CODE == itemCode) - .OrderBy((p, m, s) => p.T_CREATE) //鎸夊垱寤烘椂闂撮『搴�- .Select((p, m, s) => p.S_LOC_CODE) // 閫夋嫨鎵樼洏鐗╂枡琛ㄧ殑鏁版嵁 + .Where((p, m) => m.S_ITEM_CODE == itemCode) + .OrderBy((p, m) => p.T_CREATE) //鎸夊垱寤烘椂闂撮『搴�+ .Select((p, m) => p.S_LOC_CODE) // 閫夋嫨鎵樼洏鐗╂枡琛ㄧ殑鏁版嵁 .ToList(); LogHelper.Info($"鏈夌墿鏂檣itemCode}鐨勮揣浣嶇紪鍙穥JsonConvert.SerializeObject(locCntrs)}"); //鎵惧父瑙勯�妫�尯鍐呭惈鏈夋煡鍑虹墿鏂欒揣浣嶇殑璐т綅 @@ -1438,7 +1519,7 @@ //鏍规嵁鐗╂枡鎵炬煇搴撳尯鐨勮揣浣� var cgreservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "閫佹缂撳瓨鍖�).FirstOrDefault(); var startloc = getLocByMaterial(model.S_ITEM_CODE, cgreservoirs.areaCode); - if (startloc==null) + if (startloc == null) { return new Results { Code = "1", Message = $"鏈壘鍒板寘鍚墿鏂檣model.S_ITEM_CODE}鐨勮揣浣�, Data = null }; } @@ -1467,7 +1548,38 @@ throw; } } - + /// <summary> + /// 涓诲姩鐗╂枡缁戝畾 + /// </summary> + /// <param name="model.S_ITEM_CODE">鐗╂枡缂栫爜</param> + /// <param name="model.BIND_LOC">缁戝畾璐т綅</param> + /// <returns></returns> + internal static Results bindMaterial(GetSubmitCheck model) + { + var result = new Results() { Code = "0", Message = "鐗╂枡缁戝畾鎴愬姛锛�, Data = null }; + var db = new SqlHelper<Location>().GetInstance(); + try + { + string cntrStr = ContainerHelper.GenerateCntrNo(); + var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == model.BIND_LOC).First(); + if (locCntrRel != null) + { + cntrStr = locCntrRel.S_CNTR_CODE; + } + var res = ContainerHelper.BindLocCntrs(model.BIND_LOC, cntrStr, model.S_ITEM_CODE, "甯冨嵎"); + if (!res) + { + return new Results { Code = "1", Message = $"鐗╂枡{model.S_ITEM_CODE}璐т綅{model.BIND_LOC}缁戝畾澶辫触", Data = null }; + } + return result; + } + catch (Exception ex) + { + Console.WriteLine("bindMaterial:" + ex.Message + ex.StackTrace); + LogHelper.Error("bindMaterial:" + ex.Message, ex); + throw; + } + } /// <summary> /// 鎸夐挳鐩掕皟鐢ㄤ笅绾� /// </summary> @@ -1570,40 +1682,93 @@ { //0鍏佽杩涘叆 1涓嶅厑璁歌繘鍏� var result = new safeResult() { code = "1", msg = "success" }; - var db = new SqlHelper<Location>().GetInstance(); try { - var reservoirs = Settings.SafeDoors.Where(s => s.pointCode == model.STATION_NAME).FirstOrDefault();//y0-0000 y1-0001 on-FF00 off-0000 - TcpClient tcpClient = new TcpClient(); - //璇锋眰杩涘叆 - if (model.APPLY_CODE.Equals("1") || model.APPLY_CODE.Equals("5")) + var reservoirs = Settings.SafeInteractions.Where(s => s.pointCode == model.STATION_NAME).FirstOrDefault();//y0-0000 y1-0001 on-FF00 off-0000 + var rgvSafeInteraction = DeviceProcess.rgvSafeInteraction; + //RGV + if (reservoirs.type.Equals("RGV")) { - //鍙戦�淇″彿鍐欒姹傚紑闂� - var str = tcpClient.WriteSingleRegisterRtu("01050000FF008C3A", reservoirs.ip, int.Parse(reservoirs.port)); - //鍙戦�淇″彿璇婚棬鐘舵� - var x0bool = tcpClient.ReadInputRegistersRtu("010200000001B9CA", reservoirs.ip, int.Parse(reservoirs.port)); - //濡傛灉寮�棬鍒颁綅 - if (x0bool) + LogHelper.Info($"RGV瀹夊叏浜や簰 璇锋眰鐐逛綅锛歿model.STATION_NAME}璇锋眰鐮侊細{model.APPLY_CODE}"); + //鍗歌揣璇锋眰杩涘叆 + if (model.APPLY_CODE.Equals("5")) { - return new safeResult() { code = "0", msg = "success" }; + //鏍规嵁ip璇荤姸鎬�+ if (rgvSafeInteraction != null) + { + LogHelper.Info($"RGV瀹夊叏浜や簰鍙傛暟{JsonConvert.SerializeObject(rgvSafeInteraction)}"); + var safelist = JsonConvert.DeserializeObject<List<SafeInteraction>>(rgvSafeInteraction); + if (safelist.Any()) + { + var safedata = safelist.Where(s => s.ip == reservoirs.ip).First(); + //1鍏佽鍗歌揣 2鍗歌揣瀹屾垚纭 + if (safedata.data == "1") + { + LogHelper.Info($"RGV瀹夊叏浜や簰 鍏佽鍗歌揣"); + return new safeResult() { code = "0", msg = "success" }; + } + } + } } } - //璇锋眰绂诲紑 - else if (model.APPLY_CODE.Equals("4") || model.APPLY_CODE.Equals("8")) + //鎷嗘墭鏈�+ else if (reservoirs.type.Equals("CTJ")) { - //鍙戦�淇″彿鍐欒姹傚叧闂�- var str = tcpClient.WriteSingleRegisterRtu("010500000000CDCA", reservoirs.ip, int.Parse(reservoirs.port)); - var str2 = tcpClient.WriteSingleRegisterRtu("01050001FF00DDFA", reservoirs.ip, int.Parse(reservoirs.port)); - //鍙戦�淇″彿璇婚棬鐘舵� - var x0bool = tcpClient.ReadInputRegistersRtu("010200010001E80A", reservoirs.ip, int.Parse(reservoirs.port)); - //濡傛灉闂ㄥ凡鍏�- if (x0bool) + LogHelper.Info($"鎷嗘墭鏈哄畨鍏ㄤ氦浜� 璇锋眰鐐逛綅锛歿model.STATION_NAME}璇锋眰鐮侊細{model.APPLY_CODE}"); + //鎵惧埌绾夸綋 鏍规嵁绾夸綋鎵惧唴瀛橀噷鐨勭姸鎬�+ var reservoirs1 = Settings.ConveyorLinesInfos.Where(s => s.location == model.STATION_NAME).FirstOrDefault(); + var plcDeviceTable = S7Helper.plcDeviceTables.Find(a => a.DeviceNo == reservoirs1.code); + if (plcDeviceTable != null) { - return new safeResult() { code = "0", msg = "success" }; - } + LogHelper.Info($"鎷嗘墭鏈哄畨鍏ㄤ氦浜掑弬鏁皗JsonConvert.SerializeObject(plcDeviceTable)}"); + if (model.APPLY_CODE.Equals("1")) + { + //0-鑴辨満鐘舵�锛�-寰呮満鐘舵�锛�-杩愯涓� 寰呮満涓旀湁鎵樼洏涓旇姹傚彇妗嗘墠璧�+ if (plcDeviceTable.workMode == 1 && plcDeviceTable.lightAction == 1 && plcDeviceTable.requestTake) + { + LogHelper.Info($"鎷嗘墭鏈哄畨鍏ㄤ氦浜�鍏佽鍙栨"); + return new safeResult() { code = "0", msg = "success" }; + } + } + else if (model.APPLY_CODE.Equals("5")) + { + //0-鑴辨満鐘舵�锛�-寰呮満鐘舵�锛�-杩愯涓� 寰呮満涓旀棤鎵樼洏涓斿厑璁告斁妗嗘墠璧�+ if (plcDeviceTable.workMode == 1 && plcDeviceTable.lightAction == 0 && plcDeviceTable.requestPut) + { + LogHelper.Info($"鎷嗘墭鏈哄畨鍏ㄤ氦浜�鍏佽鏀炬"); + return new safeResult() { code = "0", msg = "success" }; + } + } + } } - return null; + + //TcpClient tcpClient = new TcpClient(); + ////鍙戦�淇″彿鍐欒姹傚紑闂�+ //var str = tcpClient.WriteSingleRegisterRtu("01050000FF008C3A", reservoirs.ip, int.Parse(reservoirs.port)); + ////鍙戦�淇″彿璇婚棬鐘舵� + //var x0bool = tcpClient.ReadInputRegistersRtu("010200000001B9CA", reservoirs.ip, int.Parse(reservoirs.port)); + ////濡傛灉寮�棬鍒颁綅 + //if (x0bool) + //{ + // return new safeResult() { code = "0", msg = "success" }; + //} + ////璇锋眰绂诲紑 + //else if (model.APPLY_CODE.Equals("8")) + //{ + // ////鍙戦�淇″彿鍐欒姹傚叧闂�+ // //var str = tcpClient.WriteSingleRegisterRtu("010500000000CDCA", reservoirs.ip, int.Parse(reservoirs.port)); + // //var str2 = tcpClient.WriteSingleRegisterRtu("01050001FF00DDFA", reservoirs.ip, int.Parse(reservoirs.port)); + // ////鍙戦�淇″彿璇婚棬鐘舵� + // //var x0bool = tcpClient.ReadInputRegistersRtu("010200010001E80A", reservoirs.ip, int.Parse(reservoirs.port)); + // ////濡傛灉闂ㄥ凡鍏�+ // //if (x0bool) + // //{ + // // return new safeResult() { code = "0", msg = "success" }; + // //} + + //} + return result; } catch (Exception ex) { diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/util/Settings.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/util/Settings.cs index b5d6447..b75b64f 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/util/Settings.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/util/Settings.cs @@ -21,7 +21,7 @@ public static List<PriorityLoc> PriorityLocs { get; set; } public static List<ConveyorLinesInfo> ConveyorLinesInfos { get; set; } public static List<linePlcInfo> linePlcInfos { get; set; } - public static List<SafeDoor> SafeDoors { get; set; } + public static List<SafeInteraction> SafeInteractions { get; set; } public static int port { get; set; } public static string WHCode { get; set; } public static string FacCode { get; set; } @@ -110,9 +110,9 @@ { PriorityLocs = JsonConvert.DeserializeObject<List<PriorityLoc>>(keyValue.Value.ToString()); } - if (keyValue.Name == "SafeDoor") + if (keyValue.Name == "SafeInteraction") { - SafeDoors = JsonConvert.DeserializeObject<List<SafeDoor>>(keyValue.Value.ToString()); + SafeInteractions = JsonConvert.DeserializeObject<List<SafeInteraction>>(keyValue.Value.ToString()); } } } @@ -192,11 +192,12 @@ public string SecondaryArea { get; set; } } - public class SafeDoor + public class SafeInteraction { public string pointCode { get; set; } public string ip { get; set; } - public string port { get; set; } + public string type { get; set; } + public string location { get; set; } } } diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/wms/ContainerHelper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/wms/ContainerHelper.cs index dd7d69d..c6d587a 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/wms/ContainerHelper.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/wms/ContainerHelper.cs @@ -626,6 +626,7 @@ db.Insertable<CntrItemDetail>(cir).ExecuteCommand(); db.Ado.CommitTran(); res = true; + LogHelper.Info($"缁戝畾瀹瑰櫒鐗╂枡琛ㄦ墭鐩橈細{trayCode}鐗╂枡缂栫爜锛歿itemCode}鐗╂枡鍚嶇О锛歿itemName}"); } catch (Exception ex) { -- Gitblit v1.9.1