From cea153552316bfad7d5aaf98035304e36b8119a7 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Fri, 11 Oct 2024 10:03:50 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E6=9C=BA=E6=A2=B0=E8=87=82=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=AE=9E=E7=8E=B0=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=A8=A1=E6=9D=BF=EF=BC=8C=E7=82=B9=E4=BD=8D=EF=BC=8C?= =?UTF-8?q?AGV=E7=9A=84=E5=9B=BA=E5=AE=9A=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Config/AGVConfig.cs | 13 +++ SlnMesnac.Config/AppConfig.cs | 18 ++++ SlnMesnac.Config/JobConfig.cs | 13 +++ SlnMesnac.Config/PositionConfig.cs | 15 ++++ .../AirportApiEntity/AGVAddTaskEntity.cs | 37 ++++++++ SlnMesnac.TouchSocket/TcpServer.cs | 88 +++++++++++++------ SlnMesnac.WPF/MainWindow.xaml | 4 + SlnMesnac.WPF/MainWindow.xaml.cs | 25 ++++++ .../Page/IndexPage/IndexContent.xaml.cs | 1 + .../IndexPage/IndexContentViewModel.cs | 41 +-------- .../ViewModel/MainWindowViewModel.cs | 52 ++++++++++- SlnMesnac.WPF/appsettings.json | 47 +++++++++- 12 files changed, 281 insertions(+), 73 deletions(-) create mode 100644 SlnMesnac.Config/AGVConfig.cs create mode 100644 SlnMesnac.Config/JobConfig.cs create mode 100644 SlnMesnac.Config/PositionConfig.cs diff --git a/SlnMesnac.Config/AGVConfig.cs b/SlnMesnac.Config/AGVConfig.cs new file mode 100644 index 0000000..6d94856 --- /dev/null +++ b/SlnMesnac.Config/AGVConfig.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Config +{ + public class AGVConfig + { + public string AGVGUID { get; set; } + + public string AGVName { get; set; } + } +} diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index ffeba99..4dc8c16 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -58,6 +58,24 @@ namespace SlnMesnac.Config /// public List visionConfig { get; set; } + /// + /// AGV配置 + /// + public List AGVConfig { get; set; } + + /// + /// 地图点位配置 + /// + public List PositionConfig { get; set; } + + /// + /// 模板配置 + /// + public List JobConfig { get; set; } + + + + /// /// Redis配置 /// diff --git a/SlnMesnac.Config/JobConfig.cs b/SlnMesnac.Config/JobConfig.cs new file mode 100644 index 0000000..270699d --- /dev/null +++ b/SlnMesnac.Config/JobConfig.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Config +{ + public class JobConfig + { + public string JobGUID { get; set; } + + public string JobName { get; set; } + } +} diff --git a/SlnMesnac.Config/PositionConfig.cs b/SlnMesnac.Config/PositionConfig.cs new file mode 100644 index 0000000..9e4b549 --- /dev/null +++ b/SlnMesnac.Config/PositionConfig.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Config +{ + public class PositionConfig + { + public string PointGUID { get; set; } + + public string PointName { get; set; } + + public string PointParamName { get; set; } + } +} diff --git a/SlnMesnac.Model/AirportApiEntity/AGVAddTaskEntity.cs b/SlnMesnac.Model/AirportApiEntity/AGVAddTaskEntity.cs index 212d0c6..cfe2f9e 100644 --- a/SlnMesnac.Model/AirportApiEntity/AGVAddTaskEntity.cs +++ b/SlnMesnac.Model/AirportApiEntity/AGVAddTaskEntity.cs @@ -122,4 +122,41 @@ namespace SlnMesnac.Model.AirportApiEntity /// public string guid { get; set; } } + + public class NewAddTaskByAGV + { + public AGVRequestAddTaskEntity NewTaskEntity(string AGVGUID, string JobGUID, string PointGUID, string ParamName, string TaskName = "AGVCTask", string RobotType = "S800") + { + AGVRequestAddTaskEntity aGVRequestAddTaskEntity = new AGVRequestAddTaskEntity() + { + businessOrderId = TaskName, + priority = 0, + RobotType = RobotType, + robotId = AGVGUID, + group = "", + taskSource = "agvc", + taskType = 0, + verifyStatus = 0, + enableSplitCar = 0, + load = new List() + { + new LoadsEntity() + { + jobid = JobGUID, + location = PointGUID, + param = new List() + { + new ParamEntity() + { + paramname = ParamName, + paramvalue = PointGUID, + } + }, + robotPort = "" + } + }, + }; + return aGVRequestAddTaskEntity; + } + } } diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs index 05c64a7..02335ae 100644 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ b/SlnMesnac.TouchSocket/TcpServer.cs @@ -86,6 +86,8 @@ namespace SlnMesnac.TouchSocket private string TestClientID = ""; + public int Vport; + public TcpServer(ILogger logger, TcpService tcpService, AppConfig appConfig) { _logger = logger; @@ -108,40 +110,44 @@ namespace SlnMesnac.TouchSocket { _service.Connecting = (client, e) => { - _logger.LogInformation($"客户端{client.IP}正在接入服务"); + _logger.LogInformation($"客户端{client.IP}:{client.Port}正在接入服务"); return EasyTask.CompletedTask; }; _service.Connected = (client, e) => { - _logger.LogInformation($"客户端{client.IP}接入服务成功"); + _logger.LogInformation($"客户端{client.IP}:{client.Port}接入服务成功"); RefreshClientInfoEvent?.Invoke(_service); RefreshStateAction?.Invoke(client.IP, true); client.ResetId(client.Port.ToString()); TestClientID = client.Port.ToString(); + Vport = client.Port; return EasyTask.CompletedTask; }; _service.Disconnected = (client, e) => { - _logger.LogInformation($"客户端{client.IP}断开连接"); + _logger.LogInformation($"客户端{client.IP}:{client.Port}断开连接"); RefreshStateAction?.Invoke(client.IP, false); RefreshClientInfoEvent?.Invoke(_service); return EasyTask.CompletedTask; }; _service.Received = (client, e) => { - var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len - _logger.LogInformation($"客户端{client.IP}:" + mes); - //区分一下指令类型,委托传参 - - if (mes == "heartbeat") - { - RefreshStateAction?.Invoke(client.IP, true); - } + //var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len + + //_logger.LogInformation($"客户端{client.IP}:{client.Port} :" + mes); + //区分一下指令类型,委托传参 + //if (mes == "heartbeat") + //{ + // RefreshStateAction?.Invoke(client.IP, true); + //} byte[] receivedBuffer = new byte[e.ByteBlock.Len]; Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len); + + var mes = ByteArrayToHexString(receivedBuffer); + _logger.LogInformation($"客户端{client.IP}:{client.Port} :" + mes); DataClassify(BufferDataAnalysis.BufferRootAnalysis(receivedBuffer), client.Id); return EasyTask.CompletedTask; @@ -168,6 +174,21 @@ namespace SlnMesnac.TouchSocket } + /// + /// byte数组转字符串 + /// + /// + /// + private string ByteArrayToHexString(byte[] byteArray) + { + if (byteArray == null || byteArray.Length == 0) + { + return string.Empty; + } + + return string.Join(" ", byteArray.Select(b => b.ToString("X2"))); + } + //private void Test() //{ // try @@ -362,15 +383,20 @@ namespace SlnMesnac.TouchSocket /// public void VisionStateRequest(TcpVisionEntity entity, string id) { - SendRequestVisionSysState(id); + if(entity.DataLength == 2) + { + + } + //Thread.Sleep(1000); + //SendRequestVisionSysState(id); } /// /// AMR就绪,请求视觉开始工作 /// - public void RequestVisionStartWork(StackState state, int port) + public void RequestVisionStartWork(StackState state, string id) { - SendAMRRequestVisionStartWork(new byte[1] { (byte)state }, port.ToString()); + SendAMRRequestVisionStartWork(new byte[1] { (byte)state }, id); } /// @@ -404,67 +430,71 @@ namespace SlnMesnac.TouchSocket _logger.LogInformation($"视觉系统收到开始工作状态:{result}"); } + int VCount = 1; + /// /// 接受码垛结果 /// public void StackResultSend(TcpVisionEntity entity, string id) { - string result; if (entity.DataLength == 1) { if (entity.DataBytes[0] == 0x00) { - result = "码垛完成"; + _logger.LogInformation($"视觉系统一次码垛结束,码垛完成"); //上位机回复收到码垛结果 SendReplayStackResult(id); - if (true) //这里写是否继续下一次码垛的判断条件 + if (VCount < 5) //这里写是否继续下一次码垛的判断条件 { //如果码垛没结束继续发下一次的码垛信号 if (true) //这里写向哪个机器人码垛的判断条件 { //发送向搬运机器人(AGVDeliver)码垛的信号 - SendAMRRequestVisionStartWork(new byte[] { 0x10 }, id); + RequestVisionStartWork(StackState.AGVNoPositioning, id); _logger.LogInformation("下一次码垛开始,方向:搬运机器人"); } else { //发送向复合机器人(AMR)码垛的信号 - SendAMRRequestVisionStartWork(new byte[] { 0x01 }, id); + RequestVisionStartWork(StackState.AMRNoPositioning, id); _logger.LogInformation("下一次码垛开始,方向:复合机器人"); } + VCount++; } else { //如果码垛结束就请求复位 - SendStackOverRequestVisionSysReplace(id); + RequestVisionReplace(id); + _logger.LogInformation("本次码垛结束,请求复位"); + VCount = 1; } } else if (entity.DataBytes[0] == 0x01) { - result = "码垛过程失败"; + _logger.LogInformation($"视觉系统一次码垛结束,码垛过程失败"); } else if (entity.DataBytes[0] == 0x02) { - result = "码垛检查失败"; + _logger.LogInformation($"视觉系统一次码垛结束,码垛检查失败"); } else { - result = "未知返回代码"; + _logger.LogInformation($"视觉系统一次码垛结束,未知返回代码"); } } else { - result = "返回数据格式错误"; + _logger.LogInformation($"视觉系统一次码垛结束,返回数据格式错误"); } - _logger.LogInformation($"视觉系统一次码垛结束:{result}"); + } /// /// 码垛结束,请求视觉系统复位 /// - public void RequestVisionReplace(int port) + public void RequestVisionReplace(string port) { - SendStackOverRequestVisionSysReplace(port.ToString()); + SendStackOverRequestVisionSysReplace(port); } /// @@ -509,12 +539,12 @@ namespace SlnMesnac.TouchSocket /// /// 搬运机器人码垛无需定位 /// - RGVNoPositioning = 0x10, + AGVNoPositioning = 0x10, /// /// 搬运机器人码垛需要定位 /// - RGVNeedPositioning = 0x11, + AGVNeedPositioning = 0x11, } } diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 0444fba..94d9883 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -64,6 +64,10 @@