src/Bro.Device.AuboRobot/AuboRobotDriver.cs
@@ -82,6 +82,7 @@
        #endregion
        TcpClient client = new TcpClient();
        NetworkStream stream = null;
        byte[] buffer = new byte[1024];
        private void OnConnect(IAsyncResult ar)
@@ -89,7 +90,8 @@
            try
            {
                client.EndConnect(ar);
                client.GetStream().BeginRead(buffer, 0, buffer.Length, OnDateReceived, null);
                stream = client.GetStream();
                stream.BeginRead(buffer, 0, buffer.Length, OnDataReceived, null);
            }
            catch (Exception ex)
            {
@@ -103,20 +105,21 @@
            }
        }
        private void OnDateReceived(IAsyncResult ar)
        private void OnDataReceived(IAsyncResult ar)
        {
            try
            {
                int dataLength = client.GetStream().EndRead(ar);
                int dataLength = stream.EndRead(ar);
                if (dataLength > 0)
                {
                    byte[] data = buffer.Take(dataLength).ToArray();
                    string dataStr = System.Text.Encoding.ASCII.GetString(data).Trim();
                    //OnLog?.BeginInvoke(DateTime.Now, this, $"{Name}接收数据:{dataStr}", null, null);
                    AnalyzeData(dataStr);
                    client.GetStream().BeginRead(buffer, 0, buffer.Length, OnDateReceived, null);
                    stream.BeginRead(buffer, 0, buffer.Length, OnDataReceived, null);
                }
                else
                {
@@ -192,7 +195,7 @@
                                 newValues.Add(int.Parse(resultStr[i].ToString()));
                             }
                             monitorHandle.Set();
                             MonitorHandle.Set();
                         }
                         else
                         {
@@ -232,6 +235,7 @@
            msg.Datas = new List<string>((paras ?? new List<float>()).ConvertAll(i => i.ToString()));
            OnLog?.BeginInvoke(DateTime.Now, this, $"{Name}发送指令:{msg.GetDisplayText()}", null, null);
            SendMsg(msg, true);
        }
@@ -246,6 +250,7 @@
        }
        bool canMonitor = true;
        object monitorLock = new object();
        public void SendMsg(RobotMsg msg, bool isWaitReply = true, bool isMonitorMsg = false)
        {
            if (isWaitReply)
@@ -256,17 +261,20 @@
            byte[] bytes = msg.GetMsgBytes(IConfig.Seperator, IConfig.EndChar);
            if (!isMonitorMsg)
            lock (monitorLock)
            {
                canMonitor = false;
            }
                if (!isMonitorMsg)
                {
                    canMonitor = false;
                }
            if (isMonitorMsg && !canMonitor)
                return;
                if (isMonitorMsg && !canMonitor)
                    return;
            //lock (this)
            {
                client.GetStream().Write(bytes, 0, bytes.Length);
                //lock (this)
                {
                    stream.Write(bytes, 0, bytes.Length);
                }
            }
            if (isWaitReply)
@@ -286,12 +294,15 @@
        protected List<int> oldValues = new List<int>();
        List<int> newValues = new List<int>();
        AutoResetEvent monitorHandle = new AutoResetEvent(false);
        public ManualResetEvent MonitorHandle { get; set; } = new ManualResetEvent(false);
        //public ManualResetEvent IOChangedHandle { get; set; } = new ManualResetEvent(true);
        public List<int> GetMonitorValues(int startAddress, int length)
        {
            MonitorHandle.Reset();
            scanMsg.ID = SID;
            SendMsg(scanMsg, true, true);
            monitorHandle.WaitOne(IConfig.ReplyTimeout);
            MonitorHandle.WaitOne(IConfig.ReplyTimeout);
            return newValues;
        }