You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2021/08/06 22:26:10 UTC
[plc4x] branch develop updated: PLC4X-309 - [S7] Writing byte array
not working - Fixed the serialization of PlcList typed fields when writing
This is an automated email from the ASF dual-hosted git repository.
cdutz 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 08d332b PLC4X-309 - [S7] Writing byte array not working - Fixed the serialization of PlcList typed fields when writing
08d332b is described below
commit 08d332bb8a4004144d7a2dcb18f3d6d53b91712e
Author: cdutz <ch...@c-ware.de>
AuthorDate: Sat Aug 7 00:26:01 2021 +0200
PLC4X-309 - [S7] Writing byte array not working
- Fixed the serialization of PlcList typed fields when writing
---
.../java/s7/readwrite/protocol/S7ProtocolLogic.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
index 40903d1..e956cdf 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
@@ -51,6 +51,7 @@ import org.apache.plc4x.java.spi.transaction.RequestTransactionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
@@ -512,10 +513,20 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
try {
DataTransportSize transportSize = field.getDataType().getDataTransportSize();
int stringLength = (field instanceof S7StringField) ? ((S7StringField) field).getStringLength() : 254;
- WriteBufferByteBased writeBuffer = DataItemIO.staticSerialize(plcValue, field.getDataType().getDataProtocolId(),
- stringLength);
- if(writeBuffer != null) {
- byte[] data = writeBuffer.getData();
+ ByteBuffer byteBuffer = null;
+ for(int i = 0; i < field.getNumberOfElements(); i++) {
+ WriteBufferByteBased writeBuffer = DataItemIO.staticSerialize(plcValue.getIndex(i),
+ field.getDataType().getDataProtocolId(), stringLength);
+ if(writeBuffer != null) {
+ // Allocate enough space for all items.
+ if(byteBuffer == null) {
+ byteBuffer = ByteBuffer.allocate(writeBuffer.getData().length * field.getNumberOfElements());
+ }
+ byteBuffer.put(writeBuffer.getData());
+ }
+ }
+ if(byteBuffer != null) {
+ byte[] data = byteBuffer.array();
return new S7VarPayloadDataItem(DataTransportErrorCode.OK, transportSize, data);
}
} catch (ParseException e) {