diff --git a/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs index 7ae07dc..6977a54 100644 --- a/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs +++ b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs @@ -11,29 +11,27 @@ 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) + public BaseStateRefreshBusiness(ILogger logger, IAGVStateService agvService) { _logger = logger; _AGVStateService = agvService; - _ManipulatorStateService = manipulatorStateService; } - public static BaseStateRefreshBusiness GetInstance(ILogger logger, IAGVStateService agvService, IManipulatorStateService manipulatorStateService) + public static BaseStateRefreshBusiness GetInstance(ILogger logger, IAGVStateService agvService) { if (instance == null) { - instance = new BaseStateRefreshBusiness(logger, agvService, manipulatorStateService); + instance = new BaseStateRefreshBusiness(logger, agvService); } return instance; } - public bool UpdateAGVStateByResposne(AGVStateRequestEntity request) + public bool UpdateAGVStateByResposne() { try { - var response = AirPorthttpClient.AGVStateRequest(request); + var response = AirPorthttpClient.AGVStateRequest(); _AGVStateService.UpdateOrAddByResponse(response); } catch (Exception e) @@ -43,18 +41,5 @@ namespace SlnMesnac.Business.@base 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.Business/base/BaseTaskInfoBusiness.cs b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs index c0b2a7d..88d229d 100644 --- a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs +++ b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs @@ -30,8 +30,8 @@ namespace SlnMesnac.Business.@base { _logger = logger; _tcpServer = tcpServer; - _tcpServer.VisionSysStateEvent += TcpServerOnVisionSysStateEvent; - _tcpServer.StackWorkDoneEvent += _tcpServer_StackWorkDoneEvent; + _tcpServer.ReceiveVisionSysStateEvent += TcpServerOnVisionSysStateEvent; + _tcpServer.ReceiveStackWorkDoneEvent += _tcpServer_StackWorkDoneEvent; _Taskservice = Taskservice; _AGVStateService = agvService; InitClearTimer(); @@ -41,7 +41,7 @@ namespace SlnMesnac.Business.@base /// 一次码垛完成,发送码垛结果 /// /// - private void _tcpServer_StackWorkDoneEvent(TcpVisionEntity entity) + private void _tcpServer_StackWorkDoneEvent(TcpVisionEntity entity, string id) { try { @@ -76,7 +76,7 @@ namespace SlnMesnac.Business.@base /// 视觉系统回复给上位机调度系统开始工作状态 /// /// - private void TcpServerOnVisionSysStateEvent(TcpVisionEntity entity) + private void TcpServerOnVisionSysStateEvent(TcpVisionEntity entity, string id) { try { diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index ecc275c..ffeba99 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -74,11 +74,6 @@ namespace SlnMesnac.Config /// public string AGVIpConfig { get; set; } - /// - /// 机械臂地址配置 - /// - public string ManipulatorIpConfig { get; set; } - /// /// 机械臂地址配置 /// diff --git a/SlnMesnac.Model/domain/AGVState.cs b/SlnMesnac.Model/domain/AGVState.cs index 3b130b9..b0893cc 100644 --- a/SlnMesnac.Model/domain/AGVState.cs +++ b/SlnMesnac.Model/domain/AGVState.cs @@ -24,7 +24,7 @@ namespace SlnMesnac.Repository public int id {get;set;} /// - /// Desc: + /// Desc:AGV编号 /// Default: /// Nullable:False /// @@ -32,7 +32,7 @@ namespace SlnMesnac.Repository public string agvno {get;set;} /// - /// Desc: + /// Desc:AGV类型 1:AMR 2: 机械臂 /// Default: /// Nullable:False /// @@ -40,7 +40,7 @@ namespace SlnMesnac.Repository public string agvtype {get;set;} /// - /// Desc: + /// Desc:任务编号 /// Default: /// Nullable:False /// @@ -48,7 +48,7 @@ namespace SlnMesnac.Repository public string taskno {get;set;} /// - /// Desc: + /// Desc:AGV报警状态 /// Default: /// Nullable:False /// @@ -56,7 +56,7 @@ namespace SlnMesnac.Repository public string agvalarmstate {get;set;} /// - /// Desc: + /// Desc:AGV工作状态 /// Default: /// Nullable:False /// @@ -64,7 +64,7 @@ namespace SlnMesnac.Repository public string agvworkstate {get;set;} /// - /// Desc: + /// Desc:刷新时间 /// Default: /// Nullable:False /// diff --git a/SlnMesnac.Repository/service/IAGVStateService.cs b/SlnMesnac.Repository/service/IAGVStateService.cs index 5ff2935..a037ca9 100644 --- a/SlnMesnac.Repository/service/IAGVStateService.cs +++ b/SlnMesnac.Repository/service/IAGVStateService.cs @@ -35,7 +35,7 @@ namespace SlnMesnac.Repository.service /// /// /// - Task UpdateOrAddByResponse(AGVStateResponseEntity response); + Task UpdateOrAddByResponse(AGVResponseEntity> response); } } \ No newline at end of file diff --git a/SlnMesnac.Repository/service/IManipulatorStateService.cs b/SlnMesnac.Repository/service/IManipulatorStateService.cs deleted file mode 100644 index 8b5060d..0000000 --- a/SlnMesnac.Repository/service/IManipulatorStateService.cs +++ /dev/null @@ -1,39 +0,0 @@ -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 d73bf2b..579f3f9 100644 --- a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs @@ -15,7 +15,7 @@ namespace SlnMesnac.Repository.service.Impl public class AGVStateServiceImpl : BaseServiceImpl, IAGVStateService { private ILogger _logger; - public AGVStateServiceImpl(Repository repository, ILogger logger) :base(repository) + public AGVStateServiceImpl(Repository repository, ILogger logger) : base(repository) { _logger = logger; } @@ -26,13 +26,18 @@ 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($"��ȡ����AGV��Ϣ�쳣:{ex.Message}"); + _logger.LogError($"AGV状态获取错误:{ex.Message}"); } return agvStateInfoList; } @@ -46,7 +51,7 @@ namespace SlnMesnac.Repository.service.Impl } catch (Exception ex) { - _logger.LogError($"��ȡ����AGV��Ϣ�쳣:{ex.Message}"); + _logger.LogError($"所有AGV状态获取错误:{ex.Message}"); } return agvStateInfoList; } @@ -57,34 +62,43 @@ namespace SlnMesnac.Repository.service.Impl return result; } - public async Task UpdateOrAddByResponse(AGVStateResponseEntity response) + public async Task UpdateOrAddByResponse(AGVResponseEntity> response) { - AGVState record = new AGVState() + List records = new List(); + foreach (var entity in response.Data) { - agvno = response.AGVNo, - agvalarmstate = response.AGVAlarmState, - agvtype = response.AGVType, - agvworkstate = response.AGVWorkState, - refreshtime = DateTime.Now, - taskno = response.TaskNo, - }; + AGVState record = new AGVState() + { + agvno = entity.Guid, + agvalarmstate = entity.AgvMoveStatus != 6 ? "正常" : "异常", + agvtype = entity.Name, + agvworkstate = entity.AgvMoveStatus == 1 ? "空闲" : "忙碌", + refreshtime = DateTime.Now, + taskno = entity.TaskID, + }; + records.Add(record); + } + bool result = false; try { var list = GetAllAGVState(); - if (list.Where(x => x.agvno == response.AGVNo).Count() == 0) - { - result = _rep.Insert(record); - } - else + foreach (var r in records) { - record.id = list.Where(x => x.agvno == response.AGVNo).FirstOrDefault().id; - result = await _rep.UpdateAsync(record); + if (list.Where(x => x.agvno == r.agvno).Count() == 0) + { + result = _rep.Insert(r); + } + else + { + r.id = list.Where(x => x.agvno == r.agvno).FirstOrDefault().id; + result = await _rep.UpdateAsync(r); + } } } catch (Exception ex) { - _logger.LogError($"��е��״̬��Ϣ�����쳣:{ex.Message}"); + _logger.LogError($"AGV状态更新错误:{ex.Message}"); } return result; } diff --git a/SlnMesnac.Repository/service/Impl/ManipulatorStateServiceImpl.cs b/SlnMesnac.Repository/service/Impl/ManipulatorStateServiceImpl.cs deleted file mode 100644 index 56f6b3d..0000000 --- a/SlnMesnac.Repository/service/Impl/ManipulatorStateServiceImpl.cs +++ /dev/null @@ -1,92 +0,0 @@ -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 index d3b4444..eb2b10d 100644 --- a/SlnMesnac.TouchSocket/AirPorthttpClient.cs +++ b/SlnMesnac.TouchSocket/AirPorthttpClient.cs @@ -54,7 +54,6 @@ namespace SlnMesnac.TouchSocket try { AirportAGVClient = CreateWebApiClient(_appConfig.AGVIpConfig); - AirportManipulatorClient = CreateWebApiClient(_appConfig.ManipulatorIpConfig); } catch (Exception ex) { @@ -65,7 +64,7 @@ namespace SlnMesnac.TouchSocket } /// - /// AGV呼叫请求 + /// /// /// public static string AGVCallRequest() @@ -76,26 +75,49 @@ namespace SlnMesnac.TouchSocket } /// - /// AGV状态请求 + /// AGV下发任务请求 /// /// /// - public static AGVStateResponseEntity AGVStateRequest(AGVStateRequestEntity aGVStateRequest) + public static AGVResponseEntity AGVAddTaskRequest(AGVRequestAddTaskEntity addTaskEntity) { - JToken responseValue = AirportAGVClient.InvokeT("POST:/m1/5051269-4712337-default/apitest/AGVtest", null, aGVStateRequest); + JToken responseValue = AirportAGVClient.InvokeT("POST:/api/task/addTask", null, addTaskEntity); if (responseValue == null) { - return new AGVStateResponseEntity(); + return new AGVResponseEntity(); } string json = responseValue.ToString(); if (string.IsNullOrEmpty(json)) { - return new AGVStateResponseEntity(); + return new AGVResponseEntity(); } - AGVStateResponseEntity aGVStateResponseEntity = new AGVStateResponseEntity(); - aGVStateResponseEntity = JsonSerializer.Deserialize(json); - return aGVStateResponseEntity; + AGVResponseEntity responseEntity; + responseEntity = JsonSerializer.Deserialize>(json); + return responseEntity; } + + /// + /// 获取AGV所有信息 + /// + /// + /// + public static AGVResponseEntity> AGVStateRequest() + { + JToken responseValue = AirportAGVClient.InvokeT("GET:http://192.168.40.81:5102/api/task/robot/getRobot", null); + if (responseValue == null) + { + return new AGVResponseEntity>(); + } + string json = responseValue.ToString(); + if (string.IsNullOrEmpty(json)) + { + return new AGVResponseEntity>(); + } + AGVResponseEntity> ResponseEntity; + ResponseEntity = JsonSerializer.Deserialize>>(json); + return ResponseEntity; + } } + } diff --git a/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs index e2fe7af..0c3822a 100644 --- a/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexPage/IndexContentViewModel.cs @@ -53,7 +53,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage private ILogger _stateBusinessLogger; private IAirportTaskService _taskservice; private IAGVStateService _agvstateService; - private IManipulatorStateService _monipulatorstateService; private BaseTaskInfoBusiness _taskInfoBusiness; private BaseStateRefreshBusiness _StateRefreshBusiness; private DispatcherTimer _timer; diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index e0e208b..a7d7b96 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -82,8 +82,7 @@ "redisConfig": "175.27.215.92:6379,password=redis@2023", - "AGVIpConfig": "127.0.0.1:4523", - "ManipulatorIpConfig": "127.0.0.1:4523", + "AGVIpConfig": "http://192.168.40.81:5102", "TCPVisionConfig": "127.0.0.1:6000" }