src/Bro.Device.SeerAGV/SeerAGVDriver.cs
@@ -36,13 +36,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;
@@ -73,7 +73,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 +107,7 @@
        byte[] buffer = new byte[1024];
        string currentPosition = "";
        string CurrentPosition
        public string CurrentPosition
        {
            get => currentPosition;
            set
@@ -105,13 +116,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,7 +133,11 @@
                if (taskStatus != value)
                {
                    taskStatus = value;
                    OnAGVTaskStatusChanged?.Invoke(this, taskStatus);
                    if (taskStatus != AGVTaskStatus.None)
                    {
                        OnAGVTaskStatusChanged?.Invoke(this, taskStatus);
                    }
                }
            }
        }
@@ -130,10 +148,17 @@
        {
            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);
                }
                catch (Exception ex)
                {
                    OnLog?.Invoke(DateTime.Now, this, $"{Name}监听异常:{ex.GetExceptionMessage()}");
                }
            }
        }
@@ -145,7 +170,7 @@
            {
                try
                {
                    InitialTcpClient(client, port);
                    InitialTcpClient(ref client, port);
                    var stream = client.GetStream();
                    stream.Write(msg.Frame, 0, msg.Frame.Length);
@@ -155,8 +180,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,7 +223,7 @@
        {
            await Task.Run(() =>
            {
                switch (recMsg.TypeCode)
                switch (recMsg.TypeCode - 10000)
                {
                    case (int)AGVCode.QueryPosition:
                        CurrentPosition = recMsg.JValues.Value<string>("current_station");
@@ -219,8 +243,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);
        }