增加日志打印

This commit is contained in:
anerx 2025-03-18 18:32:10 +08:00
parent 957917bc4d
commit 84851bbb0d

View File

@ -1,5 +1,6 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text.Json;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Seyounth.Hyosung.Core.Agv; using Seyounth.Hyosung.Core.Agv;
using Seyounth.Hyosung.Core.Plc; using Seyounth.Hyosung.Core.Plc;
@ -73,6 +74,9 @@ public class HyosungRuntime(
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private async Task OnPlcRequestScanFixture(int fixtureId) private async Task OnPlcRequestScanFixture(int fixtureId)
{
logger.LogInformation($"plc request scan fixture:{fixtureId}");
try
{ {
var fix = await hyosungScannerService.ScanFixtureAsync(fixtureId); var fix = await hyosungScannerService.ScanFixtureAsync(fixtureId);
if (string.IsNullOrEmpty(fix)) if (string.IsNullOrEmpty(fix))
@ -86,6 +90,13 @@ public class HyosungRuntime(
logger.LogInformation($"scan fixture{fixtureId} success: {fix}"); logger.LogInformation($"scan fixture{fixtureId} success: {fix}");
} }
} }
catch (Exception e)
{
await hyosungPlcService.WriteScanFixtureResultAsync(fixtureId, false);
logger.LogError(e, $"scan fixture{fixtureId} fail");
}
}
/// <summary> /// <summary>
/// 处理PLC请求扫描纱事件 /// 处理PLC请求扫描纱事件
@ -94,6 +105,8 @@ public class HyosungRuntime(
private async Task OnPlcRequestScanProduct(int varietyId) private async Task OnPlcRequestScanProduct(int varietyId)
{ {
logger.LogInformation($"plc request scan yarn qrcode"); logger.LogInformation($"plc request scan yarn qrcode");
try
{
var yarn = await hyosungScannerService.ScanYarnAsync(varietyId); var yarn = await hyosungScannerService.ScanYarnAsync(varietyId);
if (yarn is null) if (yarn is null)
{ {
@ -109,10 +122,17 @@ public class HyosungRuntime(
logger.LogInformation($"scan yarn fail,lot not equal"); logger.LogInformation($"scan yarn fail,lot not equal");
return; return;
} }
await yarnService.AddYarnAsync(yarn); await yarnService.AddYarnAsync(yarn);
await hyosungPlcService.WriteScanYarnResultAsync(true, (short)varietyId, yarn.ScanCode); await hyosungPlcService.WriteScanYarnResultAsync(true, (short)varietyId, yarn.ScanCode);
logger.LogInformation($"scan yarn {yarn.ScanCode} success: qrcode[{yarn.QrCode}]"); logger.LogInformation($"scan yarn {yarn.ScanCode} success: qrcode[{yarn.QrCode}]");
} }
catch (Exception e)
{
await hyosungPlcService.WriteScanYarnResultAsync(false);
logger.LogError(e, $"scan yarn fail");
}
}
/// <summary> /// <summary>
/// 处理PLC请求下线事件 /// 处理PLC请求下线事件
@ -121,11 +141,19 @@ public class HyosungRuntime(
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private async Task OnPlcRequestLeavingProductionLine(PlcStackInfo info) private async Task OnPlcRequestLeavingProductionLine(PlcStackInfo info)
{ {
//使托盘完成 logger.LogInformation($"plc request leaving production line");
try
{
await trayService.StorageAsync(info.TrayCode); await trayService.StorageAsync(info.TrayCode);
await hyosungAgvService.StorageAsync(info.TrayCode); await hyosungAgvService.StorageAsync(info.TrayCode);
//标志下线已完成 //标志下线已完成
await hyosungPlcService.LeaveCompletedAsync(); await hyosungPlcService.LeaveCompletedAsync();
logger.LogInformation($"plc leaving production line success");
}
catch (Exception e)
{
logger.LogError(e, $"plc leaving production line fail");
}
} }
@ -137,6 +165,9 @@ public class HyosungRuntime(
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private async Task OnPlcNeedNewTrayCode(int index, int varietyId) private async Task OnPlcNeedNewTrayCode(int index, int varietyId)
{
logger.LogInformation($"plc request new tray code:{index} {varietyId}");
try
{ {
var tray = await trayService.GeneraNewTray(varietyId); var tray = await trayService.GeneraNewTray(varietyId);
var variety = await varietyService.GetById(varietyId); var variety = await varietyService.GetById(varietyId);
@ -157,6 +188,12 @@ public class HyosungRuntime(
} }
await hyosungPlcService.WriteTrayCodeAsync(index, tray.TrayCode); await hyosungPlcService.WriteTrayCodeAsync(index, tray.TrayCode);
logger.LogInformation($"plc request new tray code success: {tray.TrayCode}");
}
catch (Exception e)
{
logger.LogError(e, $"plc request new tray code fail");
}
} }
/// <summary> /// <summary>
@ -166,6 +203,9 @@ public class HyosungRuntime(
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private async Task OnPlcPutCompleted(PlcStackingInfo arg) private async Task OnPlcPutCompleted(PlcStackingInfo arg)
{
logger.LogInformation($"plc put completed:{JsonSerializer.Serialize(arg)}");
try
{ {
if (arg.TrayCode == Stack1.TrayCode) if (arg.TrayCode == Stack1.TrayCode)
{ {
@ -191,6 +231,12 @@ public class HyosungRuntime(
} }
await hyosungPlcService.WriteReceivedYarnCountAsync(arg.YarnCode.Count); await hyosungPlcService.WriteReceivedYarnCountAsync(arg.YarnCode.Count);
logger.LogInformation($"plc put completed success");
}
catch (Exception e)
{
logger.LogError(e, $"plc put completed fail");
}
} }
/// <summary> /// <summary>
@ -200,6 +246,9 @@ public class HyosungRuntime(
/// <returns></returns> /// <returns></returns>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private async Task OnPlcRequestPackLineOption(string arg) private async Task OnPlcRequestPackLineOption(string arg)
{
logger.LogInformation($"plc request pack line option");
try
{ {
var tray = await trayService.GetByCode(arg); var tray = await trayService.GetByCode(arg);
var variety = await varietyService.GetById(tray.VarietyId); var variety = await varietyService.GetById(tray.VarietyId);
@ -222,6 +271,12 @@ public class HyosungRuntime(
TrayCode = arg TrayCode = arg
}; };
await hyosungPlcService.WritePackLineOptionAsync(PackLineOption); await hyosungPlcService.WritePackLineOptionAsync(PackLineOption);
logger.LogInformation($"plc request pack line option success");
}
catch (Exception e)
{
logger.LogError(e, $"plc request pack line option fail");
}
} }
/// <summary> /// <summary>
@ -233,6 +288,7 @@ public class HyosungRuntime(
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private async Task OnPlcRequestPrintLabel(int arg1, string trayCode, int height) private async Task OnPlcRequestPrintLabel(int arg1, string trayCode, int height)
{ {
logger.LogInformation($"plc request print label:{arg1} {trayCode} {height}");
try try
{ {
if (arg1 == 1) if (arg1 == 1)
@ -248,9 +304,10 @@ public class HyosungRuntime(
await hyosungWmsService.UpdateControlNo(variety, controlNo); await hyosungWmsService.UpdateControlNo(variety, controlNo);
} }
else else
await printer.PrintAsync(1, trayCode); await printer.PrintAsync(2, trayCode);
await hyosungPlcService.WritePrintLabelResultAsync(arg1, true); await hyosungPlcService.WritePrintLabelResultAsync(arg1, true);
logger.LogInformation($"plc request print label success");
} }
catch (Exception e) catch (Exception e)
{ {