Asynchronous, non-blocking, EtherNet/IP client implementation for Java
<dependency>
<groupId>com.digitalpetri.enip</groupId>
<artifactId>enip-client</artifactId>
<version>1.1.2</version>
</dependency>
EtherNetIpClientConfig config = EtherNetIpClientConfig.builder("10.20.4.57")
.setSerialNumber(0x00)
.setVendorId(0x00)
.setTimeout(Duration.ofSeconds(2))
.build();
EtherNetIpClient client = new EtherNetIpClient(config);
client.connect().get();
client.listIdentity().whenComplete((li, ex) -> {
if (li != null) {
li.getIdentity().ifPresent(id -> {
System.out.println("productName=" + id.getProductName());
System.out.println("revisionMajor=" + id.getRevisionMajor());
System.out.println("revisionMinor=" + id.getRevisionMinor());
});
} else {
ex.printStackTrace();
}
});
EtherNetIpClientConfig config = EtherNetIpClientConfig.builder("10.20.4.57")
.setSerialNumber(0x00)
.setVendorId(0x00)
.setTimeout(Duration.ofSeconds(2))
.build();
// backplane, slot 0
PaddedEPath connectionPath = new PaddedEPath(
new PortSegment(1, new byte[]{(byte) 0}));
CipClient client = new CipClient(config, connectionPath);
client.connect().get();
GetAttributeListService service = new GetAttributeListService(
new PaddedEPath(new ClassId(0x01), new InstanceId(0x01)),
new int[]{4},
new int[]{2}
);
client.invokeUnconnected(service).whenComplete((as, ex) -> {
if (as != null) {
try {
ByteBuf data = as[0].getData();
int major = data.readUnsignedByte();
int minor = data.readUnsignedByte();
System.out.println(String.format("firmware v%s.%s", major, minor));
} catch (Throwable t) {
t.printStackTrace();
} finally {
Arrays.stream(as).forEach(a -> ReferenceCountUtil.release(a.getData()));
}
} else {
ex.printStackTrace();
}
});
See the logix-services README!
Apache License, Version 2.0