Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 0.13.0-SNAPSHOT S7 closes TCP connection #1994

Open
2 of 16 tasks
agrazio opened this issue Jan 30, 2025 · 0 comments
Open
2 of 16 tasks

[Bug]: 0.13.0-SNAPSHOT S7 closes TCP connection #1994

agrazio opened this issue Jan 30, 2025 · 0 comments
Labels
java Pull requests that update Java code S7 https://plc4x.apache.org/users/protocols/s7.html

Comments

@agrazio
Copy link

agrazio commented Jan 30, 2025

What happened?

Reading eight tags every second from a S7_1200 PLC with S7 with version 0.12.0 it works, but with 0.13.0-SNAPSHOT after a while the connection drops and cannot be restored; it gets stuck in a loop at:

[plc4x-s7ha-thread-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HPlcConnection - Creating primary connection. [plc4x-s7ha-thread-1] INFO org.apache.plc4x.java.transport.tcp.TcpChannelFactory - Configuring Bootstrap with org.apache.plc4x.java.s7.readwrite.configuration.S7TcpTransportConfiguration@5f4b0cf4 [plc4x-s7ha-thread-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HPlcConnection - Reconnecting primary channel. [nioEventLoopGroup-427-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HMuxImpl - Unregistered of channel: PRIMARY [nioEventLoopGroup-427-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HMuxImpl - io.netty.channel.embedded.EmbeddedEventLoop@7da0be76 [plc4x-s7ha-thread-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HPlcConnection - Creating primary connection. [plc4x-s7ha-thread-1] INFO org.apache.plc4x.java.transport.tcp.TcpChannelFactory - Configuring Bootstrap with org.apache.plc4x.java.s7.readwrite.configuration.S7TcpTransportConfiguration@5f4b0cf4 [plc4x-s7ha-thread-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HPlcConnection - Reconnecting primary channel. [nioEventLoopGroup-428-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HMuxImpl - Unregistered of channel: PRIMARY [nioEventLoopGroup-428-1] INFO org.apache.plc4x.java.s7.readwrite.protocol.S7HMuxImpl - io.netty.channel.embedded.EmbeddedEventLoop@7da0be76

Example code:

public static void main(String[] args) {
        initialize();
        scheduler.scheduleAtFixedRate(() -> executeRead(config.getTags()), 0, 1000, TimeUnit.MILLISECONDS);
}

public static void initialize() {
    cachedPlcConnectionManager = CachedPlcConnectionManager.getBuilder().build();
    config = Configuration.getConfiguration();
    scheduler.scheduleAtFixedRate(() -> executeRead(config.getTags()), 0, 10, TimeUnit.MILLISECONDS);
}

public static void executeRead(List<Configuration.Tag> tags) {
    try (PlcConnection plcConnection = cachedPlcConnectionManager.getConnection(config.getDeviceAddress())) {
        if (!plcConnection.getMetadata().isReadSupported()) {
            System.out.printf("[%s] Connection does not support reading%n", LocalDateTime.now());
            return;
        }

        PlcReadRequest.Builder readRequestBuilder = plcConnection.readRequestBuilder();
        for (Configuration.Tag tag : tags) {
            readRequestBuilder.addTagAddress(tag.getName(), tag.getAddress());
        }

        PlcReadRequest readRequest = readRequestBuilder.build();
        PlcReadResponse response = readRequest.execute().get();
        processResponse(response);

    } catch (PlcConnectionException e) {
        System.out.printf("[%s] Connection error: %s%n", LocalDateTime.now(), e.getMessage());
    } catch (Exception e) {
        System.out.printf("[%s] Error during PLC read: %s%n", LocalDateTime.now(), e.getMessage());
    }
}

On failure, it creates up to 40 connections, then closes them, and continues opening and closing connections without establishing a working one.

Version

v0.13.0-SNAPSHOT

Programming Languages

  • plc4j
  • plc4go
  • plc4c
  • plc4net

Protocols

  • AB-Ethernet
  • ADS /AMS
  • BACnet/IP
  • CANopen
  • DeltaV
  • DF1
  • EtherNet/IP
  • Firmata
  • KNXnet/IP
  • Modbus
  • OPC-UA
  • S7
@agrazio agrazio added the bug label Jan 30, 2025
@ottlukas ottlukas added java Pull requests that update Java code S7 https://plc4x.apache.org/users/protocols/s7.html labels Feb 5, 2025
@ottlukas ottlukas removed the bug label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java Pull requests that update Java code S7 https://plc4x.apache.org/users/protocols/s7.html
Projects
None yet
Development

No branches or pull requests

2 participants