private void buttonFw_Click(object sender, EventArgs e) { if (!checkP2P.Checked) // multicast mode, get first @ by device query { if (MCastAddress == null) { GetMultiCastAdress(); if (MCastAddress != null) { device.Class1AddMulticast(MCastAddress); // I will be possible to Join the 32 consecutives @ to be sure } } } if (FwclosePacket == null) { // CycleTime in microseconds EnIPNetworkStatus result = device.ForwardOpen(Config, Output, Input, out FwclosePacket, (uint)(CycleTime.Value * 1000), checkP2P.Checked, checkWriteConfig.Checked); if (result == EnIPNetworkStatus.OnLine) { buttonFw.Text = "Forward Close"; tmrO2T.Interval = (int)CycleTime.Value; // here in ms it's a Windows timer tmrO2T.Enabled = true; if (Input != null) { Input.T2OEvent += new T2OEventHandler(Input_T2OEvent); } } else { FwclosePacket = null; } } else { tmrO2T.Enabled = false; device.ForwardClose(FwclosePacket); buttonFw.Text = "(Large)Forward Open"; FwclosePacket = null; if (Input != null) { Input.T2OEvent -= new T2OEventHandler(Input_T2OEvent); } ImgInputActivity.Visible = false; } }
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(); }