Skip to content

Commit

Permalink
Add STRING and WSTRING to getDataTypeTableEntry. serializePlcValue, r…
Browse files Browse the repository at this point in the history
…emove check directly in dataTypeTable, only use getDataTypeTableEntry.
  • Loading branch information
François Dupont committed Nov 19, 2024
1 parent d09c49a commit eac8bc7
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1199,10 +1199,6 @@ protected CompletableFuture<PlcWriteResponse> multiWrite(PlcWriteRequest writeRe

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);
Expand Down Expand Up @@ -1953,13 +1949,28 @@ protected Optional<AdsDataTypeTableEntry> getDataTypeTableEntry(String name) {
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();
Expand Down

0 comments on commit eac8bc7

Please sign in to comment.