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

cgarcia pushed a commit to branch feature/s7strings
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/s7strings by this push:
     new 2da3dd477c Corrects reading of the TIME format.
2da3dd477c is described below

commit 2da3dd477c6308d1eb106a91f49fe3a23db32e96
Author: Cesar Garcia <[email protected]>
AuthorDate: Fri Dec 1 19:39:35 2023 -0400

    Corrects reading of the TIME format.
---
 .../apache/plc4x/java/s7/readwrite/DataItem.java   |  4 +--
 .../examples/plc4j/s7event/PlcReadDataS7400H.java  | 38 +++++++++++++++++++---
 .../s7/src/main/resources/protocols/s7/s7.mspec    |  2 +-
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git 
a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java
 
b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java
index 40dfd1d4d6..051dedaa11 100644
--- 
a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java
+++ 
b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java
@@ -181,7 +181,7 @@ public class DataItem {
 
       // Simple Field (milliseconds)
       Long milliseconds = /*TODO: migrate me*/ /*TODO: migrate me*/
-          readBuffer.readUnsignedLong("", 32);
+          readBuffer.readLong("", 32);
 
       return PlcTIME.ofMilliseconds(milliseconds);
     } else if (EvaluationHelper.equals(dataProtocolId, "IEC61131_LTIME")) { // 
LTIME
@@ -367,7 +367,7 @@ public class DataItem {
       // Simple Field (milliseconds)
       long milliseconds = (long) _value.getLong();
       /*TODO: migrate me*/
-      /*TODO: migrate me*/ writeBuffer.writeUnsignedLong(
+      /*TODO: migrate me*/ writeBuffer.writeLong(
           "", 32, ((Number) (milliseconds)).longValue());
     } else if (EvaluationHelper.equals(dataProtocolId, "IEC61131_LTIME")) { // 
LTIME
       // Simple Field (nanoseconds)
diff --git 
a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/PlcReadDataS7400H.java
 
b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/PlcReadDataS7400H.java
index 604ab80045..8222917bc6 100644
--- 
a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/PlcReadDataS7400H.java
+++ 
b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/PlcReadDataS7400H.java
@@ -19,6 +19,7 @@
 package org.apache.plc4x.examples.plc4j.s7event;
 
 import java.io.IOException;
+import java.time.Duration;
 import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.commons.lang3.time.StopWatch;
 import org.apache.plc4x.java.DefaultPlcDriverManager;
@@ -26,6 +27,8 @@ import 
org.apache.plc4x.java.api.exceptions.PlcConnectionException;
 import org.apache.plc4x.java.api.listener.ConnectionStateListener;
 import org.apache.plc4x.java.api.messages.PlcReadRequest;
 import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.java.api.messages.PlcWriteResponse;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.apache.plc4x.java.s7.readwrite.protocol.S7HPlcConnection;
 import org.slf4j.Logger;
@@ -78,7 +81,7 @@ public class PlcReadDataS7400H implements 
ConnectionStateListener {
         OpenConnection("s7://10.10.1.80/10.10.1.81?remote-rack=0&"
                 + "remote-slot=3&remote-rack2=0&remote-slot=4&"
                 + "controller-type=S7_400&read-timeout=8&"                
-                + "ping=true&ping-time=2&retry-time=3"); //(01)
+                + "ping=false&ping-time=2&retry-time=3"); //(01)
            
         logger.info("*****************************************************"); 
         logger.info("* 1. Once the connection is executed, it must read"); 
@@ -90,7 +93,7 @@ public class PlcReadDataS7400H implements 
ConnectionStateListener {
         logger.info("*    Press [ENTER]");        
         logger.info("*****************************************************"); 
         System.in.read();
-        
+        Write();
         Read(); //(01.1)
                  
         logger.info("*****************************************************"); 
@@ -146,7 +149,7 @@ public class PlcReadDataS7400H implements 
ConnectionStateListener {
         logger.info("*    Press [ENTER]");        
         logger.info("*****************************************************");
         System.in.read();  
-        
+
         Read(); //(07.1)    
         
         
@@ -221,7 +224,7 @@ public class PlcReadDataS7400H implements 
ConnectionStateListener {
         if (!isConnected.get()) return;
         try {
             final PlcReadRequest.Builder readrequest = 
connection.readRequestBuilder();  //(01)
-            readrequest.addTagAddress("TEST", "%DB1000:4:INT"); //(02) 
+            readrequest.addTagAddress("TEST", "%DB406:4:TIME"); //(02) 
             
             final PlcReadRequest rr = readrequest.build(); //(03)
             final PlcReadResponse response; //(04)            
@@ -237,6 +240,33 @@ public class PlcReadDataS7400H implements 
ConnectionStateListener {
         };          
     }    
     
+    
+    
/***************************************************************************
+    * The reading process is standard. In case of an exception, 
+    * the user must take the appropriate actions, but "do not close 
+    * the connection":
+    
***************************************************************************/    
+    private void Write() {
+        if (!isConnected.get()) return;
+        try {
+            final PlcWriteRequest.Builder writeRequest = 
connection.writeRequestBuilder();  //(01)
+            writeRequest.addTagAddress("TAG01", 
"%DB400:4:TIME",Duration.ofDays(5)); //(02) 
+          
+            
+            final PlcWriteRequest wr = writeRequest.build(); //(03)
+            final PlcWriteResponse response; //(04)            
+            response = wr.execute().get(); //(05)
+            
+            if (response.getResponseCode("TAG01") == PlcResponseCode.OK) { 
//(06)
+                logger.info("TAG01 Write sucefull...");
+            } else {
+                logger.info("TAG01 Problem reading...");                
+            }            
+            
+        } catch (Exception ex) { //(07)
+            logger.info("Read: " + ex.getMessage());
+        };          
+    }        
     
/***************************************************************************
     * This method is called when the driver makes an internal TCP connection.
     * The first connection of the driver does not generate this event.
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec 
b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 599d089c21..bba452cdab 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -772,7 +772,7 @@
         // -----------------------------------------
         // - Duration: Interpreted as "milliseconds"
         ['"IEC61131_TIME"' TIME
-            [simple uint 32 milliseconds]
+            [simple int 32 milliseconds]
         ]
         //['"S7_S5TIME"' TIME
         //    [reserved uint 2  '0x00']

Reply via email to