Quellcode durchsuchen

添加自动控制延时

ltwork vor 1 Jahr
Ursprung
Commit
aeac4a7322

+ 1 - 1
BlankApp1/BlankApp1/App.config

@@ -6,7 +6,7 @@
 	    <!--1表示欧姆龙PLC,2表示为三菱PLC-->
 		<add key="PLCType" value="2"/>
 		<add key="PLCIp" value="192.168.3.39"/>
-		<add key="PLCPort" value="3000"/>
+		<add key="PLCPort" value="6000"/>
 		<add key="DelayTime" value="20"/>
 		<add key="LongDelayTime" value="60"/>
 	

+ 31 - 4
BlankApp1/BlankApp1/Common/MelsecPLCConnectioncs.cs

@@ -1,8 +1,11 @@
-using OmronFinsTCP.Net;
+using HandyControl.Collections;
+using OmronFinsTCP.Net;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Configuration;
 using System.Linq;
+using System.Net;
 using System.Text;
 using System.Threading.Tasks;
 using TFT_MelsecMcNet;
@@ -36,8 +39,13 @@ namespace PLCTool.Common
             try
             {
                 melsec_net = new MelsecMcNet(plcIp, Convert.ToInt32(plcPort));
-                OperateResult connect = melsec_net.ConnectServer();
-                if (connect.IsSuccess)
+                Func<OperateResult> func = (() =>
+                {
+                    return  melsec_net.ConnectServer();
+                });
+                var connect = Task.Run(() => func.Invoke());
+             
+                if (connect.Result.IsSuccess)
                 {
                     isConnect = true;
                     return true;
@@ -57,9 +65,28 @@ namespace PLCTool.Common
             }
         }
 
+      
         public bool IsConnectPLC()
         {
-            return melsec_net.IsConnect();
+            short rb;
+            short reSuc = -1;
+            Func<OperateResult<bool>> func = () =>
+            {
+                return melsec_net.ReadBool("X100");
+            };
+            var workTask = Task.Run(() => func.Invoke());
+
+
+            //读取成功
+            if (workTask.Result.IsSuccess)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+           
         }
 
         public string ReadPlcObject(string address, VarType valueType)

+ 5 - 5
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/AutoTestViewModel.cs

@@ -713,7 +713,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
             }
             //输入项
-            bool isAction = TestActionMethod();
+            bool isAction = await TestActionMethod();
             
             //输出项
             bool isJudgeResult = await TestJudgementMethod();
@@ -877,7 +877,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <summary>
         /// 输入项写入
         /// </summary>
-        private bool TestActionMethod()
+        private async Task<bool> TestActionMethod()
         {
             bool isActionResult = true;
             switch (SelectInJudge)
@@ -919,7 +919,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         case "AND":
                         case "ONLY":
                         case "OR":
-                            isActionResult = SendActionToPLC(InSelectLogic);
+                            isActionResult =await SendActionToPLC(InSelectLogic);
                             break;
 
                         case "ORDER":
@@ -933,7 +933,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <summary>
         /// 发送命令给PLC
         /// </summary>
-        private bool SendActionToPLC(string strActionLogic)
+        private async Task<bool> SendActionToPLC(string strActionLogic)
         {
             bool isAction = true;
             int countCond = 0;
@@ -996,7 +996,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         break;
 
                 }
-
+                await Task.Delay(500);
             }
             if (!isAction)
             {