From 7971d855ba2cf9772b46a7f67e2b669c0afcb91b Mon Sep 17 00:00:00 2001 From: patrick <patrick.xu@broconcentric.com> Date: 星期二, 22 十月 2019 11:30:35 +0800 Subject: [PATCH] 1. 添加标定操作及界面 2. 修改配置界面方法调用参数 3. SeerAGV添加电池信息监听 4. 添加AGV电池充电操作 5. 修改AGV状态变化操作,添加操作锁 --- src/Bro.Device.SeerAGV/SeerAGVDriver.cs | 87 +++++++++++++++++++++++++++++++++++-------- 1 files changed, 70 insertions(+), 17 deletions(-) diff --git a/src/Bro.Device.SeerAGV/SeerAGVDriver.cs b/src/Bro.Device.SeerAGV/SeerAGVDriver.cs index e64d17c..635132e 100644 --- a/src/Bro.Device.SeerAGV/SeerAGVDriver.cs +++ b/src/Bro.Device.SeerAGV/SeerAGVDriver.cs @@ -19,6 +19,7 @@ { public Action<SeerAGVDriver, string> OnAGVPositoinChanged; public Action<SeerAGVDriver, AGVTaskStatus> OnAGVTaskStatusChanged; + public Action<SeerAGVDriver, float> OnAGVBatteryLvlChanged; SeerAGVInitialConfig IConfig { @@ -36,13 +37,13 @@ protected override void Init() { - InitialTcpClient(client_State, IConfig.StatusPort); - InitialTcpClient(client_Guide, IConfig.GuidePort); + InitialTcpClient(ref client_State, IConfig.StatusPort); + InitialTcpClient(ref client_Guide, IConfig.GuidePort); } - private void InitialTcpClient(TcpClient client, int port) + private void InitialTcpClient(ref TcpClient client, int port) { - if (client == null || !client_State.Connected) + if (client == null || !client.Connected) { client = new TcpClient(); client.SendBufferSize = client.ReceiveBufferSize = 0; @@ -64,6 +65,7 @@ { msg_Position = new SeerMessage((int)AGVCode.QueryPosition, SID); msg_GuideStatus = new SeerMessage((int)AGVCode.QueryTaskStatus, SID, IConfig.IsSimpleMonitor ? JsonConvert.SerializeObject(new { simple = true }) : ""); + msg_Battery = new SeerMessage((int)AGVCode.QueryBattery, SID, IConfig.IsSimpleMonitor ? JsonConvert.SerializeObject(new { simple = true }) : ""); Task.Run(() => { @@ -73,7 +75,18 @@ protected override void Stop() { - throw new NotImplementedException(); + if (client_Guide != null && client_Guide.Connected) + { + CancelTask(); + client_Guide.Close(); + client_Guide = null; + } + + if (client_State != null && client_State.Connected) + { + client_State.Close(); + client_State = null; + } } #endregion @@ -96,7 +109,7 @@ byte[] buffer = new byte[1024]; string currentPosition = ""; - string CurrentPosition + public string CurrentPosition { get => currentPosition; set @@ -105,13 +118,16 @@ { currentPosition = value; - OnAGVPositoinChanged?.Invoke(this, currentPosition); + if (!string.IsNullOrWhiteSpace(currentPosition)) + { + OnAGVPositoinChanged?.Invoke(this, currentPosition); + } } } } AGVTaskStatus taskStatus = AGVTaskStatus.None; - AGVTaskStatus TaskStatus + public AGVTaskStatus TaskStatus { get => taskStatus; set @@ -119,21 +135,49 @@ if (taskStatus != value) { taskStatus = value; - OnAGVTaskStatusChanged?.Invoke(this, taskStatus); + + if (taskStatus != AGVTaskStatus.None) + { + OnAGVTaskStatusChanged?.Invoke(this, taskStatus); + } + } + } + } + + float batteryLvl = 0; + public float BatteryLvl + { + get => batteryLvl; + set + { + if (batteryLvl != value) + { + batteryLvl = value; + OnAGVBatteryLvlChanged?.Invoke(this, batteryLvl); } } } SeerMessage msg_Position = new SeerMessage(); SeerMessage msg_GuideStatus = new SeerMessage(); + SeerMessage msg_Battery = new SeerMessage(); private void MonitorAGV() { while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept) { - SendMsg(client_State, IConfig.StatusPort, msg_Position); - Thread.Sleep(IConfig.ScanInterval); - SendMsg(client_State, IConfig.StatusPort, msg_GuideStatus); - Thread.Sleep(IConfig.ScanInterval); + try + { + SendMsg(client_State, IConfig.StatusPort, msg_Position); + Thread.Sleep(IConfig.ScanInterval); + SendMsg(client_State, IConfig.StatusPort, msg_GuideStatus); + Thread.Sleep(IConfig.ScanInterval); + SendMsg(client_State, IConfig.StatusPort, msg_Battery); + Thread.Sleep(IConfig.ScanInterval); + } + catch (Exception ex) + { + OnLog?.Invoke(DateTime.Now, this, $"{Name}鐩戝惉寮傚父锛歿ex.GetExceptionMessage()}"); + } } } @@ -145,7 +189,7 @@ { try { - InitialTcpClient(client, port); + InitialTcpClient(ref client, port); var stream = client.GetStream(); stream.Write(msg.Frame, 0, msg.Frame.Length); @@ -155,8 +199,7 @@ { byte[] rec = buffer.Take(recSize).ToArray(); SeerMessage recMsg = SeerMessage.GetSeerMessage(rec); - - if (recMsg.TypeCode != msg.TypeCode || recMsg.SeqNum != msg.SeqNum) + if (recMsg.TypeCode != (10000 + msg.TypeCode) || recMsg.SeqNum != msg.SeqNum) { throw new ProcessException("鍙嶉淇℃伅鍜屽彂閫佷俊鎭笉涓�鑷�", null); } @@ -199,13 +242,16 @@ { await Task.Run(() => { - switch (recMsg.TypeCode) + switch (recMsg.TypeCode - 10000) { case (int)AGVCode.QueryPosition: CurrentPosition = recMsg.JValues.Value<string>("current_station"); break; case (int)AGVCode.QueryTaskStatus: TaskStatus = (AGVTaskStatus)recMsg.JValues.Value<int>("task_status"); + break; + case (int)AGVCode.QueryBattery: + BatteryLvl = recMsg.JValues.Value<float>("battery_level"); break; default: break; @@ -219,8 +265,15 @@ SendMsg(client_Guide, IConfig.GuidePort, msg); } + public void PauseTask() + { + SeerMessage msg = new SeerMessage((int)AGVCode.PauseTask, SID); + SendMsg(client_Guide, IConfig.GuidePort, msg); + } + public void TaskOrder(string dest) { + CurrentPosition = ""; SeerMessage msg = new SeerMessage((int)AGVCode.TaskOrder, SID, JsonConvert.SerializeObject(new { id = dest })); SendMsg(client_Guide, IConfig.GuidePort, msg); } -- Gitblit v1.8.0