public void Test_Enumerate_Hosts()
        {
            var enumerator = new OpcServerEnumeratorAuto();
            var hosts      = enumerator.EnumrateHosts();

            hosts.Should().Contain(enumerator.Localhost);
        }
Beispiel #2
0
        /// <summary>
        /// Connects the server instance to COM server.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Already connected to the OPC DA server.</exception>
        public void Connect()
        {
            if (IsConnected)
            {
                throw new InvalidOperationException("Already connected to the OPC DA server.");
            }

            Log.TraceFormat("Connecting to '{0}' opc server", Uri);

            var enumerator = new OpcServerEnumeratorAuto();
            Tuple <string, Guid> hostAndCLSID = UrlParser.Parse(
                Uri,
                (host, progId) => new Tuple <string, Guid>(host, enumerator.CLSIDFromProgId(progId, host)),
                (host, clsid) => new Tuple <string, Guid>(host, clsid));

            ComObject = Com.CreateInstanceWithBlanket(hostAndCLSID.Item2, hostAndCLSID.Item1, null, ComProxyBlanket);
            _shutdownConnectionPoint.TryConnect(ComObject);

            Log.TraceFormat("Connected to '{0}' opc server.", Uri);
            try
            {
                ClientName = _clientName;
            }
            catch (Exception ex)
            {
                Log.Warn("Cannot setup name of client.", ex);
            }
            OnConnectionStateChanged(true);
        }
        public void Test_Enumerate_OpcDa_Servers()
        {
            var enumerator         = new OpcServerEnumeratorAuto();
            var serverDescriptions = enumerator.Enumerate("", OpcServerCategory.OpcDaServers);

            serverDescriptions.Should().ContainSingle(s => s.ProgId == "Matrikon.OPC.Simulation.1");
            serverDescriptions.Should().ContainSingle(s => s.Uri.Segments[1] == "Matrikon.OPC.Simulation.1");
        }