add-喷码机设备对接

dev
liuwf 2 months ago
parent 6346490cad
commit 7d04383998

@ -9,6 +9,7 @@ using SlnMesnac.Model.enums;
using SlnMesnac.Plc; using SlnMesnac.Plc;
using SlnMesnac.Repository.service; using SlnMesnac.Repository.service;
using SlnMesnac.Rfid; using SlnMesnac.Rfid;
using SlnMesnac.TouchSocket;
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -50,7 +51,7 @@ namespace SlnMesnac.Business
/// </summary> /// </summary>
public class ProdCompletionBusiness : BaseBusiness public class ProdCompletionBusiness : BaseBusiness
{ {
private FJ500Comm.FJ500SP fj500s = new FJ500Comm.FJ500SP();
private readonly IMesProductPlanService _mesProductPlanService; private readonly IMesProductPlanService _mesProductPlanService;
private readonly IMesProductOrderService _mesProductOrderService; private readonly IMesProductOrderService _mesProductOrderService;
private readonly IMesPrdBarCodeService _barCodeTaskService; private readonly IMesPrdBarCodeService _barCodeTaskService;
@ -63,6 +64,7 @@ namespace SlnMesnac.Business
public ProdCompletionBusiness(ISqlSugarClient _sqlSugarClient, ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) public ProdCompletionBusiness(ISqlSugarClient _sqlSugarClient, ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
{ {
UdpServer.ReceivedPMCodeEvent += PmCodeHandler;
sqlSugarClient = _sqlSugarClient; sqlSugarClient = _sqlSugarClient;
_mesProductPlanService = mesProductPlanService; _mesProductPlanService = mesProductPlanService;
_barCodeTaskService = barCodeTaskService; _barCodeTaskService = barCodeTaskService;
@ -102,6 +104,45 @@ namespace SlnMesnac.Business
} }
/// <summary>
/// 喷码机返回信息解析处理
/// 1.传输完成及喷码完成
/// 2.喷码机状态检查
/// </summary>
/// <param name="str"></param>
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")
{
//打印完成,更新当前打印条码信息,并推送下一条信息
}
}
}
/// <summary> /// <summary>
/// É豸²ú³öÂß¼­´¦Àí /// É豸²ú³öÂß¼­´¦Àí
/// </summary> /// </summary>

@ -6,10 +6,17 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" /> <ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" /> <ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" /> <ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" /> <ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="FJ500_ExtData">
<HintPath>..\SlnMesnac.Common\DLL\FJ500_ExtData.dll</HintPath>
</Reference>
</ItemGroup>
</Project> </Project>

@ -104,10 +104,6 @@ namespace SlnMesnac.Common
/// <param name="data"></param> /// <param name="data"></param>
public void SendData(string data) public void SendData(string data)
{ {
// string[] data1 = new string[] { "123" };
//// string[] data = new string[] { "202408101111" };
// fj500sF.SendData( data1, 2);
byte[] buffer = GetBytesByCommand(data); byte[] buffer = GetBytesByCommand(data);

@ -47,6 +47,10 @@ namespace SlnMesnac.Extensions
}; };
_server.Init(6000); _server.Init(6000);
// 启动UDP
var udpSession = app.ApplicationServices.GetService<UdpServer>();
udpSession.Init(3000);
return app; return app;
} }

@ -15,4 +15,10 @@
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" /> <ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="FJ500_ExtData">
<HintPath>..\SlnMesnac.Common\DLL\FJ500_ExtData.dll</HintPath>
</Reference>
</ItemGroup>
</Project> </Project>

@ -59,7 +59,7 @@ namespace SlnMesnac.TouchSocket
{ {
try try
{ {
_logger.LogInformation("tcp启动");
_service.Connecting = (client, e) => { _service.Connecting = (client, e) => {
_logger.LogInformation($"客户端{client.IP}正在接入服务"); _logger.LogInformation($"客户端{client.IP}正在接入服务");
return EasyTask.CompletedTask; return EasyTask.CompletedTask;

@ -0,0 +1,126 @@
using 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
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.TouchSocket
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.TouchSocket
{
public class UdpServer
{
private readonly UdpSession udpService = new UdpSession();
private ILogger<UdpServer> _logger;
/// <summary>
/// 接收喷码机反馈
/// </summary>
public delegate void ReceivedPMCode(string str);
public static event ReceivedPMCode? ReceivedPMCodeEvent;
private FJ500SP fj500s = new FJ500SP();
public UdpServer(ILogger<UdpServer> 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启动成功监听端口{serverPort}");
checkStatus();
}
catch (Exception ex)
{
_logger.LogError($"UdpServer启动异常{ex.Message}");
}
}
/// <summary>
/// 发送条码数据
/// </summary>
/// <param name="message"></param>
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);
}
});
}
}
}

@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration;
using SlnMesnac.Ioc; using SlnMesnac.Ioc;
using SlnMesnac.Extensions; using SlnMesnac.Extensions;
using SlnMesnac.Generate; using SlnMesnac.Generate;
using SlnMesnac.TouchSocket;
namespace SlnMesnac.WPF namespace SlnMesnac.WPF
{ {

@ -4,9 +4,12 @@ using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SlnMesnac.Business.@base; using SlnMesnac.Business.@base;
using SlnMesnac.TouchSocket;
using SlnMesnac.WPF.Page; using SlnMesnac.WPF.Page;
using SlnMesnac.WPF.Page.Generate; using SlnMesnac.WPF.Page.Generate;
using System; using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
namespace SlnMesnac.WPF.ViewModel namespace SlnMesnac.WPF.ViewModel
@ -97,6 +100,8 @@ namespace SlnMesnac.WPF.ViewModel
} }
/// <summary> /// <summary>
/// 窗体控制 /// 窗体控制
/// </summary> /// </summary>

@ -39,7 +39,7 @@ namespace SlnMesnac.WPF.ViewModel
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>(); private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
private readonly GunHelper gunHelper = GunHelper.Instance;
#region 参数定义 #region 参数定义
/// <summary> /// <summary>
@ -169,7 +169,7 @@ namespace SlnMesnac.WPF.ViewModel
public ProdMgmtViewModel() public ProdMgmtViewModel()
{ {
gunHelper.InstanceSerialPort();
StartProdPlanCommand = new RelayCommand<string>(obj => StartProdPlan(obj)); StartProdPlanCommand = new RelayCommand<string>(obj => StartProdPlan(obj));
StopProdPlanCommand = new RelayCommand<string>(obj => StopProdPlan(obj)); StopProdPlanCommand = new RelayCommand<string>(obj => StopProdPlan(obj));

Loading…
Cancel
Save