打印文件日志 以及更新AGVBug

This commit is contained in:
anerx 2025-03-19 20:29:11 +08:00
parent c527e8135f
commit 34a3a32621
7 changed files with 56 additions and 7 deletions

View File

@ -51,8 +51,8 @@ public class HikAgv(ILogger<HikAgv> logger)
var input = new var input = new
{ {
reqCode = GetRequestCode(), reqCode = GetRequestCode(),
ctnrType, ctnrTyp = ctnrType,
taskType, taskTyp = taskType,
priority, priority,
agvCode = "4083", agvCode = "4083",
positionCodePath = new object[] positionCodePath = new object[]

View File

@ -10,7 +10,7 @@ public class HyosungAgvService(
ITrayService trayService, ITrayService trayService,
IDictService dictService) : IHyosungAgvService IDictService dictService) : IHyosungAgvService
{ {
private readonly HikAgv _agv = new HikAgv(loggerFactory.CreateLogger<HikAgv>()); private readonly HikAgv _agv = new(loggerFactory.CreateLogger<HikAgv>());
public async Task StorageAsync(string trayCode) public async Task StorageAsync(string trayCode)

View File

@ -8,12 +8,12 @@ public class AgvBinService : IAgvBinService
{ {
private readonly List<AgvBinEntity> _cache; private readonly List<AgvBinEntity> _cache;
private readonly IRepository<AgvBinEntity> repository; private readonly IRepository<AgvBinEntity> _repository;
public AgvBinService(IServiceProvider provider) public AgvBinService(IServiceProvider provider)
{ {
repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>(); _repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
_cache = repository.GetList(); _cache = _repository.GetList();
} }
public async Task<AgvBinEntity> GetAvailableBin(int height) public async Task<AgvBinEntity> GetAvailableBin(int height)
@ -40,6 +40,6 @@ public class AgvBinService : IAgvBinService
{ {
entity.IsFree = false; entity.IsFree = false;
_cache.First(e => e.Id == entity.Id).IsFree = false; _cache.First(e => e.Id == entity.Id).IsFree = false;
return repository.UpdateAsync(entity); return _repository.UpdateAsync(entity);
} }
} }

View File

@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Seyounth.Hyosung.Core.Printer; using Seyounth.Hyosung.Core.Printer;
using Seyounth.Hyosung.Runtime; using Seyounth.Hyosung.Runtime;
using Seyounth.Hyosung.Services; using Seyounth.Hyosung.Services;
@ -31,6 +32,9 @@ public partial class App : Application
{ {
var builder = Host var builder = Host
.CreateApplicationBuilder(); .CreateApplicationBuilder();
builder.Logging.ClearProviders();
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddNLog("nlog.config");
builder.Configuration.AddJsonFile("PrintTemp.json", true, true); builder.Configuration.AddJsonFile("PrintTemp.json", true, true);
builder.Configuration.AddJsonFile("appsettings.json", true, true); builder.Configuration.AddJsonFile("appsettings.json", true, true);
builder.Services.Configure<PrintTemp>(builder.Configuration.GetSection("Print")); builder.Services.Configure<PrintTemp>(builder.Configuration.GetSection("Print"));

View File

@ -12,6 +12,7 @@
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" /> <PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.4.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -22,6 +23,9 @@
<None Update="appsettings.json"> <None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Data.Models.Plc; using Seyounth.Hyosung.Data.Models.Plc;
@ -36,5 +37,19 @@ public partial class HomeViewModel : ObservableObject
_yarnCarTypes.Add("C"); _yarnCarTypes.Add("C");
_yarnCarTypes.Add("D"); _yarnCarTypes.Add("D");
_varieties = new ObservableCollection<Variety>(varietyService.GetAll()); _varieties = new ObservableCollection<Variety>(varietyService.GetAll());
DispatcherTimer timer = new DispatcherTimer();
timer = new DispatcherTimer();
// 设置定时器间隔,这里设置为 1 秒,可根据实际需求调整
timer.Interval = TimeSpan.FromSeconds(1);
// 为定时器的 Tick 事件添加处理方法
timer.Tick += Timer_Tick;
// 启动定时器
timer.Start();
}
private void Timer_Tick(object? sender, EventArgs e)
{
Stack1 = _runtime.Stack1;
Stack2 = _runtime.Stack2;
} }
} }

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="c:\temp\nlog-internal.log">
<!-- 定义目标,即日志输出的位置 -->
<targets>
<!-- 输出到控制台 -->
<target name="console" xsi:type="Console" />
<!-- 输出到文件 -->
<target name="file" xsi:type="File" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<!-- 定义规则,决定哪些日志应该输出到哪些目标 -->
<rules>
<!-- 记录所有级别的日志到控制台 -->
<logger name="*" minlevel="Trace" writeTo="console" />
<!-- 记录所有级别的日志到文件 -->
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>