or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

browse-operations.mdconnection-management.mdexception-handling.mdindex.mdread-operations.mdsubscription-system.mdvalue-system.mdwrite-operations.md
tile.json

tessl/maven-org-apache-plc4x--plc4j-api

Central API Module providing core interfaces and abstractions for unified access to industrial programmable logic controllers (PLCs)

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.plc4x/plc4j-api@0.13.x

To install, run

npx @tessl/cli install tessl/maven-org-apache-plc4x--plc4j-api@0.13.0

index.mddocs/

Apache PLC4X Java API

Apache PLC4X Java API provides a unified, protocol-agnostic interface for communicating with industrial programmable logic controllers (PLCs). It abstracts the complexity of industrial communication protocols, enabling developers to build applications that can communicate with various PLC systems using a consistent programming interface.

Package Information

  • Package Name: org.apache.plc4x:plc4j-api
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>org.apache.plc4x</groupId>
      <artifactId>plc4j-api</artifactId>
      <version>0.13.1</version>
    </dependency>

Core Imports

import org.apache.plc4x.java.DefaultPlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.PlcDriverManager;
import org.apache.plc4x.java.api.PlcConnectionManager;
import org.apache.plc4x.java.api.messages.*;
import org.apache.plc4x.java.api.value.PlcValue;
import org.apache.plc4x.java.api.types.PlcResponseCode;

Basic Usage

import org.apache.plc4x.java.DefaultPlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcReadResponse;

// Create connection manager
PlcDriverManager driverManager = new DefaultPlcDriverManager();
PlcConnectionManager connectionManager = driverManager.getConnectionManager();

// Connect to PLC
try (PlcConnection connection = connectionManager.getConnection("modbus-tcp://192.168.1.100:502")) {
    connection.connect();
    
    // Create and execute read request
    PlcReadRequest readRequest = connection.readRequestBuilder()
        .addTagAddress("sensor1", "holding-register:1")
        .addTagAddress("sensor2", "holding-register:2") 
        .build();
        
    PlcReadResponse response = readRequest.execute().get();
    
    // Extract values
    if (response.getResponseCode("sensor1") == PlcResponseCode.OK) {
        int value1 = response.getInteger("sensor1");
        int value2 = response.getInteger("sensor2");
        System.out.println("Sensor1: " + value1 + ", Sensor2: " + value2);
    }
}

Architecture

Apache PLC4X Java API is built around several key components:

  • Driver Management: PlcDriverManager provides discovery and factory methods for protocol-specific drivers
  • Connection Layer: PlcConnection abstracts PLC connections with lifecycle management and capability detection
  • Message System: Type-safe request/response pattern with builders for all operations (read, write, subscribe, browse)
  • Value System: PlcValue provides universal value abstraction with automatic type conversion
  • Asynchronous Operations: All operations return CompletableFuture for non-blocking execution
  • Metadata System: Capability discovery and configuration options through driver and connection metadata

Capabilities

Connection Management

Core connection lifecycle management, driver discovery, and connection establishment with authentication support.

public interface PlcDriverManager {
    static PlcDriverManager getDefault();
    Set<String> getProtocolCodes();
    PlcDriver getDriver(String protocolCode) throws PlcConnectionException;
    PlcDriver getDriverForUrl(String url) throws PlcConnectionException;
    PlcConnectionManager getConnectionManager();
}

public interface PlcConnectionManager {
    PlcConnection getConnection(String url) throws PlcConnectionException;
    PlcConnection getConnection(String url, PlcAuthentication authentication) throws PlcConnectionException;
}

public interface PlcConnection extends AutoCloseable {
    void connect() throws PlcConnectionException;
    boolean isConnected();
    void close() throws Exception;
    PlcConnectionMetadata getMetadata();
    CompletableFuture<? extends PlcPingResponse> ping();
}

Connection Management

Read Operations

Type-safe data reading from PLC tags with comprehensive value conversion and validation.

public interface PlcReadRequest extends PlcTagRequest {
    CompletableFuture<? extends PlcReadResponse> execute();
    
    interface Builder extends PlcRequestBuilder {
        Builder addTagAddress(String name, String tagAddress);
        Builder addTag(String name, PlcTag tag);
        PlcReadRequest build();
    }
}

public interface PlcReadResponse extends PlcTagResponse {
    PlcValue getPlcValue(String name);
    int getInteger(String name);
    boolean getBoolean(String name);
    String getString(String name);
    // Additional type-specific getters...
}

Read Operations

Write Operations

Type-safe data writing to PLC tags with value validation and conversion.

public interface PlcWriteRequest extends PlcTagRequest {
    CompletableFuture<? extends PlcWriteResponse> execute();
    
    interface Builder extends PlcRequestBuilder {
        Builder addTagAddress(String name, String tagAddress, Object... values);
        Builder addTag(String name, PlcTag tag, Object... values);
        PlcWriteRequest build();
    }
}

Write Operations

Subscription System

Event-driven communication with multiple subscription types for real-time data monitoring.

public interface PlcSubscriptionRequest extends PlcSubscriptionTagRequest {
    CompletableFuture<? extends PlcSubscriptionResponse> execute();
    
    interface Builder extends PlcRequestBuilder {
        Builder setConsumer(Consumer<PlcSubscriptionEvent> consumer);
        Builder addCyclicTagAddress(String name, String tagAddress, Duration duration);
        Builder addChangeOfStateTagAddress(String name, String tagAddress);
        Builder addEventTagAddress(String name, String tagAddress);
        PlcSubscriptionRequest build();
    }
}

public interface PlcSubscriptionEvent extends PlcReadResponse {
    Instant getTimestamp();
}

Subscription System

Value System

Universal value abstraction providing type-safe access to PLC data with automatic conversion.

public interface PlcValue {
    PlcValueType getPlcValueType();
    Object getObject();
    boolean isBoolean();
    boolean getBoolean();
    int getInteger();
    String getString();
    // Comprehensive type system...
}

Value System

Browse Operations

PLC namespace exploration and tag discovery capabilities.

public interface PlcBrowseRequest extends PlcRequest {
    CompletableFuture<? extends PlcBrowseResponse> execute();
    
    interface Builder extends PlcRequestBuilder {
        Builder addQuery(String name, String query);
        PlcBrowseRequest build();
    }
}

Browse Operations

Exception Handling

Comprehensive exception hierarchy for robust error handling in industrial communication.

public class PlcException extends Exception { }
public class PlcConnectionException extends PlcException { }
public class PlcIoException extends PlcException { }
public class PlcProtocolException extends PlcException { }
// Additional specific exceptions...

Exception Handling

Types

Core Enums

public enum PlcResponseCode {
    OK, NOT_FOUND, ACCESS_DENIED, INVALID_ADDRESS, INVALID_DATATYPE,
    INVALID_DATA, INTERNAL_ERROR, REMOTE_BUSY, REMOTE_ERROR, 
    UNSUPPORTED, RESPONSE_PENDING;
    
    short getValue();
    static PlcResponseCode enumForValue(short value);
}

public enum PlcValueType {
    NULL, BOOL, BYTE, WORD, DWORD, LWORD,
    USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT,
    REAL, LREAL, CHAR, WCHAR, STRING, WSTRING,
    TIME, LTIME, DATE, LDATE, TIME_OF_DAY, LTIME_OF_DAY,
    DATE_AND_TIME, DATE_AND_LTIME, LDATE_AND_TIME,
    Struct, List, RAW_BYTE_ARRAY;
    
    short getValue();
    Class<?> getDefaultJavaType();
}

public enum PlcSubscriptionType {
    CYCLIC, CHANGE_OF_STATE, EVENT
}

Authentication Types

public interface PlcAuthentication { }

public class PlcUsernamePasswordAuthentication implements PlcAuthentication {
    public PlcUsernamePasswordAuthentication(String username, String password);
    public String getUsername();
    public String getPassword();
}

Metadata Types

public interface PlcConnectionMetadata {
    boolean isReadSupported();
    boolean isWriteSupported();
    boolean isSubscribeSupported();
    boolean isBrowseSupported();
}

public interface PlcDriverMetadata {
    Optional<String> getDefaultTransportCode();
    List<String> getSupportedTransportCodes();
    boolean isDiscoverySupported();
}