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 2020/02/29 17:04:19 UTC

[plc4x] branch develop updated: - Fixed a bug in the encoding of single item values

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 46b55f6  - Fixed a bug in the encoding of single item values
46b55f6 is described below

commit 46b55f664c5b023ca1c70a75623a8e531d9a5e5c
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Feb 29 18:04:12 2020 +0100

    - Fixed a bug in the encoding of single item values
---
 .../plc4x/java/modbus/protocol/ModbusProtocolLogic.java       | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/protocol/ModbusProtocolLogic.java b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/protocol/ModbusProtocolLogic.java
index 053d937..cdada39 100644
--- a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/protocol/ModbusProtocolLogic.java
+++ b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/protocol/ModbusProtocolLogic.java
@@ -28,6 +28,7 @@ import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.apache.plc4x.java.api.value.PlcBoolean;
 import org.apache.plc4x.java.api.value.PlcList;
+import org.apache.plc4x.java.api.value.PlcShort;
 import org.apache.plc4x.java.api.value.PlcValue;
 import org.apache.plc4x.java.modbus.config.ModbusConfiguration;
 import org.apache.plc4x.java.modbus.field.ModbusFieldCoil;
@@ -280,6 +281,16 @@ public class ModbusProtocolLogic extends Plc4xProtocolBase<ModbusTcpADU> impleme
                 }
                 return bytes;
             }
+        } else if(plcValue instanceof PlcBoolean) {
+            PlcBoolean plcBoolean = (PlcBoolean) plcValue;
+            return plcBoolean.getBoolean() ? new byte[] {0x01} : new byte[] {0x00};
+        } else if(plcValue instanceof PlcShort) {
+            PlcShort plcShort = (PlcShort) plcValue;
+            Short shortValue = plcShort.getShort();
+            byte[] bytes = new byte[2];
+            bytes[0] = (byte)((shortValue >> 8) & 0xff);
+            bytes[1] = (byte)(shortValue & 0xff);
+            return bytes;
         }
         return new byte[0];
     }