Giter Site home page Giter Site logo

ethernet-ip's Introduction

EtherNet/IP Client

Build status Maven Central

Asynchronous, non-blocking, EtherNet/IP client implementation for Java

Maven

<dependency>
    <groupId>com.digitalpetri.enip</groupId>
    <artifactId>enip-client</artifactId>
    <version>1.2.0</version>
</dependency>

Quick Start

EtherNet/IP Example

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();
    }
});

CIP Service Example

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();
    }
});

Logix Example

See the logix-services README!

License

Apache License, Version 2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.