using ConnectionUtil; using OPCConnection; namespace Plugin.CurrentSensorControl.Entity { public class OPCContext { private static Dictionary cache = new Dictionary(); 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; } } }