瀏覽代碼

BUG调整

章政 7 年之前
父節點
當前提交
2837a355ce
共有 2 個文件被更改,包括 11 次插入11 次删除
  1. 7 9
      PLCDataReader/Main.cs
  2. 4 2
      PLCDataReader/PublicMethod/ModBusTCPClient.cs

+ 7 - 9
PLCDataReader/Main.cs

@@ -25,7 +25,7 @@ namespace UAS_PLCDataReader
         StringBuilder DeviceStatusQuerySQL = new StringBuilder();
         //用于设备主档资料查询界面SQL查看
         StringBuilder DeviceListQuerySQL = new StringBuilder();
-        DataHelper dh = SystemInf.dh;
+        static DataHelper dh = SystemInf.dh;
         List<string> SQL = new List<string>();
 
         DataHelper updatedh = new DataHelper();
@@ -225,8 +225,6 @@ namespace UAS_PLCDataReader
             TimerUpdateDevice.Start();
             TimerUpdateSQL.Start();
 
-            Ptime = new Dictionary<int, PollingTimer>();
-
             //ButtonPollingSetting.PerformClick();
             //ButtonStartPolling.PerformClick();
         }
@@ -523,9 +521,9 @@ namespace UAS_PLCDataReader
             }
         }
 
-        Dictionary<int, PollingTimer> Ptime;
+        static Dictionary<int, PollingTimer> Ptime = new Dictionary<int, PollingTimer>();
 
-        private void RunTask(object i)
+        static private void RunTask(object i)
         {
             PollingTimer timer = new PollingTimer();
             Polling pl = (Polling)i;
@@ -546,16 +544,16 @@ namespace UAS_PLCDataReader
             }
         }
 
-        DataTable DNC;
-        DataTable DC;
+        static DataTable DNC;
+        static DataTable DC;
 
-        Dictionary<string, ModBusTCPClient> client = new Dictionary<string, ModBusTCPClient>();
+        static Dictionary<string, ModBusTCPClient> client = new Dictionary<string, ModBusTCPClient>();
         /// <summary>
         /// 轮询执行的业务
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
-        private void Timer_Tick(object sender, EventArgs e)
+        static private void Timer_Tick(object sender, EventArgs e)
         {
             PollingTimer timer = (PollingTimer)sender;
             Polling pl = (Polling)timer.Polling;

+ 4 - 2
PLCDataReader/PublicMethod/ModBusTCPClient.cs

@@ -116,6 +116,7 @@ namespace UAS_PLCDataReader.PublicMethod
                 dename = Dename;
                 socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                 serverFullAddr = new IPEndPoint(IPAddress.Parse(IP), int.Parse(Port));//设置IP,端口
+                socket.ReceiveTimeout = 2000;
                 socket.Connect(serverFullAddr);
             }
             catch (Exception ex)
@@ -135,9 +136,10 @@ namespace UAS_PLCDataReader.PublicMethod
                 {
                     socket.Close();
                     socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                    socket.ReceiveTimeout = 2000;
                     socket.Connect(serverFullAddr);
                     ResetCount = 0;
-                }   
+                }
                 Command = Command.Replace(" ", "");
                 byte[] arr = new byte[Command.Length / 2];
                 for (int i = 0; i < Command.Length / 2; i++)
@@ -145,7 +147,7 @@ namespace UAS_PLCDataReader.PublicMethod
                     arr[i] = (byte)Convert.ToInt32(Command.Substring(i * 2, 2), 16);
                 }
                 socket.Send(arr);
-                byte[] receive = new byte[1024*10];
+                byte[] receive = new byte[1024 * 10];
                 LogicHandler.UpdateDeviceStatus(decode, dename, "设备运行准备获取数据", DeviceStatus.Noanswer, 0);
                 LogicHandler.DoDevicePollingLog(decode, true);
                 int length = socket.Receive(receive);