Parcourir la source

Fix unit identifier not copied by the TCP server

Reported by Antti Manninen and according to Page6 in the document
"MODBUS Messaging on TCP/IP Implementation Guide V1.0b",
------------------------
Unit Identifier – This field is used for intra-system routing purpose.
It is typically used to communicate to a MODBUS+ or a MODBUS serial
line slave through a gateway between an Ethernet TCP-IP network and
a MODBUS serial line. This field is set by the MODBUS Client in the
request and must be returned with the same value in the response by
the server.
------------------------
Stéphane Raimbault il y a 14 ans
Parent
commit
ddb2200377
2 fichiers modifiés avec 5 ajouts et 2 suppressions
  1. 3 1
      NEWS
  2. 2 1
      src/modbus-tcp.c

+ 3 - 1
NEWS

@@ -1,6 +1,8 @@
-libmodbus 2.9.3 (2010-12-XX)
+libmodbus 2.9.3 (2011-01-XX)
 ============================
 
+- Fix unit identifier not copied by the TCP server.
+  Reported by Antti Manninen.
 - New function to reply to an indication with an exception message
   modbus_reply_exception()
 - Fix missing modbus_flush() in unit tests

+ 2 - 1
src/modbus-tcp.c

@@ -141,7 +141,8 @@ int _modbus_tcp_build_response_basis(sft_t *sft, uint8_t *rsp)
 
     /* Length will be set later by send_msg (4 and 5) */
 
-    rsp[6] = 0xFF;
+    /* The slave ID is copied from the indication */
+    rsp[6] = sft->slave;
     rsp[7] = sft->function;
 
     return _MODBUS_TCP_PRESET_RSP_LENGTH;