Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plc4j/ads): Add STRING and WSTRING to getDataTypeTableEntry. #1902

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1198,11 +1198,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 +1948,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(), "", "",
fdupont-epsilia marked this conversation as resolved.
Show resolved Hide resolved
name, "", "",
Collections.emptyList(), Collections.emptyList(), new byte[0]));
} catch (IllegalArgumentException e) {
return Optional.empty();
Expand Down