diff --git a/SlnMesnac.Business/Airport/AirPortBusiness.cs b/SlnMesnac.Business/Airport/AirPortBusiness.cs new file mode 100644 index 0000000..8ece08c --- /dev/null +++ b/SlnMesnac.Business/Airport/AirPortBusiness.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using SlnMesnac.Repository.service; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SlnMesnac.Business.Airport +{ + public class AirPortBusiness + { + + } +} diff --git a/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs new file mode 100644 index 0000000..7ae07dc --- /dev/null +++ b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs @@ -0,0 +1,60 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.Repository.service; +using SlnMesnac.TouchSocket; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Business.@base +{ + public class BaseStateRefreshBusiness + { + private IAGVStateService _AGVStateService; + private IManipulatorStateService _ManipulatorStateService; + private ILogger _logger; + private static BaseStateRefreshBusiness instance; + public BaseStateRefreshBusiness(ILogger logger, IAGVStateService agvService, IManipulatorStateService manipulatorStateService) + { + _logger = logger; + _AGVStateService = agvService; + _ManipulatorStateService = manipulatorStateService; + } + public static BaseStateRefreshBusiness GetInstance(ILogger logger, IAGVStateService agvService, IManipulatorStateService manipulatorStateService) + { + if (instance == null) + { + instance = new BaseStateRefreshBusiness(logger, agvService, manipulatorStateService); + } + return instance; + } + + public bool UpdateAGVStateByResposne(AGVStateRequestEntity request) + { + try + { + var response = AirPorthttpClient.AGVStateRequest(request); + _AGVStateService.UpdateOrAddByResponse(response); + } + catch (Exception e) + { + _logger.LogError("Error:" + e); + } + return true; + } + + public bool UpdateManipulatorStateByResposne(ManipulatorStateRequestEntity request) + { + try + { + var response = AirPorthttpClient.ManipulatorStateRequest(request); + _ManipulatorStateService.UpdateOrAddByResponse(response); + } + catch (Exception e) + { + _logger.LogError("Error:" + e); + } + return true; + } + } +} diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index 21698a1..079ab1a 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -29,30 +29,29 @@ namespace SlnMesnac.Config /// /// 系统配置 /// - #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 { /// /// 日志文件路径 /// public string logPath { get; set; } - + /// /// Sql连接配置 /// public List sqlConfig { get; set; } - + /// /// PLC连接配置 /// public List plcConfig { get; set; } - + /// /// RFID连接配置 /// public List rfidConfig { get; set; } - /// /// Redis配置 /// @@ -61,9 +60,22 @@ namespace SlnMesnac.Config /// /// AMR /// - public string AMRIP { get; set; } + /// + /// AGV地址配置 + /// + public string AGVIpConfig { get; set; } + + /// + /// 机械臂地址配置 + /// + public string ManipulatorIpConfig { get; set; } + + /// + /// 机械臂地址配置 + /// + public string TCPVisionConfig { get; set; } public AppConfig Value => this; diff --git a/SlnMesnac.Extensions/SqlsugarSetup.cs b/SlnMesnac.Extensions/SqlsugarSetup.cs index 8761bea..2f3daf2 100644 --- a/SlnMesnac.Extensions/SqlsugarSetup.cs +++ b/SlnMesnac.Extensions/SqlsugarSetup.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using SlnMesnac.Config; +using SlnMesnac.Model.domain; using SqlSugar; using System; using System.Collections.Generic; @@ -31,6 +32,7 @@ namespace SlnMesnac.Extensions { public static class SqlsugarSetup { + /// /// 注册SqlSugar /// diff --git a/SlnMesnac.Model/AirportApiEntity/AGVArrivalSingalEntity.cs b/SlnMesnac.Model/AirportApiEntity/AGVArrivalSingalEntity.cs new file mode 100644 index 0000000..f31aafc --- /dev/null +++ b/SlnMesnac.Model/AirportApiEntity/AGVArrivalSingalEntity.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.AirportApiEntity +{ + public class AGVArrivalSingalEntity + { + /// + /// AGV编号 + /// + public string AGVNo { get; set; } + + /// + /// AGV类型 + /// + public string AGVType { get; set; } + + /// + /// 目的地编号 + /// + public string DestinationNo { get; set; } + + /// + /// 任务编号 + /// + public string TaskNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + + } +} diff --git a/SlnMesnac.Model/AirportApiEntity/AGVCallSingalEntity.cs b/SlnMesnac.Model/AirportApiEntity/AGVCallSingalEntity.cs new file mode 100644 index 0000000..b58e770 --- /dev/null +++ b/SlnMesnac.Model/AirportApiEntity/AGVCallSingalEntity.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.AirportApiEntity +{ + public class AGVCallSingalEntity + { + /// + /// AGV编号 + /// + public string AGVNo { get; set; } + + /// + /// AGV类型 + /// + public string AGVType { get; set; } + + /// + /// 起始地编号 + /// + public string StartingPointNo { get; set; } + + /// + /// 目的地编号 + /// + public string DestinationNo { get; set; } + + /// + /// 任务编号 + /// + public string TaskNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + } +} diff --git a/SlnMesnac.Model/AirportApiEntity/AGVStateEntity.cs b/SlnMesnac.Model/AirportApiEntity/AGVStateEntity.cs new file mode 100644 index 0000000..53b28aa --- /dev/null +++ b/SlnMesnac.Model/AirportApiEntity/AGVStateEntity.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.AirportApiEntity +{ + public class AGVStateRequestEntity + { + /// + /// AGV编号 + /// + public string AGVNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + } + + public class AGVStateResponseEntity + { + /// + /// AGV编号 + /// + public string AGVNo { get; set; } + + /// + /// AGV类型(1:机械臂小车,2:运载小车) + /// + public string AGVType { get; set; } + + /// + /// AGV报警状态(1:正常,2:故障) + /// + public string AGVAlarmState { get; set; } + + /// + /// AGV工作状态(1:空闲,2:忙碌) + /// + public string AGVWorkState { get; set; } + + /// + /// 报警信息 + /// + public string AlarmText { get; set; } + + /// + /// 任务编号 + /// + public string TaskNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + } +} diff --git a/SlnMesnac.Model/AirportApiEntity/ManipulatorStartWorkEntity.cs b/SlnMesnac.Model/AirportApiEntity/ManipulatorStartWorkEntity.cs new file mode 100644 index 0000000..8cf312a --- /dev/null +++ b/SlnMesnac.Model/AirportApiEntity/ManipulatorStartWorkEntity.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.AirportApiEntity +{ + public class ManipulatorStartWorkEntity + { + + /// + /// 机械臂编号 + /// + public string ManipulatorNo { get; set; } + + /// + /// 运载小车编号 + /// + public string CarryAGVNo { get; set; } + + /// + /// 传送带编号 + /// + public string ConveyorNo { get; set; } + + /// + /// 任务编号 + /// + public string TaskNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + + } +} diff --git a/SlnMesnac.Model/AirportApiEntity/ManipulatorStateEntity.cs b/SlnMesnac.Model/AirportApiEntity/ManipulatorStateEntity.cs new file mode 100644 index 0000000..be865ae --- /dev/null +++ b/SlnMesnac.Model/AirportApiEntity/ManipulatorStateEntity.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.AirportApiEntity +{ + public class ManipulatorStateRequestEntity + { + /// + /// 机械臂编号 + /// + public string ManipulatorNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + } + + + public class ManipulatorStateResponseEntity + { + /// + /// 机械臂编号 + /// + public string ManipulatorNo { get; set; } + + /// + /// 机械臂报警状态(1:正常,2:故障) + /// + public string ManipulatorAlarmState { get; set; } + + /// + /// 机械臂工作状态(1:空闲,2:工作) + /// + public string ManipulatorWorkState { get; set; } + + /// + /// 报警信息 + /// + public string AlarmText { get; set; } + + /// + /// 任务编号 + /// + public string TaskNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + } + +} \ No newline at end of file diff --git a/SlnMesnac.Model/AirportApiEntity/ManipulatorWorkDoneEntity.cs b/SlnMesnac.Model/AirportApiEntity/ManipulatorWorkDoneEntity.cs new file mode 100644 index 0000000..bffa616 --- /dev/null +++ b/SlnMesnac.Model/AirportApiEntity/ManipulatorWorkDoneEntity.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.AirportApiEntity +{ + public class ManipulatorWorkDoneEntity + { + + /// + /// 机械臂编号 + /// + public string ManipulatorNo { get; set; } + + /// + /// 运载小车编号 + /// + public string CarryAGVNo { get; set; } + + /// + /// 传送带编号 + /// + public string ConveyorNo { get; set; } + + /// + /// 此次抓取数量 + /// + public int NowCarryNumber { get; set; } + + /// + /// 小车装载数量 + /// + public int CarrierLoadNumber { get; set; } + + /// + /// 此次工作总抓取数量 + /// + public int AllCarryNumber { get; set; } + + /// + /// 装载方向(1:机械臂小车,2:装载小车) + /// + public string LoadLocation { get; set; } + + /// + /// 工作是否结束(0:未结束,1:结束) + /// + public string WorkIsDone { get; set; } + + /// + /// 任务编号 + /// + public string TaskNo { get; set; } + + /// + /// 信号发送时间 + /// + public string SignalSendTime { get; set; } + + } +} diff --git a/SlnMesnac.Model/domain/AGVLog.cs b/SlnMesnac.Model/domain/AGVLog.cs new file mode 100644 index 0000000..a6506a3 --- /dev/null +++ b/SlnMesnac.Model/domain/AGVLog.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + public class AGVLog + { + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ID { get; set; } + + /// + /// AGV编号 + /// + public string AGVNo { get; set; } + + /// + /// AGV类型 + /// + public string AGVType { get; set; } + + /// + /// 任务编号 + /// + public string ?TaskNo { get; set; } + + /// + /// AGV报警状态(1:正常,2:故障) + /// + public string AGVAlarmState { get; set; } + + /// + /// AGV工作状态(1:空闲,2:忙碌) + /// + public string AGVWorkState { get; set; } + + /// + /// 报警内容 + /// + public string ?AlarmText { get; set; } + + /// + /// 日志时间 + /// + public DateTime LogTime { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/AGVSetting.cs b/SlnMesnac.Model/domain/AGVSetting.cs new file mode 100644 index 0000000..53c0456 --- /dev/null +++ b/SlnMesnac.Model/domain/AGVSetting.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + public class AGVSetting + { + /// + /// 自增编号 + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ID { get; set; } + + /// + /// AGV编号 + /// + public string AGVNo { get; set; } + + /// + /// AGV类型 + /// + public string AGVType { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/ManipulatorLog.cs b/SlnMesnac.Model/domain/ManipulatorLog.cs new file mode 100644 index 0000000..821c003 --- /dev/null +++ b/SlnMesnac.Model/domain/ManipulatorLog.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + public class ManipulatorLog + { + /// + /// 自增编号 + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ID { get; set; } + + /// + /// 机械臂编号 + /// + public string ManipulatorNo { get; set; } + + /// + /// 任务编号 + /// + public string ?TaskNo { get; set; } + + /// + /// 机械臂报警状态(1:正常,2:故障) + /// + public string ManipulatorAlarmState { get; set; } + + /// + /// 机械臂工作状态(1:空闲,2:忙碌) + /// + public string ManipulatorWorkState { get; set; } + + /// + /// 报警内容 + /// + public string ?AlarmText { get; set; } + + /// + /// 日志时间 + /// + public DateTime LogTime { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/ManipulatorSetting.cs b/SlnMesnac.Model/domain/ManipulatorSetting.cs new file mode 100644 index 0000000..b8fedff --- /dev/null +++ b/SlnMesnac.Model/domain/ManipulatorSetting.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + public class ManipulatorSetting + { + /// + /// 自增编号 + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ID { get; set; } + + /// + /// 机械臂编号 + /// + public string ManipulatorNo { get; set; } + + /// + /// 机械臂所属AGV编号 + /// + public string RelatedAGVNo { get; set; } + + } +} diff --git a/SlnMesnac.Model/domain/ManipulatorState.cs b/SlnMesnac.Model/domain/ManipulatorState.cs new file mode 100644 index 0000000..65b7b6c --- /dev/null +++ b/SlnMesnac.Model/domain/ManipulatorState.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Model.domain +{ + public class ManipulatorState + { + /// + /// 自增编号 + /// + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ID { get; set; } + + /// + /// 机械臂编号 + /// + public string ManipulatorNo { get; set; } + + /// + /// 任务编号 + /// + public string ?TaskNo { get; set; } + + /// + /// 机械臂报警状态(1:正常,2:故障) + /// + public string ManipulatorAlarmState { get; set; } + + /// + /// 机械臂工作状态(1:空闲,2:忙碌) + /// + public string ManipulatorWorkState { get; set; } + + /// + /// 刷新时间 + /// + public DateTime RefreshTime { get; set; } + } +} diff --git a/SlnMesnac.Quartz/Job/GetTaskInfo_Job.cs b/SlnMesnac.Quartz/Job/GetTaskInfo_Job.cs index e06050c..7f3752b 100644 --- a/SlnMesnac.Quartz/Job/GetTaskInfo_Job.cs +++ b/SlnMesnac.Quartz/Job/GetTaskInfo_Job.cs @@ -13,7 +13,7 @@ namespace SlnMesnac.Quartz.Job { private readonly ILogger _logger; private IAirportTaskService _service; - private BaseTaskInfoBusiness _taskInfoBusiness; + private BaseTaskInfoBusiness _taskInfoBusiness; public GetTaskInfo_Job(ILogger logger, IAirportTaskService service) { _logger = logger; diff --git a/SlnMesnac.Quartz/Job/Job2.cs b/SlnMesnac.Quartz/Job/Job2.cs index cba1528..52a5906 100644 --- a/SlnMesnac.Quartz/Job/Job2.cs +++ b/SlnMesnac.Quartz/Job/Job2.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using Quartz; +using SlnMesnac.Repository.service; using System; using System.Collections.Generic; using System.Text; @@ -38,9 +39,12 @@ namespace SlnMesnac.Quartz.Job _logger = logger; } + + public Task Execute(IJobExecutionContext context) { _logger.LogInformation($"执行Job2:{DateTime.Now.ToString("HH:mm:ss")}"); + return Task.CompletedTask; } } diff --git a/SlnMesnac.Quartz/Job/MyJob.cs b/SlnMesnac.Quartz/Job/MyJob.cs index 0dd123c..1393ae1 100644 --- a/SlnMesnac.Quartz/Job/MyJob.cs +++ b/SlnMesnac.Quartz/Job/MyJob.cs @@ -1,5 +1,7 @@ using Microsoft.Extensions.Logging; using Quartz; +using SlnMesnac.Repository.service; +using SlnMesnac.Repository.service.Impl; using System; using System.Collections.Generic; using System.Text; @@ -33,9 +35,12 @@ namespace SlnMesnac.Quartz.Job { private readonly ILogger _logger; + //private readonly IAirportTaskService _airportTaskService; + public MyJob(ILogger logger) { _logger = logger; + //airportTaskService = airportTaskService; } public Task Execute(IJobExecutionContext context) diff --git a/SlnMesnac.Quartz/QuartzSetUp.cs b/SlnMesnac.Quartz/QuartzSetUp.cs index c1da80f..4ad3d5c 100644 --- a/SlnMesnac.Quartz/QuartzSetUp.cs +++ b/SlnMesnac.Quartz/QuartzSetUp.cs @@ -40,12 +40,9 @@ namespace SlnMesnac.Quartz // trigger.WithCronSchedule("*/3 * * * * ?").WithIdentity("MyJob", "MyJobGroup") // 示例:每3s执行一次 //); - q.ScheduleJob(trigger => - trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("GetAgvState_Job", "GetAgvState_JobGroup") // 示例:每5s执行一次 - ); - q.ScheduleJob(trigger => - trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("MyJob", "GetAgvState_JobGroup") // 示例:每5s执行一次 - ); + //q.ScheduleJob(trigger => + // trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例:每5s执行一次 + //); }); services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true); diff --git a/SlnMesnac.Repository/service/IAGVStateService.cs b/SlnMesnac.Repository/service/IAGVStateService.cs index 9f361ba..5ff2935 100644 --- a/SlnMesnac.Repository/service/IAGVStateService.cs +++ b/SlnMesnac.Repository/service/IAGVStateService.cs @@ -1,3 +1,4 @@ +using SlnMesnac.Model.AirportApiEntity; using SlnMesnac.Model.domain; using SlnMesnac.Model.Enum; using SlnMesnac.Repository.service.@base; @@ -23,5 +24,18 @@ namespace SlnMesnac.Repository.service /// Task UpdateAsync(AGVState record); + /// + /// ѯAGV״̬ + /// + /// + List GetAllAGVState(); + + /// + /// Ӧݲ + /// + /// + /// + Task UpdateOrAddByResponse(AGVStateResponseEntity response); + } } \ No newline at end of file diff --git a/SlnMesnac.Repository/service/IAirportTaskService.cs b/SlnMesnac.Repository/service/IAirportTaskService.cs index c8095a7..8c6d7e4 100644 --- a/SlnMesnac.Repository/service/IAirportTaskService.cs +++ b/SlnMesnac.Repository/service/IAirportTaskService.cs @@ -10,12 +10,12 @@ namespace SlnMesnac.Repository.service public interface IAirportTaskService : IBaseService { /// - /// ȡվ̨б + /// ��ȡվ̨�����б� /// /// List GetTaskInfos(); /// - /// ȡִб + /// ��ȡ��ִ�������б� /// /// List GetAGVTaskInfos(); @@ -28,7 +28,7 @@ namespace SlnMesnac.Repository.service Task> GetTaskInfoListAsync(string ConveyorNo); /// - /// б + /// ���������б� /// /// /// @@ -49,4 +49,4 @@ namespace SlnMesnac.Repository.service /// Task DeleteTaskAsync(AirportTask record); } -} \ No newline at end of file +} diff --git a/SlnMesnac.Repository/service/IManipulatorStateService.cs b/SlnMesnac.Repository/service/IManipulatorStateService.cs new file mode 100644 index 0000000..8b5060d --- /dev/null +++ b/SlnMesnac.Repository/service/IManipulatorStateService.cs @@ -0,0 +1,39 @@ +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Repository.service +{ + public interface IManipulatorStateService : IBaseService + { + /// + /// 查询空闲的机械臂信息 + /// + /// + List GetFreeManipulatorState(); + + /// + /// 查询所有机械臂信息 + /// + /// + List GetAllManipulatorState(); + + /// + /// 更新机械臂设备状态信息 + /// + /// + /// + Task UpdateAsync(ManipulatorState record); + + /// + /// 更新或插入机械臂设备状态信息 + /// + /// + /// + Task UpdateOrAddByResponse(ManipulatorStateResponseEntity response); + } +} diff --git a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs index 1979a4a..d73bf2b 100644 --- a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs @@ -1,10 +1,12 @@ using Microsoft.Extensions.Logging; using SlnMesnac.Common; +using SlnMesnac.Model.AirportApiEntity; using SlnMesnac.Model.domain; using SlnMesnac.Model.Enum; using SlnMesnac.Repository.service.@base; using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; @@ -24,13 +26,27 @@ namespace SlnMesnac.Repository.service.Impl try { Expression> exp = x => true; - exp = exp.And(x =>(x.agvno != null || x.agvno != "") && (x.taskno == null || x.taskno == "") && x.agvworkstate == "" && (x.agvalarmstate == null || x.agvalarmstate == "") && x.agvtype == _AgvType); + exp = exp.And(x =>(x.agvno != null || x.agvno != "") && (x.taskno == null || x.taskno == "") && x.agvworkstate == "�������" && (x.agvalarmstate == null || x.agvalarmstate == "") && x.agvtype == _AgvType); agvStateInfoList = base._rep.GetList(exp); } catch (Exception ex) { - _logger.LogError($"ͨͻȡϢ쳣:{ex.Message}"); + _logger.LogError($"��ȡ����AGV��Ϣ�쳣:{ex.Message}"); + } + return agvStateInfoList; + } + + public List GetAllAGVState() + { + List agvStateInfoList = null; + try + { + agvStateInfoList = base._rep.GetList(); + } + catch (Exception ex) + { + _logger.LogError($"��ȡ����AGV��Ϣ�쳣:{ex.Message}"); } return agvStateInfoList; } @@ -41,5 +57,36 @@ namespace SlnMesnac.Repository.service.Impl return result; } + public async Task UpdateOrAddByResponse(AGVStateResponseEntity response) + { + AGVState record = new AGVState() + { + agvno = response.AGVNo, + agvalarmstate = response.AGVAlarmState, + agvtype = response.AGVType, + agvworkstate = response.AGVWorkState, + refreshtime = DateTime.Now, + taskno = response.TaskNo, + }; + bool result = false; + try + { + var list = GetAllAGVState(); + if (list.Where(x => x.agvno == response.AGVNo).Count() == 0) + { + result = _rep.Insert(record); + } + else + { + record.id = list.Where(x => x.agvno == response.AGVNo).FirstOrDefault().id; + result = await _rep.UpdateAsync(record); + } + } + catch (Exception ex) + { + _logger.LogError($"��е��״̬��Ϣ�����쳣:{ex.Message}"); + } + return result; + } } } \ No newline at end of file diff --git a/SlnMesnac.Repository/service/Impl/ManipulatorStateServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ManipulatorStateServiceImpl.cs new file mode 100644 index 0000000..56f6b3d --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/ManipulatorStateServiceImpl.cs @@ -0,0 +1,92 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Common; +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.@base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Repository.service.Impl +{ + public class ManipulatorStateServiceImpl : BaseServiceImpl, IManipulatorStateService + { + private ILogger _logger; + + + public ManipulatorStateServiceImpl(Repository rep, ILogger logger) : base(rep) + { + _logger = logger; + } + + public List GetAllManipulatorState() + { + var list = new List(); + try + { + list = base._rep.GetList(); + } + catch (Exception ex) + { + _logger.LogError($"所有机械臂状态信息获取异常:{ex.Message}"); + } + return list; + } + + public List GetFreeManipulatorState() + { + var list = new List(); + try + { + list = base._rep.GetList() + .Where(x => x.ManipulatorNo != "" && (x.TaskNo == null || x.TaskNo == "") && x.ManipulatorWorkState == "任务空闲") + .ToList(); + } + catch (Exception ex) + { + _logger.LogError($"空闲机械臂状态信息获取异常:{ex.Message}"); + } + return list; + } + + public async Task UpdateAsync(ManipulatorState record) + { + bool result = await _rep.UpdateAsync(record); + return result; + } + + public async Task UpdateOrAddByResponse(ManipulatorStateResponseEntity response) + { + ManipulatorState record = new ManipulatorState() + { + ManipulatorNo = response.ManipulatorNo, + ManipulatorAlarmState = response.ManipulatorAlarmState, + ManipulatorWorkState = response.ManipulatorWorkState, + TaskNo = response.TaskNo, + RefreshTime = DateTime.Now, + }; + bool result = false; + try + { + var list = GetAllManipulatorState(); + if (list.Where(x => x.ManipulatorNo == response.ManipulatorNo).Count() == 0) + { + result = _rep.Insert(record); + } + else + { + record.ID = list.Where(x => x.ManipulatorNo == response.ManipulatorNo).FirstOrDefault().ID; + result = await _rep.UpdateAsync(record); + } + } + catch(Exception ex) + { + _logger.LogError($"机械臂状态信息更新异常:{ex.Message}"); + } + return result; + } + } +} diff --git a/SlnMesnac.TouchSocket/AirPorthttpClient.cs b/SlnMesnac.TouchSocket/AirPorthttpClient.cs new file mode 100644 index 0000000..8b27196 --- /dev/null +++ b/SlnMesnac.TouchSocket/AirPorthttpClient.cs @@ -0,0 +1,133 @@ +using Microsoft.Extensions.Hosting; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using SlnMesnac.Config; +using SlnMesnac.Model.AirportApiEntity; +using SQLitePCL; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Text.Json; +using TouchSocket.Rpc; +using TouchSocket.Sockets; +using TouchSocket.WebApi; +using JsonSerializer = System.Text.Json.JsonSerializer; +using Microsoft.Extensions.Logging; + +namespace SlnMesnac.TouchSocket +{ + public class AirPorthttpClient : BackgroundService + { + private readonly AppConfig _appConfig; + private readonly ILogger _logger; + + public AirPorthttpClient(AppConfig appConfig, ILogger logger) + { + _appConfig = appConfig; + _logger = logger; + } + + public static WebApiClient AirportAGVClient; + public static WebApiClient AirportManipulatorClient; + + private WebApiClient CreateWebApiClient(string IpHost) + { + var client = new WebApiClient(); + try + { + client.Connect(IpHost); + _logger.LogInformation(IpHost + "连接成功"); + } + catch (Exception ex) + { + _logger.LogError("ERROR: " + ex.Message); + return null; + } + return client; + } + + protected override Task ExecuteAsync(CancellationToken stoppingToken) + { + try + { + AirportAGVClient = CreateWebApiClient(_appConfig.AGVIpConfig); + AirportManipulatorClient = CreateWebApiClient(_appConfig.ManipulatorIpConfig); + } + catch (Exception ex) + { + _logger.LogError("ERROR: " + ex.Message); + return Task.FromException(ex); + } + return Task.CompletedTask; + } + + /// + /// AGV呼叫请求 + /// + /// + public static string AGVCallRequest() + { + JToken responseValue = AirportAGVClient.InvokeT("POST:", null, new AGVArrivalSingalEntity()); + + return responseValue.ToString(); + } + + /// + /// 机械臂开始工作请求 + /// + /// + public static string ManipulatorStartRequest() + { + JToken responseValue = AirportAGVClient.InvokeT("POST:", null, new AGVArrivalSingalEntity()); + + return responseValue.ToString(); + } + + /// + /// AGV状态请求 + /// + /// + /// + public static AGVStateResponseEntity AGVStateRequest(AGVStateRequestEntity aGVStateRequest) + { + JToken responseValue = AirportAGVClient.InvokeT("POST:/m1/5051269-4712337-default/apitest/AGVtest", null, aGVStateRequest); + if (responseValue == null) + { + return new AGVStateResponseEntity(); + } + string json = responseValue.ToString(); + if (string.IsNullOrEmpty(json)) + { + return new AGVStateResponseEntity(); + } + AGVStateResponseEntity aGVStateResponseEntity = new AGVStateResponseEntity(); + aGVStateResponseEntity = JsonSerializer.Deserialize(json); + return aGVStateResponseEntity; + } + + /// + /// 机械臂状态请求 + /// + /// + /// + public static ManipulatorStateResponseEntity ManipulatorStateRequest(ManipulatorStateRequestEntity manipulatorStateRequest) + { + JToken responseValue = AirportAGVClient.InvokeT("POST:/m1/5051269-4712337-default/apitest/manipulatortest", null, manipulatorStateRequest); + if (responseValue == null) + { + return new ManipulatorStateResponseEntity(); + } + string json = responseValue.ToString(); + if (string.IsNullOrEmpty(json)) + { + return new ManipulatorStateResponseEntity(); + } + ManipulatorStateResponseEntity manipulatorState = new ManipulatorStateResponseEntity(); + manipulatorState = JsonSerializer.Deserialize(json); + return manipulatorState; + } + } +} diff --git a/SlnMesnac.TouchSocket/AirportTcpServer.cs b/SlnMesnac.TouchSocket/AirportTcpServer.cs new file mode 100644 index 0000000..784afc4 --- /dev/null +++ b/SlnMesnac.TouchSocket/AirportTcpServer.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Hosting; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SlnMesnac.TouchSocket +{ + public class AirportTcpServer : BackgroundService + { + protected override Task ExecuteAsync(CancellationToken stoppingToken) + { + return Task.CompletedTask; + } + + + } +} diff --git a/SlnMesnac.TouchSocket/ApiServer.cs b/SlnMesnac.TouchSocket/ApiServer.cs index d704959..30b7e31 100644 --- a/SlnMesnac.TouchSocket/ApiServer.cs +++ b/SlnMesnac.TouchSocket/ApiServer.cs @@ -1,4 +1,5 @@ -using System; +using SlnMesnac.Model.AirportApiEntity; +using System; using System.Collections.Generic; using System.Text; using TouchSocket.Rpc; @@ -30,80 +31,64 @@ namespace SlnMesnac.TouchSocket { public class ApiServer: RpcServer { + public ApiServer() + { - public delegate void RefreshScanInfoInCenterStart(); - /// - /// 入库开始事件刷新 - /// - public event RefreshScanInfoInCenterStart RefreshScanInfoInCenterStartEvent; - - public delegate void RefreshScanInfoInCenterStop(); - /// - /// 入库结束事件刷新 - /// - public event RefreshScanInfoInCenterStop RefreshScanInfoInCenterStopEvent; - - public delegate void RefreshScanInfoOutCenterStart(); - /// - /// 出库开始事件刷新 - /// - public event RefreshScanInfoOutCenterStart RefreshScanInfoOutCenterStartEvent; + } - public delegate void RefreshScanInfoOutCenterStop(); + public delegate void AGVArrivalStart(string message, AGVArrivalSingalEntity aGVArrivalSingalEntity); /// - /// 出库结束事件刷新 + /// AGV到位信号刷新 /// - public event RefreshScanInfoOutCenterStop RefreshScanInfoOutCenterStopEvent; + public event AGVArrivalStart AGVArrivalStartEvent; /// - /// 入库开始 + /// AGV到位信号接口 /// /// /// [EnableCors("cors")] [WebApi(HttpMethodType.POST)] - public object getScanInfoInCenterStart(string messageHeader) + public object AGVArrivalSignal(string messageHeader, AGVArrivalSingalEntity aGVArrivalSingalEntity) { - RefreshScanInfoInCenterStartEvent?.Invoke(); - return true; + AGVArrivalStartEvent?.Invoke(messageHeader, aGVArrivalSingalEntity); + return "Success"; } + public delegate void ManipulatorWorkDoneStart(string message, ManipulatorWorkDoneEntity manipulatorWorkDoneEntity); + /// + /// 机械臂抓取完毕事件刷新 + /// + public event ManipulatorWorkDoneStart ManipulatorWorkDoneEvent; + /// - /// 入库结束 + /// 机械臂抓取完毕信号接口 /// /// /// [EnableCors("cors")] [WebApi(HttpMethodType.POST)] - public object getScanInfoInCenterStop(string messageHeader) + public object ManipulatorWorkDone(string messageHeader, ManipulatorWorkDoneEntity manipulatorWorkDoneEntity) { - RefreshScanInfoInCenterStopEvent?.Invoke(); - return true; + ManipulatorWorkDoneEvent?.Invoke(messageHeader, manipulatorWorkDoneEntity); + return "Success"; } - /// - /// 出库开始 - /// - /// - /// - [WebApi(HttpMethodType.POST)] - public object getScanInfoOutCenterStart(string messageHeader) + + public void SubscribeToAGVArrivalEvent() { - RefreshScanInfoOutCenterStartEvent?.Invoke(); - return true; + // 订阅 AGV 到位事件 + AGVArrivalStartEvent += OnAGVArrival; } - /// - /// 出库结束 - /// - /// - /// - [WebApi(HttpMethodType.POST)] - public object getScanInfoOutCenterStop(string messageHeader) + // 处理 AGV 到位事件的方法 + public void OnAGVArrival(string message, AGVArrivalSingalEntity aGVArrivalSingalEntity) { - RefreshScanInfoOutCenterStopEvent?.Invoke(); - return true; + Console.WriteLine($"收到AGV到位信号: {message}"); + Console.WriteLine($"AGV编号: {aGVArrivalSingalEntity.AGVNo}, 到达位置: {aGVArrivalSingalEntity.DestinationNo}"); + // 这里可以处理更多的业务逻辑,比如记录日志、更新系统状态等 } } + } diff --git a/SlnMesnac.TouchSocket/BufferDataAnalysis.cs b/SlnMesnac.TouchSocket/BufferDataAnalysis.cs new file mode 100644 index 0000000..f86339b --- /dev/null +++ b/SlnMesnac.TouchSocket/BufferDataAnalysis.cs @@ -0,0 +1,87 @@ +using Microsoft.Extensions.Logging; +using Serilog.Core; +using SlnMesnac.Config; +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.TouchSocket.Entity; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using TouchSocket.Sockets; + +namespace SlnMesnac.TouchSocket +{ + + public class BufferDataAnalysis + { + public static TcpVisionEntity BufferRootAnalysis(byte[] bytes) + { + TcpVisionEntity entity; + //数据校验,从起始符开始到数据位,按字节求和得出的结果对256求余 + if(bytes.Length <= 2) + { + return null; + } + int checkDatalength = bytes.Length - 2; + byte checksum = bytes[checkDatalength]; + byte[] checkData = new byte[checkDatalength]; + Array.Copy(bytes, 0, checkData, 0, checkDatalength); + int sum = 0; + foreach (byte b in checkData) + { + sum += b; + } + int count = sum % 256; + if (count == checksum) + { + entity = new TcpVisionEntity(); + entity.Checksum = checksum; + } + else + { + return null; + } + int index = 2; + + //取序列号 + entity.SN = new byte[2] { bytes[index], bytes[index + 1] }; + index += 2; + + //取时间戳 + entity.Timestamp = new byte[4] { bytes[index], bytes[index + 1], bytes[index + 2], bytes[index + 3] }; + index += 4; + + //取命令字 + entity.Command = bytes[index]; + index += 1; + + //取数据位长度 + entity.DataLength = bytes[index]; + index += 1; + + //取数据位 + byte[] dataBytes = new byte[entity.DataLength]; + Array.Copy(bytes, index, dataBytes, 0, entity.DataLength); + entity.DataBytes = dataBytes; + index += entity.DataLength; + return entity; + } + + public byte[] DataCombine(byte[] bytes) + { + + return null; + } + + public static byte[] GetCurrentUnixTimestampAsBytes() + { + // 获取当前的Unix时间戳,表示自1970-01-01以来的秒数 + int unixTimestamp = (int)(DateTimeOffset.UtcNow.ToUnixTimeSeconds()); + // 将时间戳转换为字节数组 + byte[] bytes = BitConverter.GetBytes(unixTimestamp); + return bytes; + } + + } +} diff --git a/SlnMesnac.TouchSocket/Entity/TcpVisionEntity.cs b/SlnMesnac.TouchSocket/Entity/TcpVisionEntity.cs new file mode 100644 index 0000000..395b51b --- /dev/null +++ b/SlnMesnac.TouchSocket/Entity/TcpVisionEntity.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.TouchSocket.Entity +{ + public class TcpVisionEntity + { + /// + /// 序列号 + /// + public byte[] SN { get; set; } + + /// + /// 时间戳 + /// + public byte[] Timestamp { get; set; } + + /// + /// 命令字 + /// + public byte Command { get; set; } + + /// + /// 数据长度 + /// + public byte DataLength { get; set; } + + /// + /// 数据位 + /// + public byte[]? DataBytes { get; set; } + + /// + /// 校验和 + /// + public byte Checksum { get; set; } + } +} diff --git a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj b/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj index 94f69ee..0df472a 100644 --- a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj +++ b/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj @@ -12,6 +12,7 @@ + diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs index c3f0ae5..fe3761b 100644 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ b/SlnMesnac.TouchSocket/TcpServer.cs @@ -1,7 +1,12 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using SlnMesnac.Config; +using SlnMesnac.TouchSocket.Entity; using System; using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; using TouchSocket.Core; using TouchSocket.Sockets; @@ -29,10 +34,13 @@ using TouchSocket.Sockets; #endregion << 版 本 注 释 >> namespace SlnMesnac.TouchSocket { - public class TcpServer + public class TcpServer : BackgroundService { + private ILogger _logger; private readonly TcpService _service; + private readonly AppConfig _appConfig; + /// /// 接收客户端指令委托 /// @@ -44,27 +52,64 @@ namespace SlnMesnac.TouchSocket public Action RefreshStateAction; - public TcpServer(ILogger logger,TcpService tcpService) + public delegate void GetVisionData(TcpVisionEntity entity); + + /// + /// 视觉系统反馈给上位机调度系统状态 + /// + public event GetVisionData? VisionSysStateEvent; + + /// + /// 视觉系统回复给上位机调度系统开始工作状态 + /// + public event GetVisionData? VisionStartWorkEvent; + + /// + /// 一次码垛完成,发送码垛结果 + /// + public event GetVisionData? StackWorkDoneEvent; + + /// + /// 视觉系统发送给机器人码垛位置定位结果 + /// + public event GetVisionData? StackRobotLocationEvent; + + /// + /// 人工异常处理完成并更新计数 + /// + public event GetVisionData? ManualExceptionDealDoneEvent; + + private string ClientID = ""; + + public TcpServer(ILogger logger,TcpService tcpService, AppConfig appConfig) { _logger = logger; _service = tcpService; + _appConfig = appConfig; + } + + protected override Task ExecuteAsync(CancellationToken stoppingToken) + { + Init(_appConfig.TCPVisionConfig); + return Task.CompletedTask; } - public void Init(int serverPort) + public void Init(string serverPort) { try { - _service.Connecting = (client, e) => { + _service.Connecting = (client, e) => { _logger.LogInformation($"客户端{client.IP}正在接入服务"); return EasyTask.CompletedTask; }; - _service.Connected = (client, e) => { + _service.Connected = (client, e) => { _logger.LogInformation($"客户端{client.IP}接入服务成功"); RefreshClientInfoEvent?.Invoke(_service); RefreshStateAction?.Invoke(client.IP,true); + ClientID = client.Id; return EasyTask.CompletedTask; }; - _service.Disconnected = (client, e) => { + _service.Disconnected = (client, e) => { _logger.LogInformation($"客户端{client.IP}断开连接"); RefreshStateAction?.Invoke(client.IP, false); RefreshClientInfoEvent?.Invoke(_service); @@ -81,15 +126,18 @@ namespace SlnMesnac.TouchSocket { RefreshStateAction?.Invoke(client.IP, true); } + //var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len + byte[] receivedBuffer = new byte[e.ByteBlock.Len]; Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len); - ReceivedClientBufferEvent?.Invoke(receivedBuffer); - + //ReceivedClientBufferEvent?.Invoke(receivedBuffer); + DataClassify(BufferDataAnalysis.BufferRootAnalysis(receivedBuffer)); + return EasyTask.CompletedTask; }; _service.Setup(new TouchSocketConfig()//载入配置 - .SetListenIPHosts(new IPHost[] { new IPHost($"0.0.0.0:{serverPort}") }) + .SetListenIPHosts(new IPHost[] { new IPHost(serverPort) }) .ConfigureContainer(a =>//容器的配置顺序应该在最前面 { a.AddConsoleLogger(); @@ -110,15 +158,37 @@ namespace SlnMesnac.TouchSocket } /// - /// 向所有客户端发送心跳 + /// 数据类型区分 /// - public void SendHeartBeat() + /// + public void DataClassify(TcpVisionEntity entity) { - var clients = _service.SocketClients.GetClients(); - foreach (var item in clients) + if(entity == null) { - _service.Send(item.Id,"heartbeat"); + _logger.LogError("数据格式校验错误!"); + return; + } + switch(entity.Command) + { + case 10: VisionSysStateEvent?.Invoke(entity); break; + case 11: VisionStartWorkEvent?.Invoke(entity); break; + case 12: StackWorkDoneEvent?.Invoke(entity); break; + case 13: StackRobotLocationEvent?.Invoke(entity); break; + case 14: ManualExceptionDealDoneEvent?.Invoke(entity); break; + default: _logger.LogInformation("未知命令字!"); return; } } + + ///// + ///// 向所有客户端发送心跳 + ///// + //public void SendHeartBeat() + //{ + // var clients = _service.SocketClients.GetClients(); + // foreach (var item in clients) + // { + // _service.Send(item.Id,"heartbeat"); + // } + //} } } diff --git a/SlnMesnac.TouchSocket/TouchSocketSetup.cs b/SlnMesnac.TouchSocket/TouchSocketSetup.cs index ea36ae7..52b5f6b 100644 --- a/SlnMesnac.TouchSocket/TouchSocketSetup.cs +++ b/SlnMesnac.TouchSocket/TouchSocketSetup.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Text; using Microsoft.AspNetCore.Builder; using TouchSocket.Sockets; +using TouchSocket.WebApi; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -34,7 +35,7 @@ namespace SlnMesnac.TouchSocket /// public static class TouchSocketSetup { - + public static IApplicationBuilder UseTouchSocketExtensions(this IApplicationBuilder app) { var _server = app.ApplicationServices.GetService(); diff --git a/SlnMesnac.TouchSocket/WebApiServer.cs b/SlnMesnac.TouchSocket/WebApiServer.cs index 7c85740..219b2d0 100644 --- a/SlnMesnac.TouchSocket/WebApiServer.cs +++ b/SlnMesnac.TouchSocket/WebApiServer.cs @@ -109,4 +109,6 @@ namespace SlnMesnac.TouchSocket await e.InvokeNext(); } } + + } diff --git a/SlnMesnac.WPF/MainWindow.xaml.cs b/SlnMesnac.WPF/MainWindow.xaml.cs index 2139374..6a06a5e 100644 --- a/SlnMesnac.WPF/MainWindow.xaml.cs +++ b/SlnMesnac.WPF/MainWindow.xaml.cs @@ -1,4 +1,6 @@ -using SlnMesnac.WPF.ViewModel; +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.TouchSocket; +using SlnMesnac.WPF.ViewModel; using System; using System.Collections.Generic; using System.Linq; @@ -27,5 +29,17 @@ namespace SlnMesnac.WPF this.DataContext = new MainWindowViewModel(); } + + private void Button_Click(object sender, RoutedEventArgs e) + { + var a = AirPorthttpClient.ManipulatorStateRequest(new ManipulatorStateRequestEntity()); + var b = AirPorthttpClient.AGVStateRequest(new AGVStateRequestEntity()); + + + + + + return; + } } } diff --git a/SlnMesnac.WPF/Startup.cs b/SlnMesnac.WPF/Startup.cs index a95108b..9201391 100644 --- a/SlnMesnac.WPF/Startup.cs +++ b/SlnMesnac.WPF/Startup.cs @@ -45,6 +45,12 @@ namespace SlnMesnac.WPF //注册PLC工厂 services.AddPlcFactorySetup(); + //注册httpClient + services.AddHostedService(); + + //注册TCPServer + services.AddHostedService(); + //注册RFID工厂 //services.AddRfidFactorySetup(); @@ -52,7 +58,7 @@ namespace SlnMesnac.WPF //services.AddQuartzSetUp(); } - + /// /// AutoFac自动注入 /// diff --git a/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs index 574949e..c78c83a 100644 --- a/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs @@ -48,9 +48,12 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage { private ILogger _logger; private ILogger _taskBusinessLogger; + private ILogger _stateBusinessLogger; private IAirportTaskService _taskservice; private IAGVStateService _agvstateService; + private IManipulatorStateService _monipulatorstateService; private BaseTaskInfoBusiness _taskInfoBusiness; + private BaseStateRefreshBusiness _StateRefreshBusiness; private DispatcherTimer _timer; private TcpServer _tcpServer; @@ -105,6 +108,11 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage LoadTaskInfo(); + //_StateRefreshBusiness.UpdateManipulatorStateByResposne( + // new Model.AirportApiEntity.ManipulatorStateRequestEntity() + // { ManipulatorNo = "1", SignalSendTime = DateTime.Now.ToString()}); + //List AirportTaskItem = _taskservice.GetTaskInfos(); + //TaskItems = new ObservableCollection(AirportTaskItem); // TaskItems = new ObservableCollection // { // new AirportTask { TaskCode = "1", StationName = "1#站台", TaskDetails = "入库:P04->C01", Status = "任务状态:执行中" }, diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index 409b4d3..4864dae 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -8,7 +8,7 @@ }, "AllowedHosts": "*", "AppConfig": { - "logPath": "F:\\Mesnac\\2023部门项目\\机场AGV调度\\HightWay_AirPot_WCS\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\log", + "logPath": "D:\\WorkCode\\AirPortWCS\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\log", "SqlConfig": [ //{ // "configId": "mes", @@ -23,7 +23,7 @@ { "configId": "AGV", "dbType": 2, - "connStr": "Data Source=F:\\Mesnac\\2023部门项目\\机场AGV调度\\HightWay_AirPot_WCS\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\data\\Airport_db.sqlite;" + "connStr": "Data Source=D:\\WorkCode\\AirPortWCS\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows\\data\\Airport_db.sqlite" } ], "PlcConfig": [ @@ -62,8 +62,11 @@ ], "AMRIP": "127.0.0.1", - "redisConfig": "175.27.215.92:6379,password=redis@2023" + "redisConfig": "175.27.215.92:6379,password=redis@2023", + "AGVIpConfig": "127.0.0.1:4523", + "ManipulatorIpConfig": "127.0.0.1:4523", + "TCPVisionConfig": "127.0.0.1:6000" } } diff --git a/SlnMesnac/Controllers/AirportController.cs b/SlnMesnac/Controllers/AirportController.cs new file mode 100644 index 0000000..a72c25c --- /dev/null +++ b/SlnMesnac/Controllers/AirportController.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Quartz; +using SlnMesnac.Model.AirportApiEntity; +using SlnMesnac.Repository.service; + +namespace SlnMesnac.Controllers +{ + /// + /// 任务调度 + /// + [ApiController] + [Route("api/[controller]")] + public class AirportController + { + private readonly ILogger _logger; + + /// + /// + /// + /// + /// + public AirportController(ILogger logger) + { + _logger = logger; + } + + } + +} \ No newline at end of file diff --git a/SlnMesnac/Properties/launchSettings.json b/SlnMesnac/Properties/launchSettings.json index 3f9dcb9..8727f03 100644 --- a/SlnMesnac/Properties/launchSettings.json +++ b/SlnMesnac/Properties/launchSettings.json @@ -1,18 +1,8 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:32147", - "sslPort": 44302 - } - }, +{ "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - //"launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -20,11 +10,29 @@ "SlnMesnac": { "commandName": "Project", "launchBrowser": true, - //"launchUrl": "swagger", - "applicationUrl": "http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "applicationUrl": "http://localhost:5000" + }, + "WSL": { + "commandName": "WSL2", + "launchBrowser": true, + "launchUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "http://localhost:5000" + }, + "distributionName": "" + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:32147", + "sslPort": 44302 } } -} +} \ No newline at end of file diff --git a/SlnMesnac/SlnMesnac.csproj b/SlnMesnac/SlnMesnac.csproj index 191e4dc..d54790a 100644 --- a/SlnMesnac/SlnMesnac.csproj +++ b/SlnMesnac/SlnMesnac.csproj @@ -12,6 +12,7 @@ + diff --git a/SlnMesnac/Startup.cs b/SlnMesnac/Startup.cs index 14525f4..db57ccc 100644 --- a/SlnMesnac/Startup.cs +++ b/SlnMesnac/Startup.cs @@ -4,6 +4,7 @@ using SlnMesnac.Quartz; using SlnMesnac.Serilog; using SlnMesnac.Extensions; using System.Runtime.Serialization; +using SlnMesnac.Business.Airport; namespace SlnMesnac { @@ -79,6 +80,8 @@ namespace SlnMesnac //注册任务调度 services.AddQuartzSetUp(); + //添加服务 + //services.AddHostedService(); } diff --git a/SlnMesnac/appsettings.json b/SlnMesnac/appsettings.json index d05c71e..29fe095 100644 --- a/SlnMesnac/appsettings.json +++ b/SlnMesnac/appsettings.json @@ -10,6 +10,6 @@ "AppConfig": { "logPath": "E:\\桌面\\日常代码\\SlnMesnac\\SlnMesnac\\bin\\Debug\\net6.0", "mesConnStr": "server=.;uid=sa;pwd=123456;database=JiangYinMENS", - "mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma" + "mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma", } }