Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Export MODBUS_MAX_ADU_LENGTH and documentation (ref #241)

commit 98c4aca38412f6b86ffeb3fd01c68ee9f1fd04eb 1 parent 130cf4b
Stéphane Raimbault authored
Showing with 25 additions and 6 deletions.
  1. +15 −1 doc/modbus_receive_confirmation.txt
  2. +10 −5 src/modbus.h
16 doc/modbus_receive_confirmation.txt
View
@@ -14,11 +14,18 @@ SYNOPSIS
DESCRIPTION
-----------
-The *modbus_receive_confirmation(*_ function shall receive a request via the
+The *modbus_receive_confirmation()* function shall receive a request via the
socket of the context _ctx_. This function must be used for debugging purposes
because the received response isn't checked against the initial request. This
function can be used to receive request not handled by the library.
+The maximum size of the response depends on the used backend, in RTU the _rsp_
+array must be _MODBUS_RTU_MAX_ADU_LENGTH_ bytes and in TCP it must be
+_MODBUS_TCP_MAX_ADU_LENGTH_ bytes. If you want to write code compatible with
+both, you can use the constant _MODBUS_MAX_ADU_LENGTH_ (maximum value of all
+libmodbus backends). Take care to allocate enough memory to store responses to
+avoid crashes of your server.
+
RETURN VALUE
------------
@@ -27,6 +34,13 @@ response length if sucessful. The returned request length can be zero if the
indication request is ignored (eg. a query for another slave in RTU
mode). Otherwise it shall return -1 and set errno.
+EXAMPLE
+-------
+[source,c]
+-------------------
+uint8_t rsp[MODBUS_MAX_ADU_LENGTH];
+rc = modbus_receive_confirmation(ctx, rsp);
+-------------------
SEE ALSO
--------
15 src/modbus.h
View
@@ -97,14 +97,19 @@ MODBUS_BEGIN_DECLS
* the first MODBUS implementation on Serial Line network (max. RS485 ADU = 256
* bytes). Therefore, MODBUS PDU for serial line communication = 256 - Server
* address (1 byte) - CRC (2 bytes) = 253 bytes.
- *
- * Consequently:
- * - RS232 / RS485 ADU = 253 bytes + Server address (1 byte) + CRC (2 bytes) =
- * 256 bytes.
- * - TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes.
*/
#define MODBUS_MAX_PDU_LENGTH 253
+/* Consequently:
+ * - RTU MODBUS ADU = 253 bytes + Server address (1 byte) + CRC (2 bytes) = 256
+ * bytes.
+ * - TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes.
+ * so the maximum of both backend in 260 bytes. This size can used to allocate
+ * an array of bytes to store responses and it will be compatible with the two
+ * backends.
+ */
+#define MODBUS_MAX_ADU_LENGTH 260
+
/* Random number to avoid errno conflicts */
#define MODBUS_ENOBASE 112345678
Please sign in to comment.
Something went wrong with that request. Please try again.