fdupont-epsilia commented on issue #1626:
URL: https://github.com/apache/plc4x/issues/1626#issuecomment-2479971084

   Code below is working, I'm sure you will rework it in a much better form.
   
   Took a while to figure out to get AdsDataType "CHAR" 0x1E (30)  instead of 
"STRING" 0x20 (32).
   
   ```java
       protected Optional<AdsDataTypeTableEntry> getDataTypeTableEntry(String 
name) {
           if(dataTypeTable.containsKey(name)) {
               return Optional.of(dataTypeTable.get(name));
           }
           try {
               AdsDataType adsDataType;
               int numBytes;
               if (name.startsWith("STRING(")) {
                   adsDataType = AdsDataType.valueOf("CHAR");
                   java.util.regex.Pattern pattern = 
java.util.regex.Pattern.compile("\\((\\d+)\\)");
                   java.util.regex.Matcher matcher = pattern.matcher(name);
                   if (matcher.find()) {
                       numBytes = Integer.parseInt(matcher.group(1)) + 1;
                  }
                   else {
                       return Optional.empty();
                   }
               }
               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, numBytes, 0,
                   adsDataType.getValue(), 0, 0, 0,
                   name, "", "",
                   Collections.emptyList(), Collections.emptyList(), new 
byte[0]));
           } catch (IllegalArgumentException e) {
               return Optional.empty();
           }
       }
   ```
   
   After all, « ARRAY [1..13] OF WORD » is returned by the plc.
   Will continue testing other basic type I am using. And validate if writing 
works.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to