Beckhoff / TF6000_ADS_DOTNET_V5_Samples

Sample code for the Version 6.X series of the TwinCAT ADS .NET Packages
https://infosys.beckhoff.com/content/1033/tc3_ads.net/9407515403.html?id=6770980177009971601
BSD Zero Clause License
37 stars 15 forks source link

WhenNotification returns default values #17

Closed drvic10k closed 2 years ago

drvic10k commented 2 years ago

When trying to get the data as an IObservable using this extension, the struct that is returned has all properties with default values

public static IObservable<SymbolValueNotification> WhenNotification(
      this IAdsConnection client,
      ISymbol symbol,
      NotificationSettings settings)
RalfHeitmann commented 2 years ago

Unfortunately I couldn't reproduce the issue. With the following code everything works as expected.

TYPE DUT :
STRUCT
    i1 : INT;
    i2 : INT;
END_STRUCT
END_TYPE
PROGRAM MAIN
VAR
    dut : DUT;
END_VAR

dut.i1 := dut.i1 + 1;
dut.i2 := dut.i1 + 1;
using System;
using TwinCAT;
using TwinCAT.Ads;
using TwinCAT.Ads.Reactive;
using TwinCAT.Ads.TypeSystem;
using TwinCAT.TypeSystem;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            using (AdsClient client = new AdsClient())
            {
                client.Connect(851);

                ISymbolLoader loader = SymbolLoaderFactory.Create(client, SymbolLoaderSettings.DefaultDynamic);
                IValueSymbol dutSymbol = (IValueSymbol)loader.Symbols["MAIN.dut"];

                dynamic val1 = dutSymbol.ReadValue();
                var observable = client.WhenNotification(dutSymbol, NotificationSettings.Default);

                observable.Subscribe(n =>
                {
                    dynamic valNot = n.Value;
                    Console.WriteLine(valNot.i1);
                });

                Console.ReadLine();
            }
        }
    }
}

Please provide us with more detailed information.

drvic10k commented 2 years ago

I see that you are using the port 851, which is probably a real server, I am using the AdsSymbolicServer

it seems to be similar to this issue: https://github.com/Beckhoff/TF6000_ADS_DOTNET_V5_Samples/issues/14

RalfHeitmann commented 2 years ago

Sorry, I thought it could be a bug in the WhenNotification Observer. I can confirm an issue that doesn't read the correct symbol value in the AdsSymbolicServer when Notifications are fired (Values remain the Default Value). A new version of the packages and sample code is coming soon ...