Commit ddb2200377565bd8da694e125c4e89e415b15749
1 parent
3c459bc1
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. ------------------------
Showing
2 changed files
with
5 additions
and
2 deletions
NEWS
| 1 | -libmodbus 2.9.3 (2010-12-XX) | 1 | +libmodbus 2.9.3 (2011-01-XX) |
| 2 | ============================ | 2 | ============================ |
| 3 | 3 | ||
| 4 | +- Fix unit identifier not copied by the TCP server. | ||
| 5 | + Reported by Antti Manninen. | ||
| 4 | - New function to reply to an indication with an exception message | 6 | - New function to reply to an indication with an exception message |
| 5 | modbus_reply_exception() | 7 | modbus_reply_exception() |
| 6 | - Fix missing modbus_flush() in unit tests | 8 | - Fix missing modbus_flush() in unit tests |
src/modbus-tcp.c
| @@ -141,7 +141,8 @@ int _modbus_tcp_build_response_basis(sft_t *sft, uint8_t *rsp) | @@ -141,7 +141,8 @@ int _modbus_tcp_build_response_basis(sft_t *sft, uint8_t *rsp) | ||
| 141 | 141 | ||
| 142 | /* Length will be set later by send_msg (4 and 5) */ | 142 | /* Length will be set later by send_msg (4 and 5) */ |
| 143 | 143 | ||
| 144 | - rsp[6] = 0xFF; | 144 | + /* The slave ID is copied from the indication */ |
| 145 | + rsp[6] = sft->slave; | ||
| 145 | rsp[7] = sft->function; | 146 | rsp[7] = sft->function; |
| 146 | 147 | ||
| 147 | return _MODBUS_TCP_PRESET_RSP_LENGTH; | 148 | return _MODBUS_TCP_PRESET_RSP_LENGTH; |