public ImplicitMessaging(TreeView devicetreeView)
        {
            InitializeComponent();

            ClassView.ImageList = devicetreeView.ImageList;

            TreeNode baseNode = devicetreeView.SelectedNode;

            while (baseNode.Parent != null)
            {
                baseNode = baseNode.Parent;
            }

            device = (EnIPRemoteDevice)baseNode.Tag;

            foreach (TreeNode t in baseNode.Nodes)
            {
                ClassView.Nodes.Add((TreeNode)t.Clone());
            }

            ClassView.ExpandAll();

            ClassView.ItemDrag += new ItemDragEventHandler(ClassView_ItemDrag);

            this.Text = "Implicit Messaging with " + baseNode.Text;

            try
            {
                IPEndPoint LocalEp = new IPEndPoint(IPAddress.Parse(Properties.Settings.Default.DefaultIPInterface), 0x8AE);
                // It's not a problem to do this with more than one remote device,
                // the underlying udp socket is static
                device.Class1Activate(LocalEp);
            }
            catch { }
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting");

            IPEndPoint       ep      = new IPEndPoint(IPAddress.Parse("172.20.54.58"), 0xAF12);
            EnIPRemoteDevice WagoPlc = new EnIPRemoteDevice(ep);

            WagoPlc.autoConnect         = true;
            WagoPlc.autoRegisterSession = true;

            // class 4, instance 107, attribut 3 : Input Data
            EnIPClass    Class4      = new EnIPClass(WagoPlc, 4);
            EnIPInstance Instance107 = new EnIPInstance(Class4, 107);
            EnIPAttribut Inputs      = new EnIPAttribut(Instance107, 3);

            // Read require, it provides the data size in the RawData field
            // If not, one have to make a new on it with the good size before
            // calling ForwardOpen : Inputs.RawData=new byte[xx]
            Inputs.ReadDataFromNetwork();

            // Open an Udp endpoint, server mode is mandatory : default port 0x8AE
            // Local IP should be given if more than 1 ethernet/wifi interface is present
            IPEndPoint LocalEp = new IPEndPoint(IPAddress.Parse(""), 0x8AE);

            // It's not a problem to do this with more than one remote device,
            // the underlying udp socket is static
            WagoPlc.Class1Activate(LocalEp);
            // Not required in P2P mode
            WagoPlc.Class1AddMulticast("239.192.72.32");

            // Attach concerned attributs to the UDP callback handler : here just one
            Inputs.Class1Enrolment();

            // Register me to get notified
            Inputs.T2OEvent += new T2OEventHandler(Inputs_T2OEvent);

            // ForwardOpen in Multicast, T2O, cycle 200 ms, duration infinite (-1)
            Inputs.ForwardOpen(false, true, false, 200, -1);

            Console.WriteLine("Running, hit a key to stop");

            Console.ReadKey();

            Inputs.ForwardClose();
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting");

            IPEndPoint       ep     = new IPEndPoint(IPAddress.Parse("100.75.137.27"), 0xAF12);
            EnIPRemoteDevice OpENer = new EnIPRemoteDevice(ep);

            OpENer.autoConnect         = true;
            OpENer.autoRegisterSession = true;

            // class 4, instance 151, attribut 3 : Config Data
            EnIPClass    Class4      = new EnIPClass(OpENer, 4);
            EnIPInstance Instance151 = new EnIPInstance(Class4, 151);
            EnIPAttribut Config      = new EnIPAttribut(Instance151, 3);

            // class 4, instance 150, attribut 3 : Output Data
            EnIPInstance Instance150 = new EnIPInstance(Class4, 150);
            EnIPAttribut Outputs     = new EnIPAttribut(Instance150, 3);

            // class 4, instance 100, attribut 3 : Input Data
            EnIPInstance Instance100 = new EnIPInstance(Class4, 100);
            EnIPAttribut Inputs      = new EnIPAttribut(Instance100, 3);

            // Read require, it provides the data size in the RawData field
            // If not, one have to make a new on it with the good size before
            // calling ForwardOpen : Inputs.RawData=new byte[xx]
            Config.ReadDataFromNetwork();
            Inputs.ReadDataFromNetwork();
            Outputs.ReadDataFromNetwork();

            IPEndPoint LocalEp = new IPEndPoint(IPAddress.Any, 0x8AE);

            // It's not a problem to do this with more than one remote device,
            // the underlying udp socket is static
            OpENer.Class1Activate(LocalEp);

            // ForwardOpen in P2P, cycle 200 ms
            ForwardOpen_Config conf = new ForwardOpen_Config(Outputs, Inputs, true, 200 * 1000);
            // here can change conf for exemple to set Exclusive use, change priority or CycleTime not equal in the both direction

            // Attributes order cannot be changed, last optional attribute true
            // will write the config value Config.RawData (modifies it after ReadDataFromNetwork before this call)
            ForwardClose_Packet CloseData;
            EnIPNetworkStatus   result = OpENer.ForwardOpen(Config, Outputs, Inputs, out CloseData, conf, false);

            if (result == EnIPNetworkStatus.OnLine)
            {
                // Register Inputs events to get notified
                Inputs.T2OEvent += new T2OEventHandler(Inputs_T2OEvent);

                Console.WriteLine("Running, hit a key to stop");
                while (!Console.KeyAvailable)
                {
                    Outputs.RawData[0] = (byte)(Outputs.RawData[0] + 1);
                    Outputs.Class1UpdateO2T(); // must be called even if no data changed to maintain the link (Heartbeat)
                    Thread.Sleep(200);
                }
                OpENer.ForwardClose(CloseData);
            }
            else
            {
                Console.WriteLine("Fail");
            }
        }