Sfoglia il codice sorgente

Merge branch 'master' of ssh://10.10.100.21/source/mes-client

Hcsy 7 anni fa
parent
commit
fba1e006d4
2 ha cambiato i file con 11 aggiunte e 10 eliminazioni
  1. 8 9
      PLCDataReader/Main.cs
  2. 3 1
      PLCDataReader/PublicMethod/ModBusTCPClient.cs

+ 8 - 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,15 +521,16 @@ 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;
             timer.Polling = i;
             timer.Interval = pl.Interval * 1000;
             timer.Elapsed += Timer_Tick;
+            GC.KeepAlive(timer);
             timer.Start();
             try
             {
@@ -545,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;

+ 3 - 1
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,6 +136,7 @@ namespace UAS_PLCDataReader.PublicMethod
                 {
                     socket.Close();
                     socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                    socket.ReceiveTimeout = 2000;
                     socket.Connect(serverFullAddr);
                     ResetCount = 0;
                 }
@@ -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 * 100];
+                byte[] receive = new byte[1024 * 10];
                 LogicHandler.UpdateDeviceStatus(decode, dename, "设备运行准备获取数据", DeviceStatus.Noanswer, 0);
                 LogicHandler.DoDevicePollingLog(decode, true);
                 int length = socket.Receive(receive);