章政 8 жил өмнө
parent
commit
a92c23b79b

+ 56 - 6
UAS-MES/PublicMethod/ModeBusTCPServer.cs

@@ -23,8 +23,8 @@ namespace UAS_MES.PublicMethod
         Thread threadWatch = null; //负责监听客户端的线程
         Socket socketWatch = null; //负责监听客户端的套接字
         Socket socConnection;
-        string ip = "";
-        string port = "";
+        //等待机械臂完成动作
+        bool WaitFinish = true;
 
         public bool IsOpen
         {
@@ -39,12 +39,42 @@ namespace UAS_MES.PublicMethod
             }
         }
 
-        public ModeBusTCPServer(string IP, string Port)
+        public string IP
         {
-            ip = IP;
-            port = Port;
+            get
+            {
+                return iP;
+            }
+
+            set
+            {
+                iP = value;
+            }
+        }
+
+        public string Port
+        {
+            get
+            {
+                return port;
+            }
+
+            set
+            {
+                port = value;
+            }
+        }
+
+        private string iP;
+
+        private string port;
+
+        public ModeBusTCPServer()
+        {
+           
         }
 
+
         public void Open()
         {
             try
@@ -52,7 +82,7 @@ namespace UAS_MES.PublicMethod
                 //定义一个套接字用于监听客户端发来的信息  包含3个参数(IP4寻址协议,流式连接,TCP协议)
                 socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                 //服务端发送信息 需要1个IP地址和端口号
-                IPAddress ipaddress = IPAddress.Parse(ip);
+                IPAddress ipaddress = IPAddress.Parse(iP);
                 //将IP地址和端口号绑定到网络节点endpoint上 
                 IPEndPoint endpoint = new IPEndPoint(ipaddress, int.Parse(port));
                 //监听绑定的网络节点
@@ -88,6 +118,14 @@ namespace UAS_MES.PublicMethod
                 }
                 string stringdata = BitConverter.ToString(datashow);//把数组转换成16进制字符串
                 stringdata = stringdata.Replace("-", "");
+                //503口打开
+                if (stringdata.Substring(7, 1) == "1")
+                {
+                    socConnection.Send(M501_OFF);
+                    socConnection.Send(M502_OFF);
+                    socConnection.Send(M503_OFF);
+                    WaitFinish = false;
+                }
             }
         }
 
@@ -104,12 +142,24 @@ namespace UAS_MES.PublicMethod
             {
                 case "M501_ON":
                     socConnection.Send(M501_ON);
+                    WaitFinish = true;
+                    while (WaitFinish)
+                    {
+                        Thread.Sleep(80);
+                        socConnection.Send(M503_READ);
+                    }
                     break;
                 case "M501_OFF":
                     socConnection.Send(M501_OFF);
                     break;
                 case "M502_ON":
                     socConnection.Send(M502_ON);
+                    WaitFinish = true;
+                    while (WaitFinish)
+                    {
+                        Thread.Sleep(80);
+                        socConnection.Send(M503_READ);
+                    }
                     break;
                 case "M502_OFF":
                     socConnection.Send(M502_OFF);