章政 8 жил өмнө
parent
commit
45d583fcb5
2 өөрчлөгдсөн 28 нэмэгдсэн , 177 устгасан
  1. 21 38
      UAS-MES/Form1.Designer.cs
  2. 7 139
      UAS-MES/Form1.cs

+ 21 - 38
UAS-MES/Form1.Designer.cs

@@ -32,12 +32,10 @@
             this.button2 = new System.Windows.Forms.Button();
             this.button3 = new System.Windows.Forms.Button();
             this.button4 = new System.Windows.Forms.Button();
-            this.progressBar1 = new System.Windows.Forms.ProgressBar();
-            this.textBoxWithPlaceHolder1 = new UAS_MES.CustomControl.TextBoxWithIcon.TextBoxWithPlaceHolder();
-            this.serialPortCombox1 = new UAS_MES.CustomControl.ComBoxWithFocus.SerialPortCombox();
             this.txtMsg = new System.Windows.Forms.RichTextBox();
             this.txtIP = new System.Windows.Forms.TextBox();
             this.txtPORT = new System.Windows.Forms.TextBox();
+            this.enterTextBox2 = new UAS_MES.CustomControl.TextBoxWithIcon.EnterTextBox();
             this.SuspendLayout();
             // 
             // button1
@@ -62,12 +60,12 @@
             // 
             // button3
             // 
-            this.button3.Location = new System.Drawing.Point(407, 198);
+            this.button3.Location = new System.Drawing.Point(424, 198);
             this.button3.Margin = new System.Windows.Forms.Padding(4);
             this.button3.Name = "button3";
             this.button3.Size = new System.Drawing.Size(100, 29);
             this.button3.TabIndex = 0;
-            this.button3.Text = "button3";
+            this.button3.Text = "OPEN";
             this.button3.UseVisualStyleBackColor = true;
             this.button3.Click += new System.EventHandler(this.button3_Click_1);
             // 
@@ -78,35 +76,10 @@
             this.button4.Name = "button4";
             this.button4.Size = new System.Drawing.Size(100, 29);
             this.button4.TabIndex = 2;
-            this.button4.Text = "button4";
+            this.button4.Text = "Send";
             this.button4.UseVisualStyleBackColor = true;
             this.button4.Click += new System.EventHandler(this.button4_Click);
             // 
-            // progressBar1
-            // 
-            this.progressBar1.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
-            this.progressBar1.Location = new System.Drawing.Point(288, 112);
-            this.progressBar1.Margin = new System.Windows.Forms.Padding(4);
-            this.progressBar1.Name = "progressBar1";
-            this.progressBar1.Size = new System.Drawing.Size(448, 29);
-            this.progressBar1.TabIndex = 3;
-            // 
-            // textBoxWithPlaceHolder1
-            // 
-            this.textBoxWithPlaceHolder1.BackColor = System.Drawing.Color.White;
-            this.textBoxWithPlaceHolder1.Location = new System.Drawing.Point(697, 198);
-            this.textBoxWithPlaceHolder1.Name = "textBoxWithPlaceHolder1";
-            this.textBoxWithPlaceHolder1.PlaceHolder = "123123";
-            this.textBoxWithPlaceHolder1.Size = new System.Drawing.Size(241, 25);
-            this.textBoxWithPlaceHolder1.TabIndex = 4;
-            // 
-            // serialPortCombox1
-            // 
-            this.serialPortCombox1.Location = new System.Drawing.Point(398, 61);
-            this.serialPortCombox1.Name = "serialPortCombox1";
-            this.serialPortCombox1.Size = new System.Drawing.Size(186, 25);
-            this.serialPortCombox1.TabIndex = 6;
-            // 
             // txtMsg
             // 
             this.txtMsg.Location = new System.Drawing.Point(424, 320);
@@ -129,19 +102,31 @@
             this.txtPORT.Name = "txtPORT";
             this.txtPORT.Size = new System.Drawing.Size(100, 25);
             this.txtPORT.TabIndex = 9;
-            this.txtPORT.Text = "502";
+            this.txtPORT.Text = "8080";
+            // 
+            // enterTextBox2
+            // 
+            this.enterTextBox2.AllPower = null;
+            this.enterTextBox2.BackColor = System.Drawing.Color.White;
+            this.enterTextBox2.ID = null;
+            this.enterTextBox2.Location = new System.Drawing.Point(753, 270);
+            this.enterTextBox2.Name = "enterTextBox2";
+            this.enterTextBox2.Power = null;
+            this.enterTextBox2.Size = new System.Drawing.Size(196, 25);
+            this.enterTextBox2.Str = null;
+            this.enterTextBox2.Str1 = null;
+            this.enterTextBox2.Str2 = null;
+            this.enterTextBox2.TabIndex = 10;
             // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1239, 738);
+            this.Controls.Add(this.enterTextBox2);
             this.Controls.Add(this.txtPORT);
             this.Controls.Add(this.txtIP);
             this.Controls.Add(this.txtMsg);
-            this.Controls.Add(this.serialPortCombox1);
-            this.Controls.Add(this.textBoxWithPlaceHolder1);
-            this.Controls.Add(this.progressBar1);
             this.Controls.Add(this.button4);
             this.Controls.Add(this.button3);
             this.Margin = new System.Windows.Forms.Padding(4);
@@ -163,11 +148,9 @@
         private CustomControl.SetLoading.LoadingCircle loadingCircle1;
         private System.Windows.Forms.Button button3;
         private System.Windows.Forms.Button button4;
-        private System.Windows.Forms.ProgressBar progressBar1;
-        private CustomControl.TextBoxWithIcon.TextBoxWithPlaceHolder textBoxWithPlaceHolder1;
-        private CustomControl.ComBoxWithFocus.SerialPortCombox serialPortCombox1;
         private System.Windows.Forms.RichTextBox txtMsg;
         private System.Windows.Forms.TextBox txtIP;
         private System.Windows.Forms.TextBox txtPORT;
+        private CustomControl.TextBoxWithIcon.EnterTextBox enterTextBox2;
     }
 }

+ 7 - 139
UAS-MES/Form1.cs

@@ -31,7 +31,7 @@ namespace UAS_MES
             InitializeComponent();
         }
 
-      
+
 
         private void Form1_Load(object sender, EventArgs e)
         {
@@ -41,7 +41,7 @@ namespace UAS_MES
             //Com.BaudRate = 9600;
             //Com.StopBits = StopBits.One;
             //Com.Parity = Parity.None;
-  
+
         }
 
         [DllImport("WinIo64.dll")]
@@ -71,149 +71,17 @@ namespace UAS_MES
         private static IntPtr state_port = (IntPtr)0x379;    //状态端口地址 S3-S7 只能读取5位  
         private static IntPtr control_port = (IntPtr)0x37A;  //控制端口地址 C0-C3 只能控制或输出4位  
 
-        /// <summary>  
-        /// 设定DataPort输出  
-        /// </summary>  
-        /// <param name="WriteValue">设定值:范围为0~255</param>  
-        private void setDateBuff(int WriteValue)
-        {
-            IntPtr m_nport = data_port;                 //数据端口地址data_port  
-
-            int m_nValue = WriteValue;
-
-            //调用WinIo库函数SetPortVal写端口值  
-            SetPortVal(m_nport, m_nValue, 1);           //write a BYTE value to an I/O port  
-        }
-
-        /// <summary>  
-        /// 设定ControlPort输出  
-        /// 高4位默认设置,请不要修改,因此输出时保持高位值不变,将要输出的值从低4位输出  
-        /// Control端口C2读写正常,C0、C1、C3写入0则输出高电平,写入1输出低电平;读取亦然  
-        /// </summary>  
-        /// <param name="WriteValue">设定值</param>  
-        private void setControlBuff(int WriteValue)
-        {
-            IntPtr m_nport = control_port;              //获得控制端口地址  
-            //获得控制端口的值,  
-            int temp_dwPortVal = 0;
-            GetPortVal(m_nport, out temp_dwPortVal, 1); //reads a BYTE value from an I/O port  
-
-            int temp_aa = temp_dwPortVal & 0xF0;        //将低4位置为0;高4位不变  
-
-            int WriValue = WriteValue & 0x0F;           //取设定值低4位;高4位为0  
-            temp_aa = temp_aa | WriteValue;             //合并端口值高4位与设定值低4位  
-            temp_aa = temp_aa ^ 0x0B;                   //将低4位中C0、C1、C3取反(0->1;1->0)(保证设定值与实际电平相吻合)  
-            SetPortVal(m_nport, temp_aa, 1);            //写出的值中,高4位保持端口原来的值不变,低4位实际输出  
-        }
-
-        /// <summary>  
-        /// 读取ControlPort值  
-        /// Control端口C2读取正常,C0、C1、C3高电平则读入0,低电平则读入1  
-        /// </summary>  
-        /// <returns>返回C0-C3 四个端口的值:范围为0~15</returns>  
-        private int getControlBuff()
-        {
-            IntPtr m_nport = control_port;              //控制端口地址data_port  
-
-            int m_nValue = 0;
-            //调用WinIo库函数SetPortVal写端口值  
-            GetPortVal(m_nport, out m_nValue, 1);      //reads a BYTE value from an I/O port  
-
-            int ValueGet = m_nValue ^ 0x0B;            //将低4位中C0、C1、C3取反(0->1;1->0)  
-            ValueGet = ValueGet & 0x0F;                //去掉高4位值  
-            return ValueGet;
-        }
-
-        /// <summary>  
-        /// 读取StatePort值  
-        /// State端口S7高电平则读入0,低电平则读入1;其他正常  
-        /// </summary>  
-        /// <returns>返回S3-S7 五个端口的值:范围0-31</returns>  
-        private int getStateBuff()
-        {
-            IntPtr m_nport = state_port;               //控制端口地址state_port  
-
-            int dwPortVal = 0;
-            GetPortVal(m_nport, out dwPortVal, 1);    //reads a BYTE value from an I/O port  
-
-            int ValueGet = dwPortVal ^ 0x80;          //将S7取反(保证读取与实际电平相吻合)  
-            ValueGet = ValueGet & 0xF8;               //去掉S0 ~S2位;  
-            ValueGet = ValueGet >> 3;                 //右移3位,将S7~S3变为低5位  
-            return ValueGet;
-        }
-
-        public bool OpenWinIo()
-        {
-            if (InitializeWinIo())
-            {
-                this.online = true;
-                return true;
-            }
-            else
-            {
-                this.online = false;
-                return false;
-            }
-        }
-
-        public void CloseWinIo()
-        {
-            ShutdownWinIo();
-            this.online = false;
-        }
-
-        SerialPort Com = new SerialPort();
-
+        ModeBusTCPServer md;
         private void button3_Click_1(object sender, EventArgs e)
         {
-            //byte[] byteArr = new byte[20];
-            //Com.Write(byteArr, 0, byteArr.Length);
-            //CloseWinIo();
+            md = new ModeBusTCPServer(txtIP.Text, txtPORT.Text);
+            md.Open();
+            txtMsg.AppendText("SUCCESS");
         }
 
-        Thread threadWatch = null; //负责监听客户端的线程
-        Socket socketWatch = null; //负责监听客户端的套接字
-        //创建一个负责和客户端通信的套接字 
-        List<Socket> socConnections = new List<Socket>();
-        List<Thread> dictThread = new List<Thread>();
         private void button4_Click(object sender, EventArgs e)
         {
-            CheckForIllegalCrossThreadCalls = false;
-            //定义一个套接字用于监听客户端发来的信息  包含3个参数(IP4寻址协议,流式连接,TCP协议)
-            socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-            //服务端发送信息 需要1个IP地址和端口号
-            IPAddress ipaddress = IPAddress.Parse(txtIP.Text.Trim()); //获取文本框输入的IP地址
-            //将IP地址和端口号绑定到网络节点endpoint上 
-            IPEndPoint endpoint = new IPEndPoint(ipaddress, int.Parse(txtPORT.Text.Trim())); //获取文本框上输入的端口号
-            //监听绑定的网络节点
-            socketWatch.Bind(endpoint);
-            //将套接字的监听队列长度限制为20
-            socketWatch.Listen(20);
-            //创建一个监听线程 
-            threadWatch = new Thread(WatchConnecting);
-            //将窗体线程设置为与后台同步
-            threadWatch.IsBackground = true;
-            //启动线程
-            threadWatch.Start();
-            //启动线程后 txtMsg文本框显示相应提示
-            txtMsg.AppendText("开始监听客户端传来的信息!" + "\r\n");
-
-        }
-
-        private void WatchConnecting()
-        {
-            while (true)
-            {
-                byte[] data = new byte[1024];
-                socketWatch.Receive(data);
-                int length = data[5];
-                byte[] datashow = new byte[length + 6];
-                Console.WriteLine(data);
-                for (int i = 0; i <= length + 5; i++)
-                    datashow[i] = data[i];
-                string stringdata = BitConverter.ToString(datashow);//把数组转换成16进制字符串
-                Console.WriteLine(stringdata);
-            }
+            md.SendOrder(enterTextBox2.Text);
         }
     }
 }