Explicit Messaging: Write digital outputs to Ethernet/IP Device
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package explicitmessagingexample; import java.io.IOException; import de.re.eeip.cip.exception.CIPException; public class Main { public static void main(String[] args) throws InterruptedException, IOException, CIPException { de.re.eeip.EEIPClient eeipClient = new de.re.eeip.EEIPClient(); //Register Session (Wago-Device 750-352 IP-Address: 192.168.178.66) //we use the Standard Port for Ethernet/IP TCP-connections 0xAF12 eeipClient.RegisterSession("192.168.178.66"); //We write an Output to the Wago-Device; According to the Manual of the Device //Instance 0x66 of the Assembly Object contains the Digital Output data //The Documentation can be found at: http://www.wago.de/download.esm?file=%5Cdownload%5C00368362_0.pdf&name=m07500352_xxxxxxxx_0en.pdf while (true) { //We set the first output "High" eeipClient.getAssemblyObject().setInstance(0x66, new byte[] { 0x01 }); System.out.println("Set digital output #1 High"); Thread.sleep(5000); //We set the secoond output "High" eeipClient.getAssemblyObject().setInstance(0x66, new byte[] { 0x02 }); System.out.println("Set digital output #2 High"); Thread.sleep(5000); //We set the first and secoond output "High" eeipClient.getAssemblyObject().setInstance(0x66, new byte[] { 0x03 }); System.out.println("Set digital output #1 und #2 High"); Thread.sleep(5000); //We reset the outputs eeipClient.getAssemblyObject().setInstance(0x66, new byte[] { 0x00 }); } //When done, we unregister the session //eeipClient.UnRegisterSession(); } } |
Explicit Messaging: Read digital inputs from Ethernet/IP Device
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
package explicitmessagingexample2; import java.io.IOException; import de.re.eeip.cip.exception.CIPException; public class Main { public static void main(String[] args) throws IOException, CIPException { de.re.eeip.EEIPClient eeipClient = new de.re.eeip.EEIPClient(); //Register Session (Wago-Device 750-352 IP-Address: 192.168.178.66) //we use the Standard Port for Ethernet/IP TCP-connections 0xAF12 eeipClient.RegisterSession("192.168.178.66"); //Get the State of a digital Input According to the Manual //Instance 0x6C of the Assembly Object contains the Digital Input data //The Documentation can be found at: http://www.wago.de/download.esm?file=%5Cdownload%5C00368362_0.pdf&name=m07500352_xxxxxxxx_0en.pdf byte[] digitalInputs = eeipClient.getAssemblyObject().getInstance(0x6c); System.out.println("State of Digital Input 1: " + (de.re.eeip.EEIPClient.ToBool(digitalInputs[0], 0))); System.out.println("State of Digital Input 2: " + (de.re.eeip.EEIPClient.ToBool(digitalInputs[0], 1))); System.out.println("State of Digital Input 3: " + (de.re.eeip.EEIPClient.ToBool(digitalInputs[0], 2))); System.out.println("State of Digital Input 4: " + (de.re.eeip.EEIPClient.ToBool(digitalInputs[0], 3))); //When done, we unregister the session eeipClient.UnRegisterSession(); } } |
Explicit Messaging: Read Analog Inputs from Ethernet/IP Device
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
package explicitmessagingexampleanalog; import java.io.IOException; import de.re.eeip.cip.exception.CIPException; public class Main { public static void main(String[] args) throws IOException, CIPException { de.re.eeip.EEIPClient eeipClient = new de.re.eeip.EEIPClient(); //Register Session (Wago-Device 750-352 IP-Address: 192.168.178.66) //we use the Standard Port for Ethernet/IP TCP-connections 0xAF12 eeipClient.RegisterSession("192.168.178.66"); //Get the State of Analog Inputs According to the Manual //Instance 0x6D of the Assembly Object contains the Analog Input data //The Documentation can be found at: http://www.wago.de/download.esm?file=%5Cdownload%5C00368362_0.pdf&name=m07500352_xxxxxxxx_0en.pdf //Page 202 shows the documentation for instance 6D hex byte[] analogInputs = eeipClient.getAssemblyObject().getInstance(0x6D); System.out.println("Temperature of Analog Input 1: " + (de.re.eeip.EEIPClient.ToUshort(new byte[] { analogInputs[0], analogInputs[1] }) / 10.0) + "°C"); System.out.println("Temperature of Analog Input 2: " + (de.re.eeip.EEIPClient.ToUshort(new byte[] { analogInputs[2], analogInputs[3] }) / 10.0) + "°C"); //When done, we unregister the session eeipClient.UnRegisterSession(); } } |
Discover available Ethernet/IP Devices on the Network
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package discoverdevices; import java.util.List; public class Main { public static void main(String[] args) { de.re.eeip.EEIPClient eipClient = new de.re.eeip.EEIPClient(); List<de.re.eeip.encapsulation.CipIdentityItem> cipIdentityItem = eipClient.ListIdentity(); for (de.re.eeip.encapsulation.CipIdentityItem item : cipIdentityItem) { System.out.println("Ethernet/IP Device Found:"); System.out.println(item.ProductName1); System.out.println("IP-Address: " + de.re.eeip.encapsulation.CipIdentityItem.getIPAddress(item.SocketAddress.SIN_Address)); System.out.println("Port: " + item.SocketAddress.SIN_port); System.out.println("Vendor ID: " + item.VendorID1); System.out.println("Product-code: " + item.ProductCode1); System.out.println("Type-Code: " + item.ItemTypeCode); System.out.println("Serial Number: " + item.SerialNumber1); System.out.println(); } } } |
Implicit Messaging using Wago 750-352 Ethernet/IP Coupler
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import de.re.eeip.EEIPClient; import de.re.eeip.cip.datatypes.ConnectionType; import de.re.eeip.cip.datatypes.Priority; import de.re.eeip.cip.datatypes.RealTimeFormat; import de.re.eeip.cip.exception.CIPException; import java.io.Console; import java.io.IOException; import java.util.List; /** * This example shows the Implicit Messaging of a Wago 750-352 in Java * Hardware Configuration: * Coupler: 750-352 * Digital Input: 750-402 4-Channel * Digital Input: Beckhoff KL1012 2-Channel * Analog Input: Beckhoff KL3202 2-Channel * Digital Outout: 750-501 2-Channel * Termination: 750-600 * * Documentation: http://www.wago.de/download.esm?file=%5Cdownload%5C00368362_0.pdf&name=m07500352_xxxxxxxx_0en.pdf */ public class Main { public static void main(String[] args) throws InterruptedException { EEIPClient eipClient = new EEIPClient(); try { System.out.println("Fisrst Register a session"); eipClient.RegisterSession("192.168.1.3"); //Parameters for Originator -> Target communication eipClient.setO_T_InstanceID(101); //Output Assembly 65hex eipClient.setO_T_Length(1); eipClient.setO_T_RealTimeFormat(RealTimeFormat.Header32Bit); eipClient.setO_T_ownerRedundant(false); eipClient.setO_T_priority(Priority.Urgent); eipClient.setO_T_variableLength(false); eipClient.setO_T_connectionType(ConnectionType.Point_to_Point); //Parameters for Target -> Originator communication eipClient.setT_O_InstanceID(104); //Input Assembly 68hex eipClient.setT_O_Length(6); eipClient.setT_O_RealTimeFormat(RealTimeFormat.Modeless); eipClient.setT_O_ownerRedundant(false); eipClient.setT_O_priority(Priority.Urgent); eipClient.setT_O_variableLength(false); eipClient.setT_O_connectionType(ConnectionType.Multicast); eipClient.O_T_IOData[0] = 1; System.out.println("Send Forward open to initiate IO Messaging"); eipClient.ForwardOpen(); for (int i = 0; i < 50; i++) { System.out.println("Byte 0: "+eipClient.T_O_IOData[0]); System.out.println("Byte 1: "+eipClient.T_O_IOData[1]); System.out.println("Byte 2: "+eipClient.T_O_IOData[2]); System.out.println("Byte 3: "+eipClient.T_O_IOData[3]); System.out.println("Byte 4: "+eipClient.T_O_IOData[4]); System.out.println("Byte 5: "+eipClient.T_O_IOData[5]); Thread.sleep(500); } System.out.println("Send Forward Close"); eipClient.ForwardClose(); System.out.println("Unregister Session"); eipClient.UnRegisterSession(); } catch (IOException e) { e.printStackTrace(); } catch (CIPException e) { e.printStackTrace(); } } } |
Implicit Messaging using Allen-Bradley 1734-AENT Ethernet/IP Coupler
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import de.re.eeip.EEIPClient; import de.re.eeip.cip.datatypes.ConnectionType; import de.re.eeip.cip.datatypes.Priority; import de.re.eeip.cip.datatypes.RealTimeFormat; import de.re.eeip.cip.exception.CIPException; import java.io.IOException; /** * This example shows the Implicit Messaging of a Allen Bradley 1734-AENT Point I/O in Java * Hardware Configuration: * Coupler: 1734-AENT * Digital Input: 1734-IB4 4-Channel * Digital Input: 1734-IB4 4-Channel * Digital Input: 1734-IB4 4-Channel * Digital Input: 1734-IB4 4-Channel * Digital Output: 1734-OB4E 4-Channel * Digital Output: 1734-OB4E 4-Channel * Digital Output: 1734-OB4E 4-Channel * Digital Output: 1734-OB4E 4-Channel */ public class MainAllenBradley { public static void main(String[] args) throws InterruptedException { EEIPClient eipClient = new EEIPClient(); try { System.out.println("Fisrst Register a session"); eipClient.RegisterSession("192.168.1.3"); //Parameters for Originator -> Target communication eipClient.setO_T_InstanceID(100); //Output Assembly 64hex eipClient.setO_T_Length(4); eipClient.setO_T_RealTimeFormat(RealTimeFormat.Header32Bit); eipClient.setO_T_ownerRedundant(false); eipClient.setO_T_priority(Priority.Scheduled); eipClient.setO_T_variableLength(false); eipClient.setO_T_connectionType(ConnectionType.Point_to_Point); //Parameters for Target -> Originator communication eipClient.setT_O_InstanceID(101); //Input Assembly 65hex eipClient.setT_O_Length(16); eipClient.setT_O_RealTimeFormat(RealTimeFormat.Modeless); eipClient.setT_O_ownerRedundant(false); eipClient.setT_O_priority(Priority.Scheduled); eipClient.setT_O_variableLength(false); eipClient.setT_O_connectionType(ConnectionType.Point_to_Point); System.out.println("Send Forward open to initiate IO Messaging"); eipClient.ForwardOpen(); for (int i = 0; i < 50; i++) { eipClient.O_T_IOData[0] = (byte)(eipClient.O_T_IOData[0]+1); eipClient.O_T_IOData[1] = (byte)(eipClient.O_T_IOData[1]+1); eipClient.O_T_IOData[2] = (byte)(eipClient.O_T_IOData[2]+1); eipClient.O_T_IOData[3] = (byte)(eipClient.O_T_IOData[3]+1); System.out.println("Input Module 1: "+eipClient.T_O_IOData[8]); System.out.println("Input Module 2: "+eipClient.T_O_IOData[9]); System.out.println("Input Module 3: "+eipClient.T_O_IOData[10]); System.out.println("Input Module 4: "+eipClient.T_O_IOData[11]); Thread.sleep(500); } System.out.println("Send Forward Close"); eipClient.ForwardClose(); System.out.println("Unregister Session"); eipClient.UnRegisterSession(); } catch (IOException e) { e.printStackTrace(); } catch (CIPException e) { e.printStackTrace(); } } } |