新增视觉交互

master
CaesarBao 4 months ago
parent 9b1e7f447e
commit 702d3dcba5

@ -2,6 +2,7 @@
using SlnMesnac.Repository.service; using SlnMesnac.Repository.service;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using SlnMesnac.Repository; using SlnMesnac.Repository;
using SlnMesnac.Repository.service.Impl; using SlnMesnac.Repository.service.Impl;
@ -12,6 +13,7 @@ using System.Timers;
using SlnMesnac.Model.Enum; using SlnMesnac.Model.Enum;
using HslCommunication.Enthernet; using HslCommunication.Enthernet;
using System.Threading; using System.Threading;
using SlnMesnac.TouchSocket.Entity;
namespace SlnMesnac.Business.@base namespace SlnMesnac.Business.@base
{ {
@ -28,11 +30,78 @@ namespace SlnMesnac.Business.@base
{ {
_logger = logger; _logger = logger;
_tcpServer = tcpServer; _tcpServer = tcpServer;
_tcpServer.VisionSysStateEvent += TcpServerOnVisionSysStateEvent;
_tcpServer.StackWorkDoneEvent += _tcpServer_StackWorkDoneEvent;
_Taskservice = Taskservice; _Taskservice = Taskservice;
_AGVStateService = agvService; _AGVStateService = agvService;
InitClearTimer(); InitClearTimer();
//doWhileGetAGVTaskInfo(); //doWhileGetAGVTaskInfo();
} }
/// <summary>
/// 一次码垛完成,发送码垛结果
/// </summary>
/// <param name="entity"></param>
private void _tcpServer_StackWorkDoneEvent(TcpVisionEntity entity)
{
try
{
if (entity != null)
{
//码垛完成
if (entity.DataBytes[0] == 0x00)
{
//更新码垛数量
}
//码垛过程失败
else if (entity.DataBytes[1] == 0x01)
{
}
//码垛过程失败
else if (entity.DataBytes[2] == 0x02)
{
}
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 视觉系统回复给上位机调度系统开始工作状态
/// </summary>
/// <param name="entity"></param>
private void TcpServerOnVisionSysStateEvent(TcpVisionEntity entity)
{
try
{
if (entity != null)
{
//任务正常
if (entity.DataBytes[0] == 0x00)
{
//更新AMR任务状态
}
//任务异常
else if (entity.DataBytes[0] == 0x01)
{
}
}
}
catch (Exception ex)
{
}
}
public static BaseTaskInfoBusiness GetInstance(ILogger<BaseTaskInfoBusiness> logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer) public static BaseTaskInfoBusiness GetInstance(ILogger<BaseTaskInfoBusiness> logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer)
{ {
if (instance == null) if (instance == null)
@ -240,6 +309,38 @@ namespace SlnMesnac.Business.@base
} }
private void GetTaskStateDetail()
{
try
{
Task.Run(() =>
{
List<AirportTask> Task = _Taskservice.GetAGVTaskInfos();
if (Task.Count > 0)
{
// 设置计时器
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
//通过任务编号查询agv任务
// 检查是否超过两秒
if (stopwatch.ElapsedMilliseconds > 2000)
{
_logger.LogError("超时");
}
Thread.Sleep(100);
}
});
}
catch (Exception ex)
{
}
}
} }
} }

@ -29,7 +29,7 @@ namespace SlnMesnac.Config
/// <summary> /// <summary>
/// 系统配置 /// 系统配置
/// </summary> /// </summary>
#pragma warning disable CS8618 // Non-nullable field 'Data' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. #pragma warning disable CS8618 // Non-nullable field 'Data' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
public class AppConfig : IOptions<AppConfig> public class AppConfig : IOptions<AppConfig>
{ {
/// <summary> /// <summary>
@ -52,6 +52,7 @@ namespace SlnMesnac.Config
/// </summary> /// </summary>
public List<RfidConfig> rfidConfig { get; set; } public List<RfidConfig> rfidConfig { get; set; }
/// <summary> /// <summary>
/// Redis配置 /// Redis配置
/// </summary> /// </summary>
@ -60,9 +61,10 @@ namespace SlnMesnac.Config
/// <summary> /// <summary>
/// AMR /// AMR
/// </summary> /// </summary>
public string AMRIP { get; set; } public string AMRIP { get; set; }
/// </summary> /// <summary>
/// AGV地址配置 /// AGV地址配置
/// </summary> /// </summary>
public string AGVIpConfig { get; set; } public string AGVIpConfig { get; set; }
@ -78,7 +80,5 @@ namespace SlnMesnac.Config
public string TCPVisionConfig { get; set; } public string TCPVisionConfig { get; set; }
public AppConfig Value => this; public AppConfig Value => this;
} }
} }

@ -48,7 +48,9 @@ namespace SlnMesnac.Serilog
Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console()
.WriteTo.File(Path.Combine(logPath, "Info.log"), LogEventLevel.Information) .WriteTo.File(Path.Combine(logPath, "Info.log"), LogEventLevel.Information)
.WriteTo.File(Path.Combine(logPath, "Error.log"), LogEventLevel.Error) .WriteTo.File(Path.Combine(logPath, "Error.log"), LogEventLevel.Error)
.WriteTo.File(Path.Combine(logPath, "Warn.log"), LogEventLevel.Warning) .WriteTo.File(Path.Combine(logPath, "data.log"), LogEventLevel.Warning)
//.WriteTo.File(Path.Combine(logPath, "data.log"), LogEventLevel.Debug)
//.WriteTo.File(Path.Combine(logPath, "Debug.log"), LogEventLevel.Debug, fileSizeLimitBytes: 5 * 1024) //.WriteTo.File(Path.Combine(logPath, "Debug.log"), LogEventLevel.Debug, fileSizeLimitBytes: 5 * 1024)
.CreateLogger(); .CreateLogger();
app.UseSerilogRequestLogging(); app.UseSerilogRequestLogging();

@ -1,9 +1,13 @@
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Core;
using SlnMesnac.Config; using SlnMesnac.Config;
using SlnMesnac.TouchSocket.Entity; using SlnMesnac.TouchSocket.Entity;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -111,11 +115,9 @@ namespace SlnMesnac.TouchSocket
}; };
_service.Received = (client, e) => _service.Received = (client, e) =>
{ {
//从客户端收到信息
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len
_logger.LogInformation($"客户端{client.IP}:"+ mes); _logger.LogInformation($"客户端{client.IP}:"+ mes);
//区分一下指令类型,委托传参 //区分一下指令类型,委托传参
if (mes == "heartbeat") if (mes == "heartbeat")
{ {
RefreshStateAction?.Invoke(client.IP, true); RefreshStateAction?.Invoke(client.IP, true);
@ -151,6 +153,37 @@ namespace SlnMesnac.TouchSocket
} }
//private void Test()
//{
// try
// {
// Task.Run(() =>
// {
// // 设置计时器
// Stopwatch stopwatch = new Stopwatch();
// stopwatch.Start();
// ISocketClient client = _service.SocketClients.GetClients().FirstOrDefault(x => x.IP == "127.0.0.1");
// if (client != null)
// {
// Thread.Sleep(4000);
// _service.Send(client.Id, new byte[0x01]);
// }
// // 检查是否超过两秒
// if (stopwatch.ElapsedMilliseconds > 2000)
// {
// _logger.LogError("超时");
// }
// Thread.Sleep(100);
// });
// }
// catch (Exception ex)
// {
// }
//}
/// <summary> /// <summary>
/// 数据类型区分 /// 数据类型区分
/// </summary> /// </summary>

@ -59,7 +59,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
public IndexContentViewModel() public IndexContentViewModel()
{ {
LogMessages = new ObservableCollection<string>(); LogMessages = new ObservableCollection<string>();
_taskBusinessLogger = App.ServiceProvider.GetService<ILogger<BaseTaskInfoBusiness>>(); _taskBusinessLogger = App.ServiceProvider.GetService<ILogger<BaseTaskInfoBusiness>>();
_taskservice = App.ServiceProvider.GetService<IAirportTaskService>(); _taskservice = App.ServiceProvider.GetService<IAirportTaskService>();

@ -8,7 +8,7 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"AppConfig": { "AppConfig": {
"logPath": "D:\\WorkCode\\AirPortWCS\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\log", "logPath": "F:\\Mesnac\\2023部门项目\\机场AGV调度\\HightWay_AirPot_WCS\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\log",
"SqlConfig": [ "SqlConfig": [
//{ //{
// "configId": "mes", // "configId": "mes",

Loading…
Cancel
Save