Преглед на файлове

修改欧姆龙PLC 类名

ltwork преди 1 година
родител
ревизия
a28eb61451

+ 3 - 3
BlankApp1/BlankApp1/App.config

@@ -4,9 +4,9 @@
 		<!--连接字符串 SQL Server-->
 		<add key="MySql" value="Data Source=localhost;Database=plc_point_db2;User Id='root';Password='521125';port=3306;charset=utf8mb4;"/>
 	    <!--1表示欧姆龙PLC,2表示为三菱PLC-->
-		<add key="PLCType" value="2"/>
-		<add key="PLCIp" value="127.0.0.1"/>
-		<add key="PLCPort" value="6000"/>
+		<add key="PLCType" value="1"/>
+		<add key="PLCIp" value="192.168.250.1"/>
+		<add key="PLCPort" value="9600"/>
 		<add key="DelayTime" value="20"/>
 		<add key="LongDelayTime" value="60"/>
 	

+ 9 - 11
BlankApp1/BlankApp1/Common/PLCCom.cs → BlankApp1/BlankApp1/Common/FinsPLCConnection.cs

@@ -12,27 +12,27 @@ using TFT_MelsecMcNet;
 
 namespace PLCTool.Common
 {
-    public class PLCCom:IPLCConnection
+    public class FinsPLCConnection: IPLCConnection
     {
         private static string plcIp = ConfigurationManager.AppSettings["PLCIp"];
         private static string plcPort = ConfigurationManager.AppSettings["PLCPort"];
         private static  EtherNetPLC ENT = new EtherNetPLC();
-        private static PLCCom instance;
+        private static FinsPLCConnection instance;
         private static bool isConnect=false;
        
 
-        private PLCCom() 
+        private FinsPLCConnection() 
         {
             ConnectPLC();
         }
 
-        public static PLCCom Instance
+        public static FinsPLCConnection Instance
         {
             get
             {
                 if ((!ENT.IsConnect))
                 {
-                    instance = new PLCCom();
+                    instance = new FinsPLCConnection();
                 }
                 return instance;
             }
@@ -67,13 +67,11 @@ namespace PLCTool.Common
         {
             try
             {
-                short re = -1;
-                await Task.Run(() =>
-                {
-                    re = ENT.Link(plcIp, short.Parse(plcPort), 500);
-                });
+                var result=await Task.Run(() =>
+                     ENT.Link(plcIp, short.Parse(plcPort), 500)
+                );
           
-                if (re == 0)
+                if (result == 0)
                 {
                     isConnect = true;
                     return true;

+ 11 - 14
BlankApp1/BlankApp1/Common/MelsecPLCConnectioncs.cs

@@ -46,21 +46,18 @@ namespace PLCTool.Common
 
                     melsec_net.ConnectServer()
                 // 耗时操作
-                ) ; 
-              
-              
-                
-                    if (result.IsSuccess)
-                    {
-                        isConnect = true;
-                        return true;
-                    }
-                    else
-                    {
+                ) ;
+                if (result.IsSuccess)
+                {
+                    isConnect = true;
+                    return true;
+                }
+                else
+                {
 
-                        isConnect = false;
-                        return false;
-                    }
+                    isConnect = false;
+                    return false;
+                }
                 
                 
 

+ 1 - 1
BlankApp1/BlankApp1/Common/PLCConnectionFactory.cs

@@ -15,7 +15,7 @@ namespace PLCTool.Common
             switch (plcType)
             {
                 case "1":
-                    return PLCCom.Instance;
+                    return FinsPLCConnection.Instance;
                 case "2":
                     return MelsecPLCConnectioncs.Instance;
                 default: