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 2022/03/06 16:39:34 UTC

[plc4x] branch develop updated: feat(protocol/modbus): Started working on ModbusRTU/ASCII

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 6f38d2e  feat(protocol/modbus): Started working on ModbusRTU/ASCII
6f38d2e is described below

commit 6f38d2e8be91ec7b4f231ba41ee39e9d9b169bd3
Author: cdutz <ch...@c-ware.de>
AuthorDate: Sun Mar 6 17:38:44 2022 +0100

    feat(protocol/modbus): Started working on ModbusRTU/ASCII
---
 .../main/resources/protocols/modbus/modbus.mspec   | 40 +++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/protocols/modbus/src/main/resources/protocols/modbus/modbus.mspec b/protocols/modbus/src/main/resources/protocols/modbus/modbus.mspec
index bb799e7..c6009b5 100644
--- a/protocols/modbus/src/main/resources/protocols/modbus/modbus.mspec
+++ b/protocols/modbus/src/main/resources/protocols/modbus/modbus.mspec
@@ -47,14 +47,46 @@
     [simple         ModbusPDU('response')   pdu]
 ]
 
-[type ModbusSerialADU(bit response) byteOrder='LITTLE_ENDIAN'
-    [simple         uint 16     transactionId]
-    [reserved       uint 16     '0x0000']
-    [simple         uint 16     length]
+[type ModbusRtuADU(bit response) byteOrder='LITTLE_ENDIAN'
+    // The start is indicated by more than 3,5 chars of value 0x00 ...
+    // The protocol will take care of consuming all except the last 4 empty chars
+    // The Length is determined by starting at the last 4 empty characters
+    // to the start of the next 4 empty characters
+    [const          uint 8      space1 0x00           ] // Character '\0'
+    [const          uint 8      space2 0x00           ] // Character '\0'
+    [const          uint 8      space3 0x00           ] // Character '\0'
+    [const          uint 8      space4 0x00           ] // Character '\0'
     [simple         uint 8      address]
 
     // The actual modbus payload
     [simple         ModbusPDU('response')   pdu]
+    //[checksum       uint 16     crc            ]
+
+    // The at least 4 silence chars is a separator ... so we don't actually consume them.
+    // They will be consumed by the next packet
+    //[const          uint 8      0x00           ] // Character '\0'
+    //[const          uint 8      0x00           ] // Character '\0'
+    //[const          uint 8      0x00           ] // Character '\0'
+    //[const          uint 8      0x00           ] // Character '\0'
+]
+
+[type ModbusAsciiADU(bit response) byteOrder='BIG_ENDIAN'
+    [const          uint 8      start 0x3A           ] // Character ':'
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    // Starting the ASCII encoded part where every byte is encoded as the ASCII representation of the raw byte.
+    [simple         uint 8      address        ]
+
+    // The actual modbus payload
+    [simple         ModbusPDU('response')   pdu]
+
+    //[checksum       uint 8      lrc            ]
+
+    // End the ASCII encoded part ...
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+    [const          uint 8      cr 0x0D           ] // Character '\r'
+    [const          uint 8      lf 0x0A           ] // Character '\n'
 ]
 
 [discriminatedType ModbusPDU(bit response)