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

sruehl 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 3260c0795c feat(plc4j/ads): Add STRING and WSTRING to 
getDataTypeTableEntry. (#1902)
3260c0795c is described below

commit 3260c0795c15b31c6a1dc037274a2ab5213fb1e2
Author: fdupont-epsilia <[email protected]>
AuthorDate: Wed Dec 4 06:08:01 2024 -0500

    feat(plc4j/ads): Add STRING and WSTRING to getDataTypeTableEntry. (#1902)
    
    * Add STRING and WSTRING to getDataTypeTableEntry. serializePlcValue, 
remove check directly in dataTypeTable, only use getDataTypeTableEntry.
    
    * fix(plc4j/ads): Remove obsolete comment #1902
    
    ---------
    
    Co-authored-by: François Dupont <[email protected]>
---
 .../plc4x/java/ads/protocol/AdsProtocolLogic.java  | 26 +++++++++++++++-------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git 
a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
 
b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
index 114a46c8ff..9d8e59afe1 100644
--- 
a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
+++ 
b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
@@ -1198,11 +1198,6 @@ public class AdsProtocolLogic extends 
Plc4xProtocolBase<AmsTCPPacket> implements
     }
 
     protected byte[] serializePlcValue(PlcValue plcValue, String datatypeName) 
throws SerializationException {
-        // First check, if we have type information available.
-        if (!dataTypeTable.containsKey(datatypeName)) {
-            throw new SerializationException("Could not find data type: " + 
datatypeName);
-        }
-
         // Get the data type, allocate enough memory and serialize the value 
based on the
         // structure defined by the data type.
         Optional<AdsDataTypeTableEntry> dataTypeTableEntryOptional = 
getDataTypeTableEntry(datatypeName);
@@ -1953,13 +1948,28 @@ public class AdsProtocolLogic extends 
Plc4xProtocolBase<AmsTCPPacket> implements
             return Optional.of(dataTypeTable.get(name));
         }
         try {
-            AdsDataType adsDataType = AdsDataType.valueOf(name);
+            AdsDataType adsDataType;
+            int numBytes;
+
+            if (name.startsWith("STRING(")) {
+                adsDataType = AdsDataType.valueOf("CHAR");
+                numBytes = Integer.parseInt(name.substring(7, name.length() - 
1)) + 1;
+            }
+            else if (name.startsWith("WSTRING(")) {
+                adsDataType = AdsDataType.valueOf("WCHAR");
+                numBytes = Integer.parseInt(name.substring(8, name.length() - 
1)) * 2 + 2;
+            }
+            else {
+                adsDataType = AdsDataType.valueOf(name);
+                numBytes = adsDataType.getNumBytes();
+            }
+
             // !It seems that the dataType value differs from system to system,
             // !However, we never really seem to use that value, so I would 
say it doesn't matter.
             return Optional.of(new AdsDataTypeTableEntry(
-                128, 1, 0, 0, adsDataType.getNumBytes(), 0,
+                128, 1, 0, 0, numBytes, 0,
                 adsDataType.getValue(), 0, 0, 0,
-                adsDataType.name(), "", "",
+                name, "", "",
                 Collections.emptyList(), Collections.emptyList(), new 
byte[0]));
         } catch (IllegalArgumentException e) {
             return Optional.empty();

Reply via email to