>From eaf5ae863e3999280a570b17bf3ef3c34d586cf9 Mon Sep 17 00:00:00 2001
From: Victor Rocco <victor_rocco@hotmail.com>
Date: Wed, 3 Oct 2012 08:53:26 -0300
Subject: [PATCH] Fix modbus tcp protocol

Prevents getting error "ERROR Communication time out" in HAL.
A slave device that checks the "slave number" in the modbus protocol
will not respond in the actual behavior, including the Delta's
RTU-EN01 remote I/O device.
Oficial modbus protocol specifies that.

The fix is: use slave number parameter instead of 0xFF in
build_request_packet_tcp(...)

Checks:
* Against a Delta RTU-EN01 remote I/O device.
* Against same file (modbus.c) RTU protocol, function
  build_request_packet_rtu(...)
* Against libmodbus 3.1.0 (www.libmodbus.org) low level frame debug.
* Oficial Modbus protocol specification (www.modbus.org).

Signed-off-by: Victor Rocco <victor_rocco@hotmail.com>
---
 src/hal/user_comps/modbus.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/hal/user_comps/modbus.c b/src/hal/user_comps/modbus.c
index ed213c2..89bef44 100644
--- a/src/hal/user_comps/modbus.c
+++ b/src/hal/user_comps/modbus.c
@@ -209,7 +209,7 @@ int build_request_packet_tcp(int slave, int function, int start_addr,
 
   /* Length to fix later with set_packet_length_tcp (4 and 5) */
 
-  packet[6] = 0xFF;
+  packet[6] = slave;
   packet[7] = function;
   packet[8] = start_addr >> 8;
   packet[9] = start_addr & 0x00ff;
-- 
1.7.0.4

