libplctag / libplctag.NET

A .NET wrapper for libplctag.
https://libplctag.github.io/
Mozilla Public License 2.0
197 stars 49 forks source link

Try Notification value changed #323

Closed patopat closed 1 year ago

patopat commented 1 year ago

Hi,

From the project "Examples", I modified a little bit the ExampleNotifyChanged.cs" to add print debug details. I have nothing in the console window except the "test started...". When I do a read Tag, I have a lot of message in the console and the value is read correctly.


        static private NotifyValueChangedTag<DintPlcMapper, int> myDINT;

        public static void Run()
        {
            LibPlcTag.LogEvent += LibPlcTag_LogEvent;
            LibPlcTag.DebugLevel = DebugLevel.Detail;

            myDINT = new()
            {
                Name = "TestEvent",
                Gateway = "192.168.1.1",
                Path = "1,0",
                PlcType = PlcType.ControlLogix,
                Protocol = Protocol.ab_eip,
                AutoSyncReadInterval = TimeSpan.FromMilliseconds(500)
            };
            Console.WriteLine("test started...");
            myDINT.ValueChanged += (s, e) => Console.WriteLine($"{myDINT.Name} changed at {DateTime.Now} to {myDINT.Value}");

        }

        private static void LibPlcTag_LogEvent(object sender, LogEventArgs e)
        {
            Console.WriteLine($"{e.DebugLevel}\t\t{e.Message}");
        }

Do you know if I need to configure anything in the PLC program for notification or any idea why no event occurs ?

Regards, Pat

patopat commented 1 year ago

Fixed by calling the initialize method.