From f8d23dcf8d6501482db1a5180325194232afe96c Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期五, 18 七月 2025 17:30:09 +0800 Subject: [PATCH] 封装部分业务代码,继续优化日志打印流程 --- Program.cs | 61 +++++++++++++++--------------- 1 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Program.cs b/Program.cs index d201d83..29085fa 100644 --- a/Program.cs +++ b/Program.cs @@ -1,17 +1,16 @@ 锘縰sing System; using System.Collections.Generic; using System.Threading; - -using HH.WCS.Mobox3.DSZSH.AppStart; using HH.WCS.Mobox3.DSZSH.device; -using HH.WCS.Mobox3.DSZSH.Helpers; -using HH.WCS.Mobox3.DSZSH.ServiceCore; +using HH.WCS.Mobox3.DSZSH.core; using Microsoft.Owin.Hosting; using Topshelf; using Task = System.Threading.Tasks.Task; +using Monitor = HH.WCS.Mobox3.DSZSH.core.Monitor; +using System.Net.Sockets; namespace HH.WCS.Mobox3.DSZSH { internal class Program @@ -22,11 +21,15 @@ // 1.0 寮�惎api Startup(); // 2.0 寮�惎tcp - StartTcp(); + //StartTcp(); // 3.0 寮�惎S7 - StartS7(); + //StartS7(); // 4.0 寮�惎Modbus //StartModbus(); + + // TCP娴嬭瘯 + //TcpClientHelper.Link("127.0.0.1", 8550); + Task.Run(() => { WCSCore.StartServer(); }); // 5.0 寮�惎绾跨▼ var rc = HostFactory.Run(x => { @@ -54,7 +57,7 @@ Console.WriteLine("Startup ApiController"); Task.Run(() => { - var url = AppStart.Settings.Config.WebApiUrl; // 杩愯鏃朵慨鏀�config.json 鏃犳晥 + var url = Settings.WebApiUrl; Console.WriteLine(url); using (WebApp.Start<Startup>(url)) { @@ -65,14 +68,17 @@ } /// <summary> - /// 寮�惎TCP鍗忚閫氳锛屾湇鍔$ + /// 寮�惎TCP鍗忚閫氳,鏈嶅姟绔� /// </summary> private static void StartTcp() { - var tcpServerIP = AppStart.Settings.Config.TcpServerIp; // 杩愯鏃朵慨鏀�config.json 鏃犳晥 - var tcpServerPort = AppStart.Settings.Config.TcpServerPort; // 杩愯鏃朵慨鏀�config.json 鏃犳晥 - new TcpServer(tcpServerIP, tcpServerPort); + //var tcpServerIP = Settings.TcpServerIp; + //var tcpServerPort = Settings.TcpServerPort; + //new TcpServer(tcpServerIP, tcpServerPort); + //var res = TcpClientHelper.Init(tcpServerIP, tcpServerPort); + //var res = TcpClientHelper.Init(tcpServerIP, 8550); + //LogHelper.Info($"TcpClient杩炴帴" + (res ? "鎴愬姛" : "澶辫触")); } /// <summary> @@ -91,18 +97,6 @@ // Console.WriteLine("S7ProductionLineHelper," + item.ProductionLine_IP); // } //} - - ////绉伴噸鐨凷7璁惧 - //var weightPLCDevice = Settings.WeightDevices; - - //if (weightPLCDevice.Count > 0) - //{ - // foreach (var item in weightPLCDevice) - // { - // new S7Helper(item.WeightDevice_IP, (short)item.WeightDevice_Rack, (short)item.WeightDevice_Slot); - // Console.WriteLine("S7WeightDeviceHelper," + item.WeightDevice_Name); - // } - //} } /// <summary> @@ -111,7 +105,7 @@ private static void StartModbus() { // 鎵�湁鐨凪odbus璁惧 - var allPLCDevice = AppStart.Settings.Config.ProductionLines; // 杩愯鏃朵慨鏀�config.json 鏃犳晥 + var allPLCDevice = Settings.ProductionLines; if (allPLCDevice.Count > 0) { foreach (var item in allPLCDevice) { @@ -127,14 +121,19 @@ { List<Task> tasks = new List<Task>(); - // 杞锛氬嚭搴撳崟鐘舵� - tasks.Add(GetTask(OutboundCore.CheckOrderState)); + tasks.Add(GetTask(WCSCore.Dispatch)); - // 杞锛氭娊妫�崟鐘舵� - tasks.Add(GetTask(CheckCore.CheckOrderState)); + // 娴嬭瘯:鎵樼洏涓嬬嚎 + //tasks.Add(GetTask(Monitor.CheckInbound)); - // 杞锛氱Щ搴撳崟鐘舵� - tasks.Add(GetTask(ShiftCore.CheckOrderState)); + // 杞:鍑哄簱鍗曠姸鎬�+ tasks.Add(GetTask(Monitor.CheckOutboundOrder)); + + // 杞:鎶芥鍗曠姸鎬�+ tasks.Add(GetTask(Monitor.CheckCheckOrder)); + + // 杞:绉诲簱鍗曠姸鎬�+ tasks.Add(GetTask(Monitor.CheckShiftOrder)); Task.WaitAll(tasks.ToArray()); } @@ -152,7 +151,7 @@ } catch (Exception ex) { - LogHelper.Error(ex.Message, ex); + LogHelper.InfoEx(ex); } Thread.Sleep(intervalMs); } -- Gitblit v1.9.1