From 84851bbb0d471335b91bafd6d2d924b2f0066608 Mon Sep 17 00:00:00 2001
From: anerx <512464164@qq.com>
Date: Tue, 18 Mar 2025 18:32:10 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97=E6=89=93?=
=?UTF-8?q?=E5=8D=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Seyounth.Hyosung.Runtime/HyosungRuntime.cs | 221 +++++++++++++--------
1 file changed, 139 insertions(+), 82 deletions(-)
diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs
index 76237d0..abd217c 100644
--- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs
+++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs
@@ -1,5 +1,6 @@
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
+using System.Text.Json;
using Microsoft.Extensions.Logging;
using Seyounth.Hyosung.Core.Agv;
using Seyounth.Hyosung.Core.Plc;
@@ -74,19 +75,29 @@ public class HyosungRuntime(
///
private async Task OnPlcRequestScanFixture(int fixtureId)
{
- var fix = await hyosungScannerService.ScanFixtureAsync(fixtureId);
- if (string.IsNullOrEmpty(fix))
+ logger.LogInformation($"plc request scan fixture:{fixtureId}");
+ try
+ {
+ var fix = await hyosungScannerService.ScanFixtureAsync(fixtureId);
+ if (string.IsNullOrEmpty(fix))
+ {
+ await hyosungPlcService.WriteScanFixtureResultAsync(fixtureId, false);
+ logger.LogInformation($"scan fixture{fixtureId} fail");
+ }
+ else
+ {
+ await hyosungPlcService.WriteScanFixtureResultAsync(fixtureId, true, (short)Convert.ToInt32(fix));
+ logger.LogInformation($"scan fixture{fixtureId} success: {fix}");
+ }
+ }
+ catch (Exception e)
{
await hyosungPlcService.WriteScanFixtureResultAsync(fixtureId, false);
- logger.LogInformation($"scan fixture{fixtureId} fail");
- }
- else
- {
- await hyosungPlcService.WriteScanFixtureResultAsync(fixtureId, true, (short)Convert.ToInt32(fix));
- logger.LogInformation($"scan fixture{fixtureId} success: {fix}");
+ logger.LogError(e, $"scan fixture{fixtureId} fail");
}
}
+
///
/// 处理PLC请求扫描纱事件
///
@@ -94,24 +105,33 @@ public class HyosungRuntime(
private async Task OnPlcRequestScanProduct(int varietyId)
{
logger.LogInformation($"plc request scan yarn qrcode");
- var yarn = await hyosungScannerService.ScanYarnAsync(varietyId);
- if (yarn is null)
+ try
{
- await hyosungPlcService.WriteScanYarnResultAsync(false);
- logger.LogInformation($"scan yarn fail");
- return;
- }
+ var yarn = await hyosungScannerService.ScanYarnAsync(varietyId);
+ if (yarn is null)
+ {
+ await hyosungPlcService.WriteScanYarnResultAsync(false);
+ logger.LogInformation($"scan yarn fail");
+ return;
+ }
- var variety = await varietyService.GetById(varietyId);
- if (yarn.Lot != variety.Lot)
+ var variety = await varietyService.GetById(varietyId);
+ if (yarn.Lot != variety.Lot)
+ {
+ await hyosungPlcService.WriteScanYarnResultAsync(false);
+ logger.LogInformation($"scan yarn fail,lot not equal");
+ return;
+ }
+
+ await yarnService.AddYarnAsync(yarn);
+ await hyosungPlcService.WriteScanYarnResultAsync(true, (short)varietyId, yarn.ScanCode);
+ logger.LogInformation($"scan yarn {yarn.ScanCode} success: qrcode[{yarn.QrCode}]");
+ }
+ catch (Exception e)
{
await hyosungPlcService.WriteScanYarnResultAsync(false);
- logger.LogInformation($"scan yarn fail,lot not equal");
- return;
+ logger.LogError(e, $"scan yarn fail");
}
- await yarnService.AddYarnAsync(yarn);
- await hyosungPlcService.WriteScanYarnResultAsync(true, (short)varietyId, yarn.ScanCode);
- logger.LogInformation($"scan yarn {yarn.ScanCode} success: qrcode[{yarn.QrCode}]");
}
///
@@ -121,11 +141,19 @@ public class HyosungRuntime(
///
private async Task OnPlcRequestLeavingProductionLine(PlcStackInfo info)
{
- //使托盘完成
- await trayService.StorageAsync(info.TrayCode);
- await hyosungAgvService.StorageAsync(info.TrayCode);
- //标志下线已完成
- await hyosungPlcService.LeaveCompletedAsync();
+ logger.LogInformation($"plc request leaving production line");
+ try
+ {
+ await trayService.StorageAsync(info.TrayCode);
+ await hyosungAgvService.StorageAsync(info.TrayCode);
+ //标志下线已完成
+ await hyosungPlcService.LeaveCompletedAsync();
+ logger.LogInformation($"plc leaving production line success");
+ }
+ catch (Exception e)
+ {
+ logger.LogError(e, $"plc leaving production line fail");
+ }
}
@@ -138,25 +166,34 @@ public class HyosungRuntime(
///
private async Task OnPlcNeedNewTrayCode(int index, int varietyId)
{
- var tray = await trayService.GeneraNewTray(varietyId);
- var variety = await varietyService.GetById(varietyId);
- var stackModel = new StackStationModel();
- stackModel.TrayCode = tray.TrayCode;
- stackModel.VarietyCode = variety.Code;
- stackModel.Layers = variety.StackingLayers;
- stackModel.TotalCount = variety.TotalCount;
- stackModel.CurrentCount = 0;
- stackModel.Yarns = new ObservableCollection();
- if (index == 1)
+ logger.LogInformation($"plc request new tray code:{index} {varietyId}");
+ try
{
- Stack1 = stackModel;
- }
- else
- {
- Stack2 = stackModel;
- }
+ var tray = await trayService.GeneraNewTray(varietyId);
+ var variety = await varietyService.GetById(varietyId);
+ var stackModel = new StackStationModel();
+ stackModel.TrayCode = tray.TrayCode;
+ stackModel.VarietyCode = variety.Code;
+ stackModel.Layers = variety.StackingLayers;
+ stackModel.TotalCount = variety.TotalCount;
+ stackModel.CurrentCount = 0;
+ stackModel.Yarns = new ObservableCollection();
+ if (index == 1)
+ {
+ Stack1 = stackModel;
+ }
+ else
+ {
+ Stack2 = stackModel;
+ }
- 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");
+ }
}
///
@@ -167,30 +204,39 @@ public class HyosungRuntime(
///
private async Task OnPlcPutCompleted(PlcStackingInfo arg)
{
- if (arg.TrayCode == Stack1.TrayCode)
+ logger.LogInformation($"plc put completed:{JsonSerializer.Serialize(arg)}");
+ try
{
- Stack1.CurrentCount += arg.YarnCode.Count;
+ if (arg.TrayCode == Stack1.TrayCode)
+ {
+ Stack1.CurrentCount += arg.YarnCode.Count;
+ foreach (var yarnCode in arg.YarnCode)
+ {
+ Stack1.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode));
+ }
+ }
+ else if (arg.TrayCode == Stack2.TrayCode)
+ {
+ Stack2.CurrentCount += arg.YarnCode.Count;
+ foreach (var yarnCode in arg.YarnCode)
+ {
+ Stack2.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode));
+ }
+ }
+
foreach (var yarnCode in arg.YarnCode)
{
- Stack1.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode));
+ await yarnService.BindTrayAsync(yarnCode, await trayService.GetIdByCode(arg.TrayCode));
+ logger.LogInformation($" stack yarn{yarnCode} succeed");
}
- }
- else if (arg.TrayCode == Stack2.TrayCode)
- {
- Stack2.CurrentCount += arg.YarnCode.Count;
- foreach (var yarnCode in arg.YarnCode)
- {
- Stack2.Yarns.Add(await yarnService.GetYarnByCodeAsync(yarnCode));
- }
- }
- foreach (var yarnCode in arg.YarnCode)
- {
- await yarnService.BindTrayAsync(yarnCode, await trayService.GetIdByCode(arg.TrayCode));
- logger.LogInformation($" stack yarn{yarnCode} succeed");
+ await hyosungPlcService.WriteReceivedYarnCountAsync(arg.YarnCode.Count);
+ logger.LogInformation($"plc put completed success");
+ }
+ catch (Exception e)
+ {
+ logger.LogError(e, $"plc put completed fail");
}
-
- await hyosungPlcService.WriteReceivedYarnCountAsync(arg.YarnCode.Count);
}
///
@@ -201,27 +247,36 @@ public class HyosungRuntime(
///
private async Task OnPlcRequestPackLineOption(string arg)
{
- var tray = await trayService.GetByCode(arg);
- var variety = await varietyService.GetById(tray.VarietyId);
- PackLineOption = new PackLineOption()
+ logger.LogInformation($"plc request pack line option");
+ try
{
- HeadCount = variety.StackHeadCount ?? 0,
- HasBox = variety.HasBox,
- IsTop = variety.NeedTopBoard is NeedType.Need or NeedType.NotNeed
- ? variety.NeedTopBoard == NeedType.Need
- : tray.IsEven && variety.NeedTopBoard == NeedType.EvenNeed,
- IsPack = variety.NeedPackStrap is NeedType.Need or NeedType.NotNeed
- ? variety.NeedPackStrap == NeedType.Need
- : tray.IsEven && variety.NeedPackStrap == NeedType.EvenNeed,
- IsFilm = variety.NeedFilmWrapping is NeedType.Need or NeedType.NotNeed
- ? variety.NeedFilmWrapping == NeedType.Need
- : tray.IsEven && variety.NeedFilmWrapping == NeedType.EvenNeed,
- IsLam = variety.NeedFilmCoating is NeedType.Need or NeedType.NotNeed
- ? variety.NeedFilmCoating == NeedType.Need
- : tray.IsEven && variety.NeedFilmCoating == NeedType.EvenNeed,
- TrayCode = arg
- };
- await hyosungPlcService.WritePackLineOptionAsync(PackLineOption);
+ var tray = await trayService.GetByCode(arg);
+ var variety = await varietyService.GetById(tray.VarietyId);
+ PackLineOption = new PackLineOption()
+ {
+ HeadCount = variety.StackHeadCount ?? 0,
+ HasBox = variety.HasBox,
+ IsTop = variety.NeedTopBoard is NeedType.Need or NeedType.NotNeed
+ ? variety.NeedTopBoard == NeedType.Need
+ : tray.IsEven && variety.NeedTopBoard == NeedType.EvenNeed,
+ IsPack = variety.NeedPackStrap is NeedType.Need or NeedType.NotNeed
+ ? variety.NeedPackStrap == NeedType.Need
+ : tray.IsEven && variety.NeedPackStrap == NeedType.EvenNeed,
+ IsFilm = variety.NeedFilmWrapping is NeedType.Need or NeedType.NotNeed
+ ? variety.NeedFilmWrapping == NeedType.Need
+ : tray.IsEven && variety.NeedFilmWrapping == NeedType.EvenNeed,
+ IsLam = variety.NeedFilmCoating is NeedType.Need or NeedType.NotNeed
+ ? variety.NeedFilmCoating == NeedType.Need
+ : tray.IsEven && variety.NeedFilmCoating == NeedType.EvenNeed,
+ TrayCode = arg
+ };
+ await hyosungPlcService.WritePackLineOptionAsync(PackLineOption);
+ logger.LogInformation($"plc request pack line option success");
+ }
+ catch (Exception e)
+ {
+ logger.LogError(e, $"plc request pack line option fail");
+ }
}
///
@@ -233,6 +288,7 @@ public class HyosungRuntime(
///
private async Task OnPlcRequestPrintLabel(int arg1, string trayCode, int height)
{
+ logger.LogInformation($"plc request print label:{arg1} {trayCode} {height}");
try
{
if (arg1 == 1)
@@ -248,9 +304,10 @@ public class HyosungRuntime(
await hyosungWmsService.UpdateControlNo(variety, controlNo);
}
else
- await printer.PrintAsync(1, trayCode);
+ await printer.PrintAsync(2, trayCode);
await hyosungPlcService.WritePrintLabelResultAsync(arg1, true);
+ logger.LogInformation($"plc request print label success");
}
catch (Exception e)
{