From dc9fb292e8b057dbd0d45c60a1538d2d95727d67 Mon Sep 17 00:00:00 2001 From: czw <selecti@yeah.net> Date: 星期三, 23 七月 2025 17:07:18 +0800 Subject: [PATCH] 1 --- 2025年6月12日/AuxAllWCS/Build/Project/代码/界面事件.cs | 278 ++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 203 insertions(+), 75 deletions(-) diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" index 023f0d4..401458c 100644 --- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" +++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" @@ -28,6 +28,10 @@ using GZ.DB.Repository.OIDATABASE; using GZ.DB.IRepository.OIDATABASE; using GZ.DB.Entity.OIDATABASE; +using static GZ.Projects.AuxAllWCS.ToWMSMES.CreateTask; +using GZ.Device.PLC; +using System.Text.RegularExpressions; +using ServiceStack.Text; namespace GZ.Projects.AuxAllWCS { /// <summary> @@ -50,11 +54,12 @@ try { - HttpSvcHost = new System.Net.HttpListener(); - HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous; - HttpSvcHost.Prefixes.Add("http://10.221.55.117:8808/"); - HttpSvcHost.Start(); - HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); + //HttpSvcHost = new System.Net.HttpListener(); + //HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous; + //HttpSvcHost.Prefixes.Add("http://10.221.55.117:8808/"); + //HttpSvcHost.Start(); + //HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); + LogHelper.Info("<<<<<<<<<<<Runnnnnnnnnnnnninggggg>>>>>>>>>>"); } catch (Exception ex) { @@ -62,37 +67,66 @@ } View1_Init(sender, e); + var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs"); + //string text = File.ReadAllText(configPath); + //PlcConfig plcConfig = JsonConvert.DeserializeObject<PlcConfig>(text); + //if (plcConfig != null && FactoryMap.ContainsKey((int)plcConfig.Brand) && FactoryMap[(int)plcConfig.Brand].Contains((int)plcConfig.Comm)) + //{ + + //foreach (var configPath in Directory.EnumerateFiles(@"G:\1AGIT\HH-0167_WuHuAoKeSi\2025骞�鏈�2鏃AuxAllWCS\Build\auxwcs\bin\Debug\Configs", "* - 鍓湰", SearchOption.TopDirectoryOnly)) + //{ + // string text = File.ReadAllText(configPath); + // PlcConfig plcConfig = JsonConvert.DeserializeObject<PlcConfig>(text); + // if (plcConfig.Brand == DeviceBrand.Siemens) + // { + // string pattern = "^(?<ip>((?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d))\r\n:(?<port>0|[1-9]\\d{0,4}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])\r\n(?:(?::(?<number>\\d+)|\\[(?<rack>\\d+),(?<slot>\\d+)\\]|\\[v(?<ver>\\d+\\.\\d+)\\])){0,3}$"; + // Match match = Regex.Match(plcConfig.IP, pattern, RegexOptions.IgnorePatternWhitespace); + // if (match.Success) + // { + + // string value = match.Groups["ip"].Value; + // int.TryParse(match.Groups["port"].Value, out var result3); + // int.TryParse(match.Groups["number"].Value, out var result4); + // short.TryParse(match.Groups["rack"].Value, out var result5); + // short.TryParse(match.Groups["slot"].Value, out var result6); + // string value2 = match.Groups["ver"].Value; + // var result = new Comm_S7Net(Comm_S7Net. CpuType., value, result3, result5, result6, result4, value2); + // } + // } + //} + //} + //Console.Write(path); /// <summary> /// 绋嬪簭鐗囨:鍒濆鍖栭厤缃� /// 鎻忚堪: /// </summary> System.Threading.Tasks.Task.Factory.StartNew(() => + { + System.Threading.Thread.CurrentThread.IsBackground = true; + ExitJudgeStack.Push(0); + //涓�洿鎵ц锛岀洿鍒版弧瓒崇粨鏉熸潯浠�+ while (true) { - System.Threading.Thread.CurrentThread.IsBackground = true; - ExitJudgeStack.Push(0); - //涓�洿鎵ц锛岀洿鍒版弧瓒崇粨鏉熸潯浠�- while (true) + if (IsExitApp) { break; } + try { - if (IsExitApp) { break; } - try - { - #region [鑴氭湰][20250323111613779][涓氬姟閫昏緫.鍒濆鍖栭厤缃甝 + #region [鑴氭湰][20250323111613779][涓氬姟閫昏緫.鍒濆鍖栭厤缃甝 - Action myDelegate = () => SettingInit(); - AutoThread.InvokeMethod(AutoThread.Instance, "ThreadSettingInit", new object[] { tag, myDelegate }); - #endregion [鑴氭湰][20250323111613779][涓氬姟閫昏緫.鍒濆鍖栭厤缃甝 - } - catch (Exception ex) - { - Conn.榛樿鏃ュ織.Error(ex.ToString()); - } - finally - { - System.Threading.Thread.Sleep(10000); - } + Action myDelegate = () => SettingInit(); + AutoThread.InvokeMethod(AutoThread.Instance, "ThreadSettingInit", new object[] { tag, myDelegate }); + #endregion [鑴氭湰][20250323111613779][涓氬姟閫昏緫.鍒濆鍖栭厤缃甝 } - ExitJudgeStack.TryPop(out int exitJudgeVal); - }); + catch (Exception ex) + { + Conn.榛樿鏃ュ織.Error(ex.ToString()); + } + finally + { + System.Threading.Thread.Sleep(10000); + } + } + ExitJudgeStack.TryPop(out int exitJudgeVal); + }); /// <summary> /// 绋嬪簭鐗囨:鎹风灛鎶撹噦1 /// 鎻忚堪: @@ -173,21 +207,21 @@ // RunafterMac(di,true); /// TODO mes 涓嬪彂銆� 鏀规垚鏈烘鑷傜洃鎺�- 鐩戞帶绌虹殑杩樻槸婊$殑 - 鑱斿姩mes 浠诲姟銆� - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.State:{Device.缁村笇灏旀姄鑷�.State} "); - Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out object value); - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.R50:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.State:{Device.缁村笇灏旀姄鑷�.State} "); + //Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out object value); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵1锛氱淮甯屽皵鎶撹噦1.R50:{value?.ToString()} "); - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.State:{Device.缁村笇灏旀姄鑷�.State} "); - Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out value); - LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.R50:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.State:{Device.缁村笇灏旀姄鑷�.State} "); + //Device.缁村笇灏旀姄鑷�.ReadPLC("缁村笇灏旀姄鑷�.R50", out value); + //LogHelper.Info($"璁惧鐘舵�锛氱淮甯屽皵2锛氱淮甯屽皵鎶撹噦2.R50:{value?.ToString()} "); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『1.State:{Device.Js鎹烽『1.State} "); - Device.Js鎹烽『1.ReadPLC("Js鎹烽『1.D1202", out value); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『1.D1202:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『1.State:{Device.Js鎹烽『1.State} "); + //Device.Js鎹烽『1.ReadPLC("Js鎹烽『1.D1202", out value); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『1.D1202:{value?.ToString()} "); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『2.State:{Device.Js鎹烽『2.State} "); - Device.Js鎹烽『2.ReadPLC("Js鎹烽『2.D1202", out value); - LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『2.D1202:{value?.ToString()} "); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬�锛欽s鎹烽『2.State:{Device.Js鎹烽『2.State} "); + //Device.Js鎹烽『2.ReadPLC("Js鎹烽『2.D1202", out value); + //LogHelper.Info($"璁惧鐘舵�锛氭嵎鐬� Js鎹烽『2.D1202:{value?.ToString()} "); #endregion [鑴氭湰][20250325085810885][涓氬姟閫昏緫.绗笁鏍囨.鑷祦杞祦绋媇 @@ -370,7 +404,7 @@ { #region [鑴氭湰][20250531163716255][涓氬姟閫昏緫.澶勭悊MES浠诲姟绾跨▼.ResolveMesTask] //mes 浠诲姟鎷嗗垎銆備竴娈典换鍔″拰 澶氭浠诲姟銆�- ToWMSMES.ResMesTask(); + ToWMSMES.ResMesTask(tag); #endregion [鑴氭湰][20250531163716255][涓氬姟閫昏緫.澶勭悊MES浠诲姟绾跨▼.ResolveMesTask] } catch (Exception ex) @@ -387,15 +421,7 @@ try { #region [鑴氭湰][20250605212104026][涓氬姟閫昏緫.SocketServer] - var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()); - foreach (var ip in host.AddressList) - { - if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) - { - Console.WriteLine($"ip= {ip.ToString()}"); - new TcpServer(ip.ToString()); - } - } + AutoThread.InvokeMethod(AutoThread.Instance, "TaskEverythingRun"); #endregion [鑴氭湰][20250605212104026][涓氬姟閫昏緫.SocketServer] } catch (Exception ex) @@ -801,35 +827,66 @@ } ExitJudgeStack.TryPop(out int exitJudgeVal); }); - //鎵ц澶氭 - for (int iii = 0; iii < 1; iii++) + /// <summary> + /// 绋嬪簭鐗囨:Ipping + /// 鎻忚堪:妫�祴IP鍦板潃閫氭柇 + /// </summary> + System.Threading.Tasks.Task.Factory.StartNew(() => { - if (IsExitApp) { break; } - try + System.Threading.Thread.CurrentThread.IsBackground = true; + ExitJudgeStack.Push(0); + //涓�洿鎵ц锛岀洿鍒版弧瓒崇粨鏉熸潯浠�+ while (true) { - #region [鑴氭湰][20250323151832119][涓氬姟閫昏緫.Program4] + if (IsExitApp) { break; } + try + { + #region [鑴氭湰][20250323151832119][涓氬姟閫昏緫.Ipping] - //LogHelper.Info($"<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>"); - //LogHelper.Info($"<<<<<<<<<<<<<<<<<绋嬪簭路鍚姩>>>>>>>>>>>>>>"); - - //// 浣跨敤鎷︽埅鍣�- //var interceptor = new ConsoleInterceptor(); - //Console.SetOut(interceptor); - - //LogHelper.Info($"<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>"); - //AnsiConsole.Markup("[underline red]Hello[/] World!"); - // AnsiConsole.Markup("[underline red]Hello[/] World!"); - #endregion [鑴氭湰][20250323151832119][涓氬姟閫昏緫.Program4] + //var hkr = AutoThread.InvokeMethod(AutoThread.Instance, "IsMachineOnline", new object[] { "192.168.1.103", 1000 }); + //Console.WriteLine("192.168.1.103 > " + hkr.ToString()); + #endregion [鑴氭湰][20250323151832119][涓氬姟閫昏緫.Ipping] + } + catch (Exception ex) + { + Conn.榛樿鏃ュ織.Error(ex.ToString()); + } + finally + { + System.Threading.Thread.Sleep(3000); + } } - catch (Exception ex) + ExitJudgeStack.TryPop(out int exitJudgeVal); + }); + /// <summary> + /// 绋嬪簭鐗囨:鏂扮嚎绋嬫�绾�+ /// 鎻忚堪:1 + /// </summary> + System.Threading.Tasks.Task.Factory.StartNew(() => + { + System.Threading.Thread.CurrentThread.IsBackground = true; + ExitJudgeStack.Push(0); + //涓�洿鎵ц锛岀洿鍒版弧瓒崇粨鏉熸潯浠�+ while (true) { - Conn.榛樿鏃ュ織.Error(ex.ToString()); + if (IsExitApp) { break; } + try + { + #region [鑴氭湰][20250708095248653][涓氬姟閫昏緫.鏂扮嚎绋嬫�绾縘 + AutoThread.InvokeMethod(AutoThread.Instance, "ThreaTotal", new object[] { tag, Device }); + #endregion [鑴氭湰][20250708095248653][涓氬姟閫昏緫.鏂扮嚎绋嬫�绾縘 + } + catch (Exception ex) + { + Conn.榛樿鏃ュ織.Error(ex.ToString()); + } + finally + { + System.Threading.Thread.Sleep(3000); + } } - finally - { - System.Threading.Thread.Sleep(3000); - } - } + ExitJudgeStack.TryPop(out int exitJudgeVal); + }); } /// <summary> @@ -933,7 +990,24 @@ Device.A2030鍙栬揣浜や簰?.Stop(); Device.RGV?.Stop(); Device.p鍙戦偅绉�涓嬬嚎?.Stop(); - Device.p鍙戦偅绉�涓婄嚎?.Stop(); + Device.D瀹氬瓙1鍙锋満姊版墜?.Stop(); + Device.D瀹氬瓙2鍙锋満姊版墜?.Stop(); + Device.S2027Read?.Stop(); + Device.S2020Read?.Stop(); + Device.S2013Read?.Stop(); + Device.S2027Write?.Stop(); + Device.S2020Write?.Stop(); + Device.S2013Write?.Stop(); + Device.S2001Write?.Stop(); + Device.S2008Write?.Stop(); + Device.S3001Read?.Stop(); + Device.S3006Read?.Stop(); + Device.S3005Read?.Stop(); + Device.S3010Read?.Stop(); + Device.A3001鏀捐揣浜や簰?.Stop(); + Device.A3005鍙栬揣浜や簰?.Stop(); + Device.A3006鏀捐揣浜や簰?.Stop(); + Device.A3010鍙栬揣浜や簰?.Stop(); } catch (Exception ex) { @@ -985,7 +1059,24 @@ || (Device.A2030鍙栬揣浜や簰 == null ? false : Device.A2030鍙栬揣浜や簰.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.RGV == null ? false : Device.RGV.State != GZ.Device.PLC.PlcRunState.Stoped) || (Device.p鍙戦偅绉�涓嬬嚎 == null ? false : Device.p鍙戦偅绉�涓嬬嚎.State != GZ.Device.PLC.PlcRunState.Stoped) - || (Device.p鍙戦偅绉�涓婄嚎 == null ? false : Device.p鍙戦偅绉�涓婄嚎.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.D瀹氬瓙1鍙锋満姊版墜 == null ? false : Device.D瀹氬瓙1鍙锋満姊版墜.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.D瀹氬瓙2鍙锋満姊版墜 == null ? false : Device.D瀹氬瓙2鍙锋満姊版墜.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2027Read == null ? false : Device.S2027Read.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2020Read == null ? false : Device.S2020Read.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2013Read == null ? false : Device.S2013Read.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2027Write == null ? false : Device.S2027Write.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2020Write == null ? false : Device.S2020Write.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2013Write == null ? false : Device.S2013Write.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2001Write == null ? false : Device.S2001Write.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S2008Write == null ? false : Device.S2008Write.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S3001Read == null ? false : Device.S3001Read.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S3006Read == null ? false : Device.S3006Read.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S3005Read == null ? false : Device.S3005Read.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.S3010Read == null ? false : Device.S3010Read.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.A3001鏀捐揣浜や簰 == null ? false : Device.A3001鏀捐揣浜や簰.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.A3005鍙栬揣浜や簰 == null ? false : Device.A3005鍙栬揣浜や簰.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.A3006鏀捐揣浜や簰 == null ? false : Device.A3006鏀捐揣浜や簰.State != GZ.Device.PLC.PlcRunState.Stoped) + || (Device.A3010鍙栬揣浜や簰 == null ? false : Device.A3010鍙栬揣浜や簰.State != GZ.Device.PLC.PlcRunState.Stoped) ) { System.Threading.Thread.Sleep(1000); @@ -1160,6 +1251,43 @@ var res = ToWMSMES.CreateTask.CreatePointTask(model); return JsonConvert.SerializeObject(res); } + case "/api/Wcs/initZZCache": + { + statusCode = System.Net.HttpStatusCode.OK; + + var rturn = new ReturnMsg + { + resultCode = 0, + resultMsg = "" + }; + try + { + LocRepository locRepository = new LocRepository(); + foreach (var item in Settings.deviceInfos.FindAll(x => x.deviceType == 2)) + { + foreach (var ssloc in item.deviceNo) + { + var ssl = locRepository.FindEntity(x => x.S_LOC_CODE == ssloc); + if (ssl != null && (ssl.N_CURRENT_NUM > 0 || ssl.S_LOCK_STATE != "鏃�)) + { + ssl.N_CURRENT_NUM = 0; + ssl.S_LOCK_STATE = "鏃�; + locRepository.Update(ssl); + } + } + } + } + catch (Exception ex) + { + LogHelper.Error("/api/Wcs/initZZCache" + requestJson + ex.Message, ex); + return JsonConvert.SerializeObject(new ReturnMsg + { + resultCode = -1, + resultMsg = ex.Message + }); + } + return JsonConvert.SerializeObject(rturn); + } } break; } @@ -1172,7 +1300,7 @@ statusCode = System.Net.HttpStatusCode.OK; // 澶嶅埗鍒癱ase 涓� //var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase) - var filePath = System.IO.Path.Combine("Static", path.Substring(1)); + var filePath = /*Directory.GetCurrentDirectory() + "\\Static" + "\\" + path.Substring(1);*/System.IO.Path.Combine(Directory.GetCurrentDirectory() + "\\Static", path.Substring(1)); return File.ReadAllText(filePath); } } -- Gitblit v1.9.1