diff --git a/SlnMesnac.Business/ProdCompletionBusiness.cs b/SlnMesnac.Business/ProdCompletionBusiness.cs index 51285a3..5eaace3 100644 --- a/SlnMesnac.Business/ProdCompletionBusiness.cs +++ b/SlnMesnac.Business/ProdCompletionBusiness.cs @@ -52,6 +52,8 @@ namespace SlnMesnac.Business public class ProdCompletionBusiness : BaseBusiness { private FJ500Comm.FJ500SP fj500s = new FJ500Comm.FJ500SP(); + //喷码机喷码失败或者设备状态检查重试次数 + private int PmTryAmount = 0; private readonly IMesProductPlanService _mesProductPlanService; private readonly IMesProductOrderService _mesProductOrderService; private readonly IMesPrdBarCodeService _barCodeTaskService; @@ -59,11 +61,13 @@ namespace SlnMesnac.Business private readonly IMesBaseBarcodeInfoService _mesBaseBarcodeInfoService; public readonly IMesPrdBarCodeService _mesPrdBarCodeService; private readonly IRealPalletTaskService _realPalletTaskService; - + private readonly UdpServer udpServer; + private DebugConfig debugConfig = DebugConfig.Instance; private ISqlSugarClient sqlSugarClient; 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 = serviceProvider.GetRequiredService(); UdpServer.ReceivedPMCodeEvent += PmCodeHandler; sqlSugarClient = _sqlSugarClient; _mesProductPlanService = mesProductPlanService; @@ -74,16 +78,16 @@ namespace SlnMesnac.Business _mesProductOrderService = serviceProvider.GetRequiredService(); _baseMaterialInfoService = serviceProvider.GetRequiredService(); Init(); - + } private void test() { - // MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.PlanCode == "20240724144533JL001"); - string epc = "A123456"; - _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto); - string bigCode = GenerateBigBarcode(productPlanDto, epc); - // BindingBarCode(bigCode, epc); + // MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.PlanCode == "20240724144533JL001"); + // string epc = "A123456"; + //_mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto); + // string bigCode = GenerateBigBarcode(productPlanDto, epc); + // BindingBarCode(bigCode, epc); } @@ -94,7 +98,7 @@ namespace SlnMesnac.Business Task.Run(async () => { - await EmptyPalletHandle(); + await EmptyPalletHandle(); }); Task.Run(() => @@ -102,8 +106,40 @@ namespace SlnMesnac.Business DeviceOutPutHandle(); }); + //喷码机设备状态检查 + checkPmStatus(); + } + + #region 喷码机设备相关通讯 + /// + /// 喷码机状态检查 + /// + public void checkPmStatus() + { + Task.Run(() => + { + while (true) + { + try + { + //发送检查状态指令 + // udpServer.SendMessage(fj500s.CheckState()); + // Thread.Sleep(1000 * 5); + // 重新发送带喷印条码,保证始终有条码 + SendFirstPmCode(); + + } + catch (Exception ex) + { + _logger.LogError("checkStatus异常:" + ex.Message); + } + Thread.Sleep(1000 * 30); + } + }); } + + /// /// 喷码机返回信息解析处理 /// 1.传输完成及喷码完成 @@ -112,37 +148,91 @@ namespace SlnMesnac.Business /// private void PmCodeHandler(string str) { - //设备状态30s一次 - if (str.Substring(0, 4) == "0A0C") - { - //推送最新需要打印条码,防止无可打印条码 - - var result = fj500s.GetState(str); - if (result == "0E") - { // 喷码机设备故障,todo 推送报警 - _logger.LogError("喷码机设备故障,待推送报警"); - } - } - else // 传输完成及喷码完成结果 + try { + int LastTryAmount = PmTryAmount; var result = fj500s.GetAck(str); - if(result == "00") + if (result == "00") { // 发送数据成功 + _logger.LogInformation("====================收到喷码机发送数据成功"); + PmTryAmount = 0; } - else if(result =="0E") + else if (result == "0E") { - // 发送数据失败,重新发送,超过10次失败推送报警 - }else if(result == "0F") + // 喷码机设备故障 + _logger.LogError($"====================收到喷码机设备状态检查故障或者喷印失败预警,喷码机重试次数:{PmTryAmount}"); + PmTryAmount++; + + if (PmTryAmount <= 30) + { + //重新发送 + Task.Run(() => + { + Thread.Sleep(1000 * 5); + SendFirstPmCode(); + }); + } + else + { + _logger.LogError("====================超过30次,推送报警"); + AddAlarm(WarnStatusEnum.喷码机设备状态检查故障或者喷印失败预警超过30次); + } + + } + else if (result == "0F") { - //打印完成,更新当前打印条码信息,并推送下一条信息 + _logger.LogInformation("====================收到喷码机打印完成,推送下一条待打印条码"); + updatePrdBarcodeInfo(); + SendFirstPmCode(); + _logger.LogInformation("====================推送下一条待打印条码成功"); + PmTryAmount = 0; + } + if (LastTryAmount>0 && PmTryAmount==0) + { // 报警消除 + _logger.LogInformation("喷码机报警消除"); + deleteAlarm(WarnStatusEnum.喷码机设备状态检查故障或者喷印失败预警超过30次); } + + } + catch (Exception ex) + { + _logger.LogError("PmCodeHandler喷码机回复信息解析处理异常:" + ex.Message); } } + /// + /// 获取数据库最早未喷印未绑定条码 + /// + private void SendFirstPmCode() + { + MesPrdBarcodeInfo mesPrdBarcodeInfo = _barCodeTaskService.Query(x => x.PrintFlag == "0" && x.BindStatus == 0).OrderBy(x => x.PrdBarcodeId).FirstOrDefault(); + if(mesPrdBarcodeInfo != null) + { + udpServer.SendMessage(mesPrdBarcodeInfo.PrdBarcodeInfo); + } + else + { + _logger.LogError("可喷码数不足,请检查原因"); + } + + } + /// + /// 喷印完成更新条码 + /// + private void updatePrdBarcodeInfo() + { + MesPrdBarcodeInfo mesPrdBarcodeInfo = _barCodeTaskService.Query(x => x.PrintFlag == "0" && x.BindStatus == 0).OrderBy(x => x.PrdBarcodeId).FirstOrDefault(); + mesPrdBarcodeInfo.PrintFlag = "1"; + mesPrdBarcodeInfo.PrintTime = DateTime.Now; + _barCodeTaskService.Update(mesPrdBarcodeInfo); + } + #endregion + + /// /// 设备产出逻辑处理 /// @@ -162,18 +252,18 @@ namespace SlnMesnac.Business Thread.Sleep(3000); continue; } - // plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), "JYHB01010125", 12); + // plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), "JYHB01010125", 12); + - if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"))) { _logger.LogInformation("等待小包出口信号触发......"); Thread.Sleep(5000); continue; } - - string rfid = plc.readStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"),12).Replace("\0",""); - + + string rfid = plc.readStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), 12).Replace("\0", ""); + if (!string.IsNullOrWhiteSpace(rfid)) { _logger.LogInformation("小包出口已经有RFID了,无需再读"); @@ -202,6 +292,7 @@ namespace SlnMesnac.Business _logger.LogError("小包出口到位信号触发,读取RFID失败超过5次......"); if (!string.IsNullOrEmpty(virtualEpc)) { + //TODU 虚拟托盘号需要在系统存储 epcStr = virtualEpc; _logger.LogError("小包出口到位信号触发,读取RFID失败超过5次,生成虚拟托盘号:" + virtualEpc); } @@ -219,8 +310,15 @@ namespace SlnMesnac.Business _mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto); if (productPlanDto == null) { - //TODO:没有计划的话,处理方式待定 - throw new ArgumentException($"未获取到正在执行的生产计划"); + + //throw new ArgumentException($"未获取到正在执行的生产计划"); + + //无计划时,按照无计划订单处理,MaterialId可修改,在配置文件 + productPlanDto = new MesProductPlanDto(); + productPlanDto.PlanCode = "0"; + productPlanDto.MaterialId = long.Parse(debugConfig.MaterialId); + productPlanDto.SaleOrderId = 0; + productPlanDto.SaleorderCode = "0"; } #region 开启事务 sqlSugarClient.AsTenant().BeginTran(); @@ -230,17 +328,17 @@ namespace SlnMesnac.Business BindingBarCode(bigCode, epcStr, productPlanDto); //3.更新mes_product_plan及mes_product_order表,更新已生产数量 UpdatePlanInfoAndOrder(productPlanDto); - + // 删除正在使用的数据库托盘号 List realPalletList = _realPalletTaskService.Query(x => x.PalletCode == epcStr); - if (realPalletList != null && realPalletList.Count>0) + if (realPalletList != null && realPalletList.Count > 0) { sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(realPalletList).ExecuteCommand(); } // 写入PLC RFID号供调度使用 - plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), epcStr,12); - // plc.writeByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"), 2); + plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), epcStr, 12); + // plc.writeByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"), 2); readRfidAmount = 0; sqlSugarClient.AsTenant().CommitTran(); #endregion @@ -255,83 +353,7 @@ namespace SlnMesnac.Business Thread.Sleep(1000 * 5); } } - /// - /// 推送报警,并生成虚拟托盘号暂时使用,虚拟托盘号储存到报警信息,人工处理可以将虚拟托盘号替换为正常托盘号 - /// 返回生产的虚拟托盘号 - /// - private string NoReadRFIDAlarm() - { - string epcStr; - try - { - epcStr = "TEMP" + DateTime.Now.ToString("MMddHHmm"); - sqlSugarClient.AsTenant().BeginTran(); - - // 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录 - int warnRuleId = int.Parse(WarnStatusEnum.小包出口读取RFID失败5次.GetDescription()); - DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); - if (dmsRecordAlarmTime == null) - { - DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); - - dmsRecordAlarmTime = new DmsRecordAlarmTime(); - dmsRecordAlarmTime.DeviceId = dmsBaseAlarmRule.DeviceId; - dmsRecordAlarmTime.AlarmRuleId = warnRuleId; - dmsRecordAlarmTime.AlarmBeginTime = DateTime.Now; - dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime; - dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason; - dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason; - dmsRecordAlarmTime.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString(); - dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr; - dmsRecordAlarmTime.CreateBy = "SlnMesnac"; - dmsRecordAlarmTime.CreateTime = DateTime.Now; - - DmsRecordAlarmInfo dmsRecordAlarmInfo = new DmsRecordAlarmInfo(); - dmsRecordAlarmInfo.DeviceId = dmsBaseAlarmRule.DeviceId; - dmsRecordAlarmInfo.AlarmRuleId = warnRuleId; - dmsRecordAlarmInfo.AlarmBeginTime = DateTime.Now; - dmsRecordAlarmInfo.AlarmStatus = "0"; - dmsRecordAlarmInfo.NoticeStatus = "0"; - dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime; - dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason; - dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason; - dmsRecordAlarmInfo.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString(); - dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr; - dmsRecordAlarmInfo.CreateBy = "SlnMesnac"; - dmsRecordAlarmInfo.CreateTime = DateTime.Now; - - sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmTime).ExecuteCommand(); - sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand(); - } - else - { - - dmsRecordAlarmTime.UpdateTime = DateTime.Now; - dmsRecordAlarmTime.UpdateBy = "SlnMesnac"; - DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); - if (dmsRecordAlarmInfo != null) - { - dmsRecordAlarmInfo.UpdateTime = DateTime.Now; - dmsRecordAlarmInfo.UpdateBy = "SlnMesnac"; - } - sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmTime).ExecuteCommand(); - sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand(); - - } - - sqlSugarClient.AsTenant().CommitTran(); - return epcStr; - } - catch (Exception ex) - { - sqlSugarClient.AsTenant().RollbackTran(); - _logger.LogError($"NoReadRFIDAlarm异常:{ex.Message}"); - return ""; - } - - } - - + /// /// 生成大条码插入mes_barcode_info; /// @@ -357,8 +379,8 @@ namespace SlnMesnac.Business mesBaseBarcodeInfo.productionDate = DateTime.Now; mesBaseBarcodeInfo.acceptedDate = DateTime.Now; mesBaseBarcodeInfo.planCode = productPlanDto.PlanCode; - MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x=>x.PlanCode== productPlanDto.PlanCode); - if(mesProductPlanDetail != null) + MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.PlanCode == productPlanDto.PlanCode); + if (mesProductPlanDetail != null) { mesBaseBarcodeInfo.planDetailCode = mesProductPlanDetail.PlanDetailCode; } @@ -395,8 +417,8 @@ namespace SlnMesnac.Business if (list.Where(x => x.PrintFlag == "1").ToList().Count < 40) { - // TODO推送低级别报警 - PrintLessThan40Alarm(); + // 推送低级别报警 + AddAlarm(WarnStatusEnum.托盘绑定时已喷码数不足40); } foreach (var item in list) { @@ -415,7 +437,7 @@ namespace SlnMesnac.Business palletInfo.MaterialId = productPlanDto.MaterialId; } sqlSugarClient.AsTenant().GetConnection("mes").Updateable(palletInfo).ExecuteCommand(); - + } private void UpdatePlanInfoAndOrder(MesProductPlanDto productPlanDto) @@ -423,12 +445,14 @@ namespace SlnMesnac.Business MesProductPlan productPlan = _mesProductPlanService.Query(x => x.PlanCode == productPlanDto.PlanCode).FirstOrDefault(); if (productPlan == null) { - throw new InvalidOperationException("未找到该生产计划!"); + _logger.LogInformation("未找到该生产计划对应的生产工单!,按照无工单处理,无需更新计划"); + return; } MesProductOrder productOrder = _mesProductOrderService.Query(x => x.ProductOrderId == productPlan.ProductOrderId).FirstOrDefault(); if (productPlan == null) { - throw new InvalidOperationException("未找到该生产计划对应的生产工单!"); + _logger.LogInformation("未找到该生产计划对应的生产工单!,按照无工单处理,无需更新计划"); + return; } #region 更新生产计划 if (productPlan.CompleteAmount == 0) @@ -468,18 +492,20 @@ namespace SlnMesnac.Business } + + #region 报警 /// - /// 小包产出绑定托盘,小包喷码数量小于40低级别报警 - /// 返回生产的虚拟托盘号 + /// + /// 插入报警 /// - private void PrintLessThan40Alarm() + private void AddAlarm(WarnStatusEnum warnStatusEnum) { try { sqlSugarClient.AsTenant().BeginTran(); // 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录 - int warnRuleId = int.Parse(WarnStatusEnum.托盘绑定时已喷码数不足40.GetDescription()); + int warnRuleId = int.Parse(warnStatusEnum.GetDescription()); DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); if (dmsRecordAlarmTime == null) { @@ -492,7 +518,7 @@ namespace SlnMesnac.Business dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime; dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason; dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason; - dmsRecordAlarmTime.AlarmData = WarnStatusEnum.托盘绑定时已喷码数不足40.ToString(); + dmsRecordAlarmTime.AlarmData = warnStatusEnum.ToString(); dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest; dmsRecordAlarmTime.CreateBy = "SlnMesnac"; dmsRecordAlarmTime.CreateTime = DateTime.Now; @@ -506,7 +532,7 @@ namespace SlnMesnac.Business dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime; dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason; dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason; - dmsRecordAlarmInfo.AlarmData = WarnStatusEnum.托盘绑定时已喷码数不足40.ToString(); + dmsRecordAlarmInfo.AlarmData = warnStatusEnum.ToString(); dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest; dmsRecordAlarmInfo.CreateBy = "SlnMesnac"; dmsRecordAlarmInfo.CreateTime = DateTime.Now; @@ -536,12 +562,118 @@ namespace SlnMesnac.Business catch (Exception ex) { sqlSugarClient.AsTenant().RollbackTran(); - _logger.LogError($"PrintLessThan40Alarm异常:{ex.Message}"); + _logger.LogError($"插入或者更新报错信息异常{warnStatusEnum.ToString()} ==>:{ex.Message}"); } } + /// + /// 消除报警 + /// + /// + private void deleteAlarm(WarnStatusEnum warnStatusEnum) + { + + DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == long.Parse(warnStatusEnum.GetDescription())); + if (dmsRecordAlarmTime != null) + { + sqlSugarClient.AsTenant().BeginTran(); + DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == dmsRecordAlarmTime.AlarmRuleId && x.AlarmStatus == "0"); + if (dmsRecordAlarmInfo != null) + { + dmsRecordAlarmInfo.AlarmEndTime = DateTime.Now; + dmsRecordAlarmInfo.AlarmStatus = "2"; + dmsRecordAlarmInfo.UpdateTime = DateTime.Now; + sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand(); + } + sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(dmsRecordAlarmTime).ExecuteCommand(); + + sqlSugarClient.AsTenant().CommitTran(); + } + } + + /// + /// 推送报警,并生成虚拟托盘号暂时使用,虚拟托盘号储存到报警信息,人工处理可以将虚拟托盘号替换为正常托盘号 + /// 返回生产的虚拟托盘号 + /// + private string NoReadRFIDAlarm() + { + string epcStr; + try + { + epcStr = "TEMP" + DateTime.Now.ToString("MMddHHmm"); + sqlSugarClient.AsTenant().BeginTran(); + + // 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录 + int warnRuleId = int.Parse(WarnStatusEnum.小包出口读取RFID失败5次.GetDescription()); + DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); + if (dmsRecordAlarmTime == null) + { + DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); + + dmsRecordAlarmTime = new DmsRecordAlarmTime(); + dmsRecordAlarmTime.DeviceId = dmsBaseAlarmRule.DeviceId; + dmsRecordAlarmTime.AlarmRuleId = warnRuleId; + dmsRecordAlarmTime.AlarmBeginTime = DateTime.Now; + dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime; + dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason; + dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason; + dmsRecordAlarmTime.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString(); + dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr; + dmsRecordAlarmTime.CreateBy = "SlnMesnac"; + dmsRecordAlarmTime.CreateTime = DateTime.Now; + + DmsRecordAlarmInfo dmsRecordAlarmInfo = new DmsRecordAlarmInfo(); + dmsRecordAlarmInfo.DeviceId = dmsBaseAlarmRule.DeviceId; + dmsRecordAlarmInfo.AlarmRuleId = warnRuleId; + dmsRecordAlarmInfo.AlarmBeginTime = DateTime.Now; + dmsRecordAlarmInfo.AlarmStatus = "0"; + dmsRecordAlarmInfo.NoticeStatus = "0"; + dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime; + dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason; + dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason; + dmsRecordAlarmInfo.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString(); + dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr; + dmsRecordAlarmInfo.CreateBy = "SlnMesnac"; + dmsRecordAlarmInfo.CreateTime = DateTime.Now; + + sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmTime).ExecuteCommand(); + sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand(); + } + else + { + + dmsRecordAlarmTime.UpdateTime = DateTime.Now; + dmsRecordAlarmTime.UpdateBy = "SlnMesnac"; + DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().First(x => x.AlarmRuleId == warnRuleId); + if (dmsRecordAlarmInfo != null) + { + dmsRecordAlarmInfo.UpdateTime = DateTime.Now; + dmsRecordAlarmInfo.UpdateBy = "SlnMesnac"; + } + sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmTime).ExecuteCommand(); + sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand(); + + } + + sqlSugarClient.AsTenant().CommitTran(); + return epcStr; + } + catch (Exception ex) + { + sqlSugarClient.AsTenant().RollbackTran(); + _logger.LogError($"NoReadRFIDAlarm异常:{ex.Message}"); + return ""; + } + + } + + + + #endregion + + /// /// 空托盘进入码垛位,读取RFID备用 /// diff --git a/SlnMesnac.Business/ProdMgmtBusiness.cs b/SlnMesnac.Business/ProdMgmtBusiness.cs index e3e4277..e8fa77d 100644 --- a/SlnMesnac.Business/ProdMgmtBusiness.cs +++ b/SlnMesnac.Business/ProdMgmtBusiness.cs @@ -84,8 +84,8 @@ namespace SlnMesnac.Business _mesPrdBarCodeService = serviceProvider.GetRequiredService(); _configInfoBusiness = configInfoBusiness; - //testRFID(); - + + } @@ -512,13 +512,15 @@ namespace SlnMesnac.Business /// private void GenerateBarcode(int amount) { + // JY2408271423CF015 List list = new List(); string baseDate = DateTime.Now.ToString("yyyyMMddHHmm"); // 褰撳墠鏃ユ湡鍜屾椂闂村埌鍒嗛挓 + baseDate = "JY" + baseDate.Substring(2); for (int i = 1; i <= amount; i++) { MesPrdBarcodeInfo record = new MesPrdBarcodeInfo(); record = new MesPrdBarcodeInfo(); - record.PrdBarcodeInfo = baseDate + i.ToString("D3"); // 灏嗗簭鍙锋牸寮忓寲涓轰笁浣嶆暟 + record.PrdBarcodeInfo = baseDate + "CF" + i.ToString("D3"); // 灏嗗簭鍙锋牸寮忓寲涓轰笁浣嶆暟 record.PrintFlag = "0"; record.CreatTime = DateTime.Now; record.BindStatus = 0; diff --git a/SlnMesnac.Config/DebugConfig.cs b/SlnMesnac.Config/DebugConfig.cs index 6f3bdfd..a84d94d 100644 --- a/SlnMesnac.Config/DebugConfig.cs +++ b/SlnMesnac.Config/DebugConfig.cs @@ -111,6 +111,16 @@ namespace SlnMesnac.Config } + /// + ///鏃犺鍒掓椂锛屾寜鐓ф棤璁″垝璁㈠崟澶勭悊锛孧aterialId鍙慨鏀 + /// + public string MaterialId + { + get { return iniHelper.IniReadValue("system", "MaterialId"); } + set { iniHelper.IniWriteValue("system", "MaterialId", value); } + } + + /// ///鍠风爜鏈篒P /// diff --git a/SlnMesnac.Extensions/MesPlcSingalSetup.cs b/SlnMesnac.Extensions/MesPlcSingalSetup.cs index d6c989d..4a877c5 100644 --- a/SlnMesnac.Extensions/MesPlcSingalSetup.cs +++ b/SlnMesnac.Extensions/MesPlcSingalSetup.cs @@ -51,6 +51,7 @@ namespace SlnMesnac.Extensions // 鍚姩UDP var udpSession = app.ApplicationServices.GetService(); udpSession.Init(3000); + // udpSession.Init(7749); return app; } diff --git a/SlnMesnac.Model/enums/WarnStatusEnum.cs b/SlnMesnac.Model/enums/WarnStatusEnum.cs index a51c2eb..368096f 100644 --- a/SlnMesnac.Model/enums/WarnStatusEnum.cs +++ b/SlnMesnac.Model/enums/WarnStatusEnum.cs @@ -66,6 +66,9 @@ namespace SlnMesnac.Model.enums 灏忓寘鍑哄彛璇诲彇RFID澶辫触5娆, [Description("2013")] - 鎵樼洏缁戝畾鏃跺凡鍠风爜鏁颁笉瓒40 + 鎵樼洏缁戝畾鏃跺凡鍠风爜鏁颁笉瓒40, + + [Description("2014")] + 鍠风爜鏈鸿澶囩姸鎬佹鏌ユ晠闅滄垨鑰呭柗鍗板け璐ラ璀﹁秴杩30娆 } } diff --git a/SlnMesnac.TouchSocket/UdpServer.cs b/SlnMesnac.TouchSocket/UdpServer.cs index a810b88..b8b5fd4 100644 --- a/SlnMesnac.TouchSocket/UdpServer.cs +++ b/SlnMesnac.TouchSocket/UdpServer.cs @@ -66,8 +66,17 @@ namespace SlnMesnac.TouchSocket { udpService.Received = (c, e) => { - string result = e.ByteBlock.ToString(); - _logger.LogInformation("鏀跺埌鍠风爜鏈哄洖澶=====銆"+result); + string result = e.ByteBlock.ToString().TrimEnd('\r', '\n');; + // _logger.LogInformation("鏀跺埌鍠风爜鏈哄洖澶=====銆"+result); + if(result== "~03040000FE79") + { + //娓呯悊鐢ㄦ埛鍖鸿繑鍥炴寚浠や笉鍋氬鐞 + } + else + { + ReceivedPMCodeEvent?.Invoke(result); + } + return EasyTask.CompletedTask; }; @@ -76,7 +85,7 @@ namespace SlnMesnac.TouchSocket udpService.Start(); _logger.LogInformation($"UdpServer鍚姩鎴愬姛锛岀洃鍚鍙o細{serverPort}"); - checkStatus(); + } catch (Exception ex) @@ -95,32 +104,19 @@ namespace SlnMesnac.TouchSocket { string[] data = new string[] { $"{message}" }; - string str = fj500s.SendData(data, 2); - - udpService.Send(new IPHost("192.168.2.51:3000").EndPoint, str); + string str0 = fj500s.ClearUser(); + string str = fj500s.SendData(data, 2); + + //娓呯悊鐢ㄦ埛鍖 + udpService.Send(new IPHost("192.168.2.51:3000").EndPoint, str0); + Thread.Sleep(20); + 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/Page/DevMonitorPage.xaml b/SlnMesnac.WPF/Page/DevMonitorPage.xaml index 3f5fd37..050ed63 100644 --- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml +++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml @@ -24,7 +24,7 @@