add-喷码机对接完成,并添加喷码机报警

dev
liuwf 5 months ago
parent 7d04383998
commit 5ee2442966

@ -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<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
{
udpServer = serviceProvider.GetRequiredService<UdpServer>();
UdpServer.ReceivedPMCodeEvent += PmCodeHandler;
sqlSugarClient = _sqlSugarClient;
_mesProductPlanService = mesProductPlanService;
@ -74,16 +78,16 @@ namespace SlnMesnac.Business
_mesProductOrderService = serviceProvider.GetRequiredService<IMesProductOrderService>();
_baseMaterialInfoService = serviceProvider.GetRequiredService<IBaseMaterialInfoService>();
Init();
}
private void test()
{
// MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().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<MesProductPlanDetail>().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 喷码机设备相关通讯
/// <summary>
/// 喷码机状态检查
/// </summary>
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);
}
});
}
/// <summary>
/// 喷码机返回信息解析处理
/// 1.传输完成及喷码完成
@ -112,37 +148,91 @@ namespace SlnMesnac.Business
/// <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 // 传输完成及喷码完成结果
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);
}
}
/// <summary>
/// 获取数据库最早未喷印未绑定条码
/// </summary>
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("可喷码数不足,请检查原因");
}
}
/// <summary>
/// 喷印完成更新条码
/// </summary>
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
/// <summary>
/// 设备产出逻辑处理
/// </summary>
@ -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<RealPalletTask> 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);
}
}
/// <summary>
/// 推送报警,并生成虚拟托盘号暂时使用,虚拟托盘号储存到报警信息,人工处理可以将虚拟托盘号替换为正常托盘号
/// <return> 返回生产的虚拟托盘号
/// </summary>
private string NoReadRFIDAlarm()
{
string epcStr;
try
{
epcStr = "TEMP" + DateTime.Now.ToString("MMddHHmm");
sqlSugarClient.AsTenant().BeginTran();
// 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录
int warnRuleId = int.Parse(WarnStatusEnum.RFID5.GetDescription());
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == warnRuleId);
if (dmsRecordAlarmTime == null)
{
DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsBaseAlarmRule>().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.RFID5.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.RFID5.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<DmsRecordAlarmInfo>().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 "";
}
}
/// <summary>
/// 生成大条码插入mes_barcode_info
/// </summary>
@ -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<MesProductPlanDetail>().First(x=>x.PlanCode== productPlanDto.PlanCode);
if(mesProductPlanDetail != null)
MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().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 报警
/// <summary>
/// 小包产出绑定托盘小包喷码数量小于40低级别报警
/// <return> 返回生产的虚拟托盘号
///
/// 插入报警
/// </summary>
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<DmsRecordAlarmTime>().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}");
}
}
/// <summary>
/// 消除报警
/// </summary>
/// <exception cref="InvalidOperationException"></exception>
private void deleteAlarm(WarnStatusEnum warnStatusEnum)
{
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == long.Parse(warnStatusEnum.GetDescription()));
if (dmsRecordAlarmTime != null)
{
sqlSugarClient.AsTenant().BeginTran();
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().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();
}
}
/// <summary>
/// 推送报警,并生成虚拟托盘号暂时使用,虚拟托盘号储存到报警信息,人工处理可以将虚拟托盘号替换为正常托盘号
/// <return> 返回生产的虚拟托盘号
/// </summary>
private string NoReadRFIDAlarm()
{
string epcStr;
try
{
epcStr = "TEMP" + DateTime.Now.ToString("MMddHHmm");
sqlSugarClient.AsTenant().BeginTran();
// 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录
int warnRuleId = int.Parse(WarnStatusEnum.RFID5.GetDescription());
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == warnRuleId);
if (dmsRecordAlarmTime == null)
{
DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsBaseAlarmRule>().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.RFID5.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.RFID5.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<DmsRecordAlarmInfo>().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
/// <summary>
/// 空托盘进入码垛位,读取RFID备用
/// </summary>

@ -84,8 +84,8 @@ namespace SlnMesnac.Business
_mesPrdBarCodeService = serviceProvider.GetRequiredService<IMesPrdBarCodeService>();
_configInfoBusiness = configInfoBusiness;
//testRFID();
}
@ -512,13 +512,15 @@ namespace SlnMesnac.Business
/// </summary>
private void GenerateBarcode(int amount)
{
// JY2408271423CF015
List<MesPrdBarcodeInfo> list = new List<MesPrdBarcodeInfo>();
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;

@ -111,6 +111,16 @@ namespace SlnMesnac.Config
}
/// <summary>
///无计划时按照无计划订单处理MaterialId可修改
/// </summary>
public string MaterialId
{
get { return iniHelper.IniReadValue("system", "MaterialId"); }
set { iniHelper.IniWriteValue("system", "MaterialId", value); }
}
/// <summary>
///喷码机IP
/// </summary>

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

@ -66,6 +66,9 @@ namespace SlnMesnac.Model.enums
RFID5,
[Description("2013")]
40
40,
[Description("2014")]
30
}
}

@ -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启动成功监听端口{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);
}
});
}
}
}

@ -24,7 +24,7 @@
<Button x:Name="StopButton" Style="{StaticResource BUTTON_AGREE}" Content="一键停止" FontSize="30" Background="OrangeRed" Width="180" Height="60" Margin="0,0,20,0" Click="StopButton_Click"/>
<Button x:Name="StopUrgentButton" Style="{StaticResource BUTTON_AGREE}" Content="急停" FontSize="30" Background="#E4B74C" Width="150" Height="60" Margin="0,0,0,0" Click="StopUrgentButton_Click"/>
<TextBlock Text="缓存区重量:" FontSize="25" VerticalAlignment="Center" Width="140" Foreground="White" HorizontalAlignment="Left" Margin="200 0 10 0" />
<TextBlock Text="缓存区重量:" FontSize="25" VerticalAlignment="Center" Width="140" Foreground="White" HorizontalAlignment="Left" Margin="150 0 10 0" />
<TextBlock x:Name="BufferWeightTxt" Text="0" Width="80" FontSize="25" VerticalAlignment="Center" Margin="0,0,20,0" Foreground="White"/>
<Button x:Name="SetStopWeightButton" Style="{StaticResource BUTTON_AGREE}" Content="设置重量阈值" FontSize="30" Background="CadetBlue" Width="200" Height="60" Margin="0 0 20 0" HorizontalAlignment="Left" Click="SetStopWeightButton_Click" />

@ -210,10 +210,10 @@ namespace SlnMesnac.WPF.Page
bool unPackStatus = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态"));
if (unPackStatus && (Cache_MaxWeight <= Cache_Weight))
{
// 所有机器停机
// 拆包
Task.Run(() =>
{
StopMachine(99);
StopMachine(0);
MessageBox.Show($"设备缓存区当前重量:{Cache_Weight},预设最大重量值:{Cache_MaxWeight},已经超重并且拆包机运行,系统下发停机命令!");
_logger.LogError($"设备缓存区当前重量:{Cache_Weight},预设最大重量值:{Cache_MaxWeight},已经超重并且拆包机运行,系统下发停机命令!");
@ -745,7 +745,11 @@ namespace SlnMesnac.WPF.Page
MessageBox.Show("螺旋2MES允许远程未切换远程");
return;
}
StartButton.IsEnabled = false;
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
StartButton.IsEnabled = false;
}));
Task.Run(() =>
{
@ -780,9 +784,13 @@ namespace SlnMesnac.WPF.Page
#endregion
if (unpackStatus)
{
MessageBoxAndLog("一键启动所有机器成功!");
recipeManageCache.SystemStatus = "1";
StartButton.IsEnabled = true;
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
StartButton.IsEnabled = true;
}));
}
});
@ -806,7 +814,12 @@ namespace SlnMesnac.WPF.Page
{
try
{
StopButton.IsEnabled = false;
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
StopButton.IsEnabled = false;
}));
#region 依次按序停止
Task.Run(() =>
{
@ -815,7 +828,11 @@ namespace SlnMesnac.WPF.Page
{
MessageBoxAndLog("一键停止所有机器成功!");
recipeManageCache.SystemStatus = "0";
StopButton.IsEnabled = true;
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
StopButton.IsEnabled = true;
}));
}
});
@ -1710,7 +1727,6 @@ namespace SlnMesnac.WPF.Page
realtimeStatusList.First(x => x.StatusCode == "MagNet_Status").StatusValue = MagNet_Status.ToString();
realtimeStatusList.First(x => x.StatusCode == "MagNet_MesUse_Flag").StatusValue = MagNet_MesUse_Flag.ToString();
}
catch (Exception ex)
{

Loading…
Cancel
Save