This is an automated email from the ASF dual-hosted git repository.

chrisdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 95af1600d8 fix: Made the error reporting a bit more explicit.
95af1600d8 is described below

commit 95af1600d8d8905369c99ed553ee75e2ea42e5ae
Author: Christofer Dutz <[email protected]>
AuthorDate: Fri Jun 19 16:20:34 2026 +0200

    fix: Made the error reporting a bit more explicit.
---
 .../org/apache/plc4x/java/s7/S7CotpConnection.java |   1 +
 .../java/s7/manual/ManualWallS7300DriverTest.java  |   2 +-
 .../readwrite/ManualWallS7300AlarmSubscribe.java   | 103 +++++++++++++++++++++
 .../readwrite/ManualWallS7300CyclicSubscribe.java  |  76 +++++++++++++++
 4 files changed, 181 insertions(+), 1 deletion(-)

diff --git 
a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/S7CotpConnection.java 
b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/S7CotpConnection.java
index d6aa165b47..f3a834d224 100644
--- 
a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/S7CotpConnection.java
+++ 
b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/S7CotpConnection.java
@@ -804,6 +804,7 @@ public class S7CotpConnection extends 
ConnectionBase<S7Configuration> {
             case OK -> PlcResponseCode.OK;
             case NOT_FOUND, INVALID_ADDRESS -> PlcResponseCode.INVALID_ADDRESS;
             case DATA_TYPE_NOT_SUPPORTED -> PlcResponseCode.INVALID_DATATYPE;
+            case ACCESS_DENIED -> PlcResponseCode.ACCESS_DENIED;
             default -> PlcResponseCode.INTERNAL_ERROR;
         };
     }
diff --git 
a/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/manual/ManualWallS7300DriverTest.java
 
b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/manual/ManualWallS7300DriverTest.java
index fa8a494172..ffd9a1b416 100644
--- 
a/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/manual/ManualWallS7300DriverTest.java
+++ 
b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/manual/ManualWallS7300DriverTest.java
@@ -44,7 +44,7 @@ public class ManualWallS7300DriverTest extends BasicPlcTest {
 
     public static void main(String[] args) throws Exception {
         boolean testArrays = false;
-        ManualWallS7300DriverTest test = new 
ManualWallS7300DriverTest("s7://192.168.24.62?remote-rack=0&remote-slot=1");//?log.audit-log-file=ManualWallS7300DriverTest-audit.log
+        ManualWallS7300DriverTest test = new 
ManualWallS7300DriverTest("s7://192.168.24.60?remote-rack=0&remote-slot=1");//?log.audit-log-file=ManualWallS7300DriverTest-audit.log
         test.addTestCase(/*"g_b1",*/            "%DB42:0.0:BOOL",           
new PlcBOOL(true));
         test.addTestCase(/*"g_b8",*/            "%DB42:1.0:BYTE",              
new PlcBYTE(0xAB));
         test.addTestCase(/*"g_b16",*/           "%DB42:2.0:WORD",              
new PlcWORD(0xBEEF));
diff --git 
a/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualWallS7300AlarmSubscribe.java
 
b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualWallS7300AlarmSubscribe.java
new file mode 100644
index 0000000000..b91b793e1f
--- /dev/null
+++ 
b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualWallS7300AlarmSubscribe.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.s7.readwrite;
+
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.PlcDriverManager;
+import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse;
+import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.api.value.PlcValue;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Manual smoke-test for the S7Comm UserData "alarm push" subscription path 
against an
+ * S7-300 (or any classic-family CPU). Connects, subscribes to the {@code ALM} 
tag, and
+ * prints every alarm indication the PLC pushes for the next 60 seconds.
+ *
+ * <p>Trigger an alarm in the PLC's diagnostic buffer (e.g. force a STOP/RUN 
transition,
+ * trigger an SFB OB, or use Step7 to inject a test message via {@code Test 
&gt; Modify
+ * Variable}) to see entries appear here.
+ *
+ * <p>Run with: {@code mvn -pl plc4j/drivers/s7 -DskipTests=true compile 
test-compile
+ * exec:java 
-Dexec.mainClass=org.apache.plc4x.java.s7.manual.ManualWallS7300AlarmSubscribe}
+ */
+public class ManualWallS7300AlarmSubscribe {
+
+    private static final String CONNECTION_URL = 
"s7://192.168.24.60?controller-type=S7_300";
+    private static final long LISTEN_DURATION_MS = 600_000L;
+
+    public static void main(String[] args) throws Exception {
+        try (PlcConnection connection = 
PlcDriverManager.getDefault().getConnectionManager().getConnection(CONNECTION_URL))
 {
+            System.out.printf("Connected. metadata.subscribeSupported=%s%n",
+                connection.getMetadata().isSubscribeSupported());
+
+            PlcSubscriptionResponse subResp = 
connection.subscriptionRequestBuilder()
+                .addEventTagAddress("alarms", "ALM")
+                .build()
+                .execute()
+                .get(5, TimeUnit.SECONDS);
+
+            PlcResponseCode code = subResp.getResponseCode("alarms");
+            System.out.printf("Subscribe response: %s%n", code);
+            if (code != PlcResponseCode.OK) {
+                System.err.println("Subscription failed — aborting");
+                return;
+            }
+
+            PlcSubscriptionHandle handle = 
subResp.getSubscriptionHandle("alarms");
+            handle.register(event -> {
+                PlcValue value = event.getPlcValue("alarms");
+                System.out.printf("[%s] alarm: %s%n", event.getTimestamp(), 
formatStruct(value));
+            });
+
+            System.out.printf("Listening for alarms for %ds — trigger an alarm 
in the PLC...%n",
+                LISTEN_DURATION_MS / 1000);
+            Thread.sleep(LISTEN_DURATION_MS);
+
+            connection.unsubscriptionRequestBuilder()
+                .addHandles(handle)
+                .build()
+                .execute()
+                .get(5, TimeUnit.SECONDS);
+            System.out.println("Unsubscribed.");
+        }
+    }
+
+    private static String formatStruct(PlcValue value) {
+        if (value == null || !value.isStruct()) {
+            return String.valueOf(value);
+        }
+        StringBuilder sb = new StringBuilder("{");
+        boolean first = true;
+        for (String key : value.getKeys()) {
+            if (!first) sb.append(", ");
+            first = false;
+            PlcValue v = value.getValue(key);
+            // Render state masks as hex for readability, eventId likewise.
+            if ("eventId".equals(key) || key.endsWith("State")) {
+                
sb.append(key).append("=0x").append(Long.toHexString(v.getLong()).toUpperCase());
+            } else {
+                sb.append(key).append("=").append(v);
+            }
+        }
+        return sb.append("}").toString();
+    }
+}
diff --git 
a/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualWallS7300CyclicSubscribe.java
 
b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualWallS7300CyclicSubscribe.java
new file mode 100644
index 0000000000..469eaf04fb
--- /dev/null
+++ 
b/plc4j/drivers/s7/src/test/java/org/apache/plc4x/java/s7/readwrite/ManualWallS7300CyclicSubscribe.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.s7.readwrite;
+
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.PlcDriverManager;
+import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse;
+import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Manual smoke-test for the S7Comm UserData "cyclic services" subscription 
path against an
+ * S7-300 (or any classic-family CPU). Asks the PLC to push the value of 
marker word
+ * {@code %MW10} every second for the next 30 seconds, then unsubscribes 
cleanly.
+ *
+ * <p>To produce visible value changes, increment {@code MW10} in a watch 
table while this
+ * is running — each push should reflect the current value.
+ */
+public class ManualWallS7300CyclicSubscribe {
+
+    private static final String CONNECTION_URL = 
"s7://192.168.24.60?controller-type=S7_300";
+    private static final long LISTEN_DURATION_MS = 30_000L;
+
+    public static void main(String[] args) throws Exception {
+        try (PlcConnection connection = 
PlcDriverManager.getDefault().getConnectionManager().getConnection(CONNECTION_URL))
 {
+            System.out.printf("Connected. metadata.subscribeSupported=%s%n",
+                connection.getMetadata().isSubscribeSupported());
+
+            PlcSubscriptionResponse subResp = 
connection.subscriptionRequestBuilder()
+                .addCyclicTagAddress("subscription-tag", "%DB42:10:DINT", 
Duration.ofSeconds(1))
+                .build()
+                .execute()
+                .get(5, TimeUnit.SECONDS);
+
+            PlcResponseCode code = subResp.getResponseCode("subscription-tag");
+            System.out.printf("Subscribe response: %s%n", code);
+            if (code != PlcResponseCode.OK) {
+                System.err.println("Subscription failed — aborting");
+                return;
+            }
+
+            PlcSubscriptionHandle handle = 
subResp.getSubscriptionHandle("subscription-tag");
+            handle.register(event -> System.out.printf("[%s] subscription-tag 
= %s%n",
+                event.getTimestamp(), event.getPlcValue("subscription-tag")));
+
+            System.out.printf("Listening for cyclic pushes for %ds...%n", 
LISTEN_DURATION_MS / 1000);
+            Thread.sleep(LISTEN_DURATION_MS);
+
+            connection.unsubscriptionRequestBuilder()
+                .addHandles(handle)
+                .build()
+                .execute()
+                .get(5, TimeUnit.SECONDS);
+            System.out.println("Unsubscribed.");
+        }
+    }
+}

Reply via email to