Ejemplo n.º 1
0
        public int Run()
        {
            Log = "";

            plctag.ForceExtractLibrary = false;

            var myLogger = new plctag.log_callback_func(logger);
            var statusAfterLoggerRegistration = plctag.plc_tag_register_logger(myLogger);

            plctag.plc_tag_set_debug_level(2);

            var tagHandle = plctag.plc_tag_create("protocol=ab_eip&gateway=192.168.0.10&path=1,0&plc=LGX&elem_size=4&elem_count=1&name=MY_DINT", 1000);

            while (plctag.plc_tag_status(tagHandle) == 1)
            {
                Thread.Sleep(100);
            }
            var statusBeforeRead = plctag.plc_tag_status(tagHandle);

            if (statusBeforeRead != 0)
            {
                AddToLog($"Something went wrong {statusBeforeRead}");
            }


            var myEventCallback         = new plctag.callback_func(eventCallback);
            var statusAfterRegistration = plctag.plc_tag_register_callback(tagHandle, myEventCallback);

            if (statusAfterRegistration != 0)
            {
                AddToLog($"Something went wrong {statusAfterRegistration}");
            }

            plctag.plc_tag_read(tagHandle, 1000);
            while (plctag.plc_tag_status(tagHandle) == 1)
            {
                Thread.Sleep(100);
            }
            var statusAfterRead = plctag.plc_tag_status(tagHandle);

            if (statusAfterRead != 0)
            {
                AddToLog($"Something went wrong {statusAfterRead}");
            }

            var value = (int)plctag.plc_tag_get_uint32(tagHandle, 0);

            // Problem occurs here
            var destroyResult = plctag.plc_tag_destroy(tagHandle);

            return(value);
        }
        public static void RunCallbackExample()
        {
            var tagHandle = plctag.plc_tag_create("protocol=ab_eip&gateway=192.168.0.10&path=1,0&plc=LGX&elem_size=4&elem_count=1&name=MY_DINT", 1000);

            while (plctag.plc_tag_status(tagHandle) == 1)
            {
                Thread.Sleep(100);
            }
            var statusBeforeRead = plctag.plc_tag_status(tagHandle);

            if (statusBeforeRead != 0)
            {
                Console.WriteLine($"Something went wrong {statusBeforeRead}");
            }

            var myCallback = new plctag.callback_func(MyCallback);
            var statusAfterRegistration = plctag.plc_tag_register_callback(tagHandle, myCallback);

            if (statusAfterRegistration != 0)
            {
                Console.WriteLine($"Something went wrong {statusAfterRegistration}");
            }

            plctag.plc_tag_read(tagHandle, 1000);
            while (plctag.plc_tag_status(tagHandle) == 1)
            {
                Thread.Sleep(100);
            }
            var statusAfterRead = plctag.plc_tag_status(tagHandle);

            if (statusAfterRead != 0)
            {
                Console.WriteLine($"Something went wrong {statusAfterRead}");
            }

            var theValue = plctag.plc_tag_get_uint32(tagHandle, 0);

            plctag.plc_tag_destroy(tagHandle);

            Console.WriteLine(theValue);
        }
Ejemplo n.º 3
0
 public static extern int plc_tag_register_callback(Int32 tag_id, plctag.callback_func func);