Beispiel #1
0
        public void Initialize()
        {
            try
            {
                if (uriString.StartsWith("opc.tcp"))
                {
                    if (opcClientOptions != null)
                    {
                        const string name    = "NowFuture";
                        var          options = new Hylasoft.Opc.Ua.UaClientOptions()
                        {
                            ApplicationName   = name,
                            ConfigSectionName = name,
                            SessionName       = name
                        };

                        if (!string.IsNullOrWhiteSpace(opcClientOptions.UserName) &&
                            !string.IsNullOrWhiteSpace(opcClientOptions.Password))
                        {
                            options.UserIdentity = new UserIdentity(opcClientOptions.UserName, opcClientOptions.Password);
                        }

                        client = new UaClient(new Uri(uriString), options);
                    }
                    else
                    {
                        client = new UaClient(new Uri(uriString));
                    }
                }

                if (uriString.StartsWith("opcda"))
                {
                    client = new DaClient(new Uri(uriString));
                }

                client.Connect();

                connectionStateChangedEventManager.OnConnectionStateChanged(ConnectionStateChanged, this, new ConnectionStateChangedEventArgs()
                {
                    IsConnected = true
                });
            }
            catch (Exception e)
            {
                throw new ApplicationException("建立与PLC连接失败,请确认", e);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a server object
 /// </summary>
 /// <param name="serverUrl">the url of the server to connect to</param>
 /// <param name="options">custom options to use with ua client</param>
 public UaClient(Uri serverUrl, UaClientOptions options)
 {
     _serverUrl = serverUrl;
     _options   = options;
     Status     = OpcStatus.NotConnected;
 }