diff --git a/SlnMesnac.Business/ProdCompletionBusiness.cs b/SlnMesnac.Business/ProdCompletionBusiness.cs index ce7b532..51285a3 100644 --- a/SlnMesnac.Business/ProdCompletionBusiness.cs +++ b/SlnMesnac.Business/ProdCompletionBusiness.cs @@ -9,6 +9,7 @@ using SlnMesnac.Model.enums; using SlnMesnac.Plc; using SlnMesnac.Repository.service; using SlnMesnac.Rfid; +using SlnMesnac.TouchSocket; using SqlSugar; using System; using System.Collections.Generic; @@ -50,7 +51,7 @@ namespace SlnMesnac.Business /// public class ProdCompletionBusiness : BaseBusiness { - + private FJ500Comm.FJ500SP fj500s = new FJ500Comm.FJ500SP(); private readonly IMesProductPlanService _mesProductPlanService; private readonly IMesProductOrderService _mesProductOrderService; private readonly IMesPrdBarCodeService _barCodeTaskService; @@ -63,6 +64,7 @@ namespace SlnMesnac.Business public ProdCompletionBusiness(ISqlSugarClient _sqlSugarClient, ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) { + UdpServer.ReceivedPMCodeEvent += PmCodeHandler; sqlSugarClient = _sqlSugarClient; _mesProductPlanService = mesProductPlanService; _barCodeTaskService = barCodeTaskService; @@ -102,6 +104,45 @@ namespace SlnMesnac.Business } + /// + /// 喷码机返回信息解析处理 + /// 1.传输完成及喷码完成 + /// 2.喷码机状态检查 + /// + /// + private void PmCodeHandler(string str) + { + //设备状态30s一次 + if (str.Substring(0, 4) == "0A0C") + { + //推送最新需要打印条码,防止无可打印条码 + + var result = fj500s.GetState(str); + if (result == "0E") + { // 喷码机设备故障,todo 推送报警 + _logger.LogError("喷码机设备故障,待推送报警"); + } + } + else // 传输完成及喷码完成结果 + { + var result = fj500s.GetAck(str); + if(result == "00") + { + // 发送数据成功 + } + else if(result =="0E") + { + // 发送数据失败,重新发送,超过10次失败推送报警 + }else if(result == "0F") + { + //打印完成,更新当前打印条码信息,并推送下一条信息 + + } + } + } + + + /// /// 设备产出逻辑处理 /// diff --git a/SlnMesnac.Business/SlnMesnac.Business.csproj b/SlnMesnac.Business/SlnMesnac.Business.csproj index 6d188fe..a5a954f 100644 --- a/SlnMesnac.Business/SlnMesnac.Business.csproj +++ b/SlnMesnac.Business/SlnMesnac.Business.csproj @@ -6,10 +6,17 @@ + + + + ..\SlnMesnac.Common\DLL\FJ500_ExtData.dll + + + diff --git a/SlnMesnac.Common/GunHelper.cs b/SlnMesnac.Common/GunHelper.cs index 3d5834e..ba6af39 100644 --- a/SlnMesnac.Common/GunHelper.cs +++ b/SlnMesnac.Common/GunHelper.cs @@ -104,11 +104,7 @@ namespace SlnMesnac.Common /// public void SendData(string data) { - // string[] data1 = new string[] { "123" }; - //// string[] data = new string[] { "202408101111" }; - // fj500sF.SendData( data1, 2); - - + byte[] buffer = GetBytesByCommand(data); serialPort.Write(buffer, 0, buffer.Length); diff --git a/SlnMesnac.Extensions/MesPlcSingalSetup.cs b/SlnMesnac.Extensions/MesPlcSingalSetup.cs index 6d6ee76..d6c989d 100644 --- a/SlnMesnac.Extensions/MesPlcSingalSetup.cs +++ b/SlnMesnac.Extensions/MesPlcSingalSetup.cs @@ -47,6 +47,10 @@ namespace SlnMesnac.Extensions }; _server.Init(6000); + + // 鍚姩UDP + var udpSession = app.ApplicationServices.GetService(); + udpSession.Init(3000); return app; } diff --git a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj b/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj index 95945bb..2376737 100644 --- a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj +++ b/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj @@ -15,4 +15,10 @@ + + + ..\SlnMesnac.Common\DLL\FJ500_ExtData.dll + + + diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs index 41b67c8..93ea509 100644 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ b/SlnMesnac.TouchSocket/TcpServer.cs @@ -59,7 +59,7 @@ namespace SlnMesnac.TouchSocket { try { - + _logger.LogInformation("tcp鍚姩"); _service.Connecting = (client, e) => { _logger.LogInformation($"瀹㈡埛绔瘂client.IP}姝e湪鎺ュ叆鏈嶅姟"); return EasyTask.CompletedTask; diff --git a/SlnMesnac.TouchSocket/UdpServer.cs b/SlnMesnac.TouchSocket/UdpServer.cs new file mode 100644 index 0000000..a810b88 --- /dev/null +++ b/SlnMesnac.TouchSocket/UdpServer.cs @@ -0,0 +1,126 @@ +锘縰sing FJ500Comm; +using Microsoft.Extensions.Logging; +using SlnMesnac.Common; +using SlnMesnac.Config; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using TouchSocket.Core; +using TouchSocket.Sockets; + +#region << 鐗 鏈 娉 閲 >> +/*-------------------------------------------------------------------- +* 鐗堟潈鎵鏈 (c) 2024 WenJY 淇濈暀鎵鏈夋潈鍒┿ +* CLR鐗堟湰锛4.0.30319.42000 +* 鏈哄櫒鍚嶇О锛歀APTOP-E0N2L34V +* 鍛藉悕绌洪棿锛歋lnMesnac.TouchSocket +* 鍞竴鏍囪瘑锛496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 +* +* 鍒涘缓鑰咃細WenJY +* 鐢靛瓙閭锛歸enjy@mesnac.com +* 鍒涘缓鏃堕棿锛2024-03-27 21:58:35 +* 鐗堟湰锛歏1.0.0 +* 鎻忚堪锛 +* +*-------------------------------------------------------------------- +* 淇敼浜猴細 +* 鏃堕棿锛 +* 淇敼璇存槑锛 +* +* 鐗堟湰锛歏1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 鐗 鏈 娉 閲 >> +namespace SlnMesnac.TouchSocket +{ + public class UdpServer + { + + private readonly UdpSession udpService = new UdpSession(); + private ILogger _logger; + + + /// + /// 鎺ユ敹鍠风爜鏈哄弽棣 + /// + public delegate void ReceivedPMCode(string str); + public static event ReceivedPMCode? ReceivedPMCodeEvent; + + + + private FJ500SP fj500s = new FJ500SP(); + + + public UdpServer(ILogger logger) + { + _logger = logger; + + } + + + public void Init(int serverPort) + { + try + { + udpService.Received = (c, e) => + { + string result = e.ByteBlock.ToString(); + _logger.LogInformation("鏀跺埌鍠风爜鏈哄洖澶=====銆"+result); + return EasyTask.CompletedTask; + }; + + udpService.Setup(new TouchSocketConfig() + .SetBindIPHost(new IPHost(serverPort))); + udpService.Start(); + + _logger.LogInformation($"UdpServer鍚姩鎴愬姛锛岀洃鍚鍙o細{serverPort}"); + checkStatus(); + + } + catch (Exception ex) + { + + _logger.LogError($"UdpServer鍚姩寮傚父锛歿ex.Message}"); + } + + } + + /// + /// 鍙戦佹潯鐮佹暟鎹 + /// + /// + public void SendMessage(string message) + { + string[] data = new string[] { $"{message}" }; + + string str = fj500s.SendData(data, 2); + + udpService.Send(new IPHost("192.168.2.51:3000").EndPoint, str); + } + + + + public void checkStatus() + { + Task.Run(() => + { + while (true) + { + try + { + //鍙戦佹鏌ョ姸鎬佹寚浠 + SendMessage(fj500s.CheckState()); + + }catch (Exception ex) + { + _logger.LogError("checkStatus寮傚父:"+ex.Message); + } + Thread.Sleep(1000*30); + } + }); + } + + } +} diff --git a/SlnMesnac.WPF/Startup.cs b/SlnMesnac.WPF/Startup.cs index c0aae3a..0933c25 100644 --- a/SlnMesnac.WPF/Startup.cs +++ b/SlnMesnac.WPF/Startup.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration; using SlnMesnac.Ioc; using SlnMesnac.Extensions; using SlnMesnac.Generate; +using SlnMesnac.TouchSocket; namespace SlnMesnac.WPF { @@ -50,7 +51,7 @@ namespace SlnMesnac.WPF //RFID services.AddRfidFactorySetup(); - + } /// diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 7929e01..adda4ed 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -4,9 +4,12 @@ using GalaSoft.MvvmLight.Command; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using SlnMesnac.Business.@base; +using SlnMesnac.TouchSocket; using SlnMesnac.WPF.Page; using SlnMesnac.WPF.Page.Generate; using System; +using System.Threading; +using System.Threading.Tasks; using System.Windows; namespace SlnMesnac.WPF.ViewModel @@ -94,9 +97,11 @@ namespace SlnMesnac.WPF.ViewModel ControlOnClickCommand = new RelayCommand(obj => ControlOnClick(obj)); FormControlCommand = new RelayCommand(x => FormControl(x)); - + } + + /// /// 绐椾綋鎺у埗 /// diff --git a/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs b/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs index 321a40d..a4cd616 100644 --- a/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs @@ -39,7 +39,7 @@ namespace SlnMesnac.WPF.ViewModel private ObservableCollection listItems = new ObservableCollection(); - private readonly GunHelper gunHelper = GunHelper.Instance; + #region 鍙傛暟瀹氫箟 /// @@ -169,7 +169,7 @@ namespace SlnMesnac.WPF.ViewModel public ProdMgmtViewModel() { - gunHelper.InstanceSerialPort(); + StartProdPlanCommand = new RelayCommand(obj => StartProdPlan(obj)); StopProdPlanCommand = new RelayCommand(obj => StopProdPlan(obj));