1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using ConnectionUtil;
using OPCConnection;
 
namespace Plugin.CurrentSensorControl.Entity
{
    public class OPCContext
    {
        private static Dictionary<string, SCADAApi> cache = new Dictionary<string, SCADAApi>();
        private static string opcIP = "127.0.0.1";
        private static int opcPort = 6543;
        private static int localPort = 18888;
 
        public static SCADAApi Get(string name)
        {
            if (!cache.ContainsKey(name))
            {
                var client = new OPCClient();
                if (!client.Connect2(opcIP, opcPort, localPort, out string errMsg))
                {
 
                }
                else
                {
 
                }
                cache[name] = client;
            }
            return cache[name];
        }
 
        public static bool Connect(string name)
        {
            if (cache.ContainsKey(name))
            {
                return cache[name].Connect2(opcIP, opcPort, localPort, out string errMsg) == true;
            }
            return false;
        }
    }
}