Exemplo n.º 1
0
        public void Initialize()
        {
            Observable.FromEventPattern <ConnectionStateChangedEventArgs>(ev => Client.ConnectionStateChanged += ev,
                                                                          ev => Client.ConnectionStateChanged -= ev)
            .Select(pattern => pattern.EventArgs.NewState)
            .Subscribe(connectionStateSubject.OnNext)
            .AddDisposableTo(disposables);

            connectionStateSubject
            .DistinctUntilChanged()
            .Where(state => state == TwinCAT.ConnectionState.Connected)
            .Do(UpdateSymbols)
            .Subscribe()
            .AddDisposableTo(disposables);

            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());

            var localhost = host
                            .AddressList
                            .FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);

            AmsNetIds = DeviceFinder.BroadcastSearchAsync(localhost).Result.Select(x => new NetId {
                Name = x.Name, Address = x.AmsNetId.ToString()
            }).ToList();
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            Observable.FromEventPattern <ConnectionStateChangedEventArgs>(ev => Client.ConnectionStateChanged += ev,
                                                                          ev => Client.ConnectionStateChanged -= ev)
            .Select(pattern => pattern.EventArgs.NewState)
            .Subscribe(connectionStateSubject.OnNext)
            .AddDisposableTo(disposables);

            connectionStateSubject
            .DistinctUntilChanged()
            .Where(state => state == TwinCAT.ConnectionState.Connected)
            .Do(UpdateSymbols)
            .Subscribe()
            .AddDisposableTo(disposables);

            Observable.Interval(TimeSpan.FromSeconds(1))
            .Do(_ => CheckConnectionHealth())
            .Subscribe()
            .AddDisposableTo(disposables);

            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());

            var localhost = host
                            .AddressList
                            .FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);

            Observable.Return(Unit.Default)
            .SelectMany(_ => DeviceFinder.BroadcastSearchAsync(localhost))
            .Select(x => x.Select(d => new NetId {
                Name = d.Name, Address = d.AmsNetId.ToString()
            }))
            .Subscribe(foundNetIdSubject.OnNext)
            .AddDisposableTo(disposables)
            ;
        }