فهرست منبع

修改指令发送编码方式

章政 7 سال پیش
والد
کامیت
a1e847a4d0
3فایلهای تغییر یافته به همراه17 افزوده شده و 18 حذف شده
  1. 3 3
      PLCDataReader/Main.Designer.cs
  2. 3 3
      PLCDataReader/Main.cs
  3. 11 12
      PLCDataReader/PublicMethod/ModeBusTCPServer.cs

+ 3 - 3
PLCDataReader/Main.Designer.cs

@@ -33,6 +33,7 @@ namespace UAS_PLCDataReader
         /// </summary>
         private void InitializeComponent()
         {
+            this.components = new System.ComponentModel.Container();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
             this.RibbonNav = new DevExpress.XtraBars.Ribbon.RibbonControl();
             this.ButtonDeviceList = new DevExpress.XtraBars.BarButtonItem();
@@ -165,8 +166,8 @@ namespace UAS_PLCDataReader
             this.PageWorkCenterStatus = new DevExpress.XtraTab.XtraTabPage();
             this.GridWorkCenterStatus = new UAS_PLCDataReader.CustomerControl.AutoDataGridControl.AutoDataGridControl();
             this.GridViewWorkCenterStatus = new UAS_PLCDataReader.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
-            this.TimerDeviceStatus = new System.Windows.Forms.Timer();
-            this.CommonTipController = new DevExpress.Utils.ToolTipController();
+            this.TimerDeviceStatus = new System.Windows.Forms.Timer(this.components);
+            this.CommonTipController = new DevExpress.Utils.ToolTipController(this.components);
             ((System.ComponentModel.ISupportInitialize)(this.RibbonNav)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MainTabControl)).BeginInit();
             this.MainTabControl.SuspendLayout();
@@ -894,7 +895,6 @@ namespace UAS_PLCDataReader
             this.dc_date.ColumnEdit = this.repositoryItemDateEdit1;
             this.dc_date.FieldName = "DC_DATE";
             this.dc_date.Name = "dc_date";
-            this.dc_date.OptionsColumn.AllowEdit = false;
             this.dc_date.Visible = true;
             this.dc_date.VisibleIndex = 9;
             this.dc_date.Width = 118;

+ 3 - 3
PLCDataReader/Main.cs

@@ -165,8 +165,8 @@ namespace UAS_PLCDataReader
             if (ButtonSaveDevice.LastSaveID != null && ButtonSaveDevice.LastSaveID.Length > 0)
             {
                 dh.BatchInsert(sql.ToString(), new string[] { "de_id" }, ButtonSaveDevice.LastSaveID);
-                GridDeviceList.RefreshData();
             }
+            GridDeviceList.RefreshData();
         }
 
         private void ComboxDeviceListWC_SelectedIndexChanged(object sender, EventArgs e)
@@ -291,8 +291,8 @@ namespace UAS_PLCDataReader
             if (ButtonSaveCommand.LastSaveID != null && ButtonSaveCommand.LastSaveID.Length > 0)
             {
                 dh.BatchInsert(sql.ToString(), new string[] { "dc_id" }, ButtonSaveCommand.LastSaveID);
-                GridCommandSetting.RefreshData();
             }
+            GridCommandSetting.RefreshData();
         }
 
         /// <summary>
@@ -528,8 +528,8 @@ namespace UAS_PLCDataReader
             if (ButtonSaveCommandSet.LastSaveID != null && ButtonSaveCommandSet.LastSaveID.Length > 0)
             {
                 dh.BatchInsert(sql.ToString(), new string[] { "dpc_id" }, ButtonSaveCommandSet.LastSaveID);
-                GridPollingSetting.RefreshData();
             }
+            GridPollingSetting.RefreshData();
         }
         /// <summary>
         /// 设置GridView多选放大镜

+ 11 - 12
PLCDataReader/PublicMethod/ModeBusTCPServer.cs

@@ -11,6 +11,8 @@ namespace UAS_PLCDataReader.PublicMethod
 {
     class ModeBusTCPServer
     {
+
+
         private bool isOpen = false;
 
         private bool receiveData;
@@ -106,8 +108,8 @@ namespace UAS_PLCDataReader.PublicMethod
                 IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
                 for (int i = 0; i < IpEntry.AddressList.Length; i++)
                 {
-                    if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork) {
-                        if(IpEntry.AddressList[i].ToString().Contains("192.168.127.20"))
+                    if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
+                    {
                         iP = IpEntry.AddressList[i].ToString();
                     }
                 }
@@ -121,7 +123,7 @@ namespace UAS_PLCDataReader.PublicMethod
                 socketWatch.Bind(endpoint);
                 //将套接字的监听队列长度限制为20
                 socketWatch.Listen(20);
-                Task.Factory.StartNew(WatchConnecting,TaskCreationOptions.LongRunning);
+                Task.Factory.StartNew(WatchConnecting, TaskCreationOptions.LongRunning);
                 ////创建一个监听线程 
                 //threadWatch = new Thread(WatchConnecting);
                 ////将窗体线程设置为与后台同步
@@ -142,6 +144,9 @@ namespace UAS_PLCDataReader.PublicMethod
         {
             if (!ReceiveCoding.ContainsKey(IPAddress))
                 ReceiveCoding.Add(IPAddress, receiveCoding);
+            //去除指令空格
+            Command = Command.Replace(" ", "");
+            byte[] arr = new byte[Command.Length / 2];
             foreach (Socket item in list)
             {
                 if (item != null)
@@ -166,17 +171,11 @@ namespace UAS_PLCDataReader.PublicMethod
                                     item.Send(Encoding.ASCII.GetBytes(str));
                                     break;
                                 case "Hexadecimal":
-                                    char[] values = Command.ToCharArray();
-                                    string strH = null;
-                                    foreach (char letter in values)
+                                    for (int i = 0; i < Command.Length / 2; i++)
                                     {
-                                        // Get the integral value of the character.
-                                        int value = Convert.ToInt32(letter);
-                                        // Convert the decimal value to a hexadecimal value in string form.
-                                        string hexOutput = String.Format("{0:X}", value);
-                                        strH += hexOutput + " ";
+                                        arr[i] = (byte)Convert.ToInt32(Command.Substring(i * 2, 2), 16);
                                     }
-                                    item.Send(Encoding.UTF8.GetBytes(strH));
+                                    item.Send(arr);
                                     break;
                             }
                         }