From 81aa282aa88ec714a4e7dd8c44422726c5d9c916 Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Fri, 25 Mar 2016 10:17:54 +0100 Subject: [PATCH] Add modbus address in the debug trace --- sunspec/core/modbus/client.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sunspec/core/modbus/client.py b/sunspec/core/modbus/client.py index fb13a6e..eecc6c1 100644 --- a/sunspec/core/modbus/client.py +++ b/sunspec/core/modbus/client.py @@ -138,7 +138,7 @@ def _read(self, slave_id, addr, count, op=FUNC_READ_HOLDING, trace_func=None): req += struct.pack('>H', computeCRC(req)) if trace_func: - s = '%s:%s ->' % (self.name, str(slave_id)) + s = '%s:%s[addr=%s] ->' % (self.name, str(slave_id), addr) for c in req: s += '%02X' % (ord(c)) trace_func(s) @@ -165,7 +165,7 @@ def _read(self, slave_id, addr, count, op=FUNC_READ_HOLDING, trace_func=None): raise ModbusClientTimeout('Response timeout') if trace_func: - s = '%s:%s <--' % (self.name, str(slave_id)) + s = '%s:%s[addr=%s] <--' % (self.name, str(slave_id), addr) for c in resp: s += '%02X' % (ord(c)) trace_func(s) @@ -216,7 +216,7 @@ def _write(self, slave_id, addr, data, trace_func=None): req += struct.pack('>H', computeCRC(req)) if trace_func: - s = '%s:%s ->' % (self.name, str(slave_id)) + s = '%s:%s[addr=%s] ->' % (self.name, str(slave_id), addr) for c in req: s += '%02X' % (ord(c)) trace_func(s) @@ -243,7 +243,7 @@ def _write(self, slave_id, addr, data, trace_func=None): raise ModbusClientTimeout('Response timeout') if trace_func: - s = '%s:%s <--' % (self.name, str(slave_id)) + s = '%s:%s[addr=%s] <--' % (self.name, str(slave_id), addr) for c in resp: s += '%02X' % (ord(c)) trace_func(s) @@ -377,7 +377,7 @@ def _read(self, addr, count, op=FUNC_READ_HOLDING): req = struct.pack('>HHHBBHH', 0, 0, TCP_READ_REQ_LEN, int(self.slave_id), op, int(addr), int(count)) if self.trace_func: - s = '%s:%s:%s ->' % (self.ipaddr, str(self.ipport), str(self.slave_id)) + s = '%s:%s:%s[addr=%s] ->' % (self.ipaddr, str(self.ipport), str(self.slave_id), addr) for c in req: s += '%02X' % (ord(c)) self.trace_func(s) @@ -407,7 +407,7 @@ def _read(self, addr, count, op=FUNC_READ_HOLDING): except_code = ord(resp[TCP_HDR_LEN + 2]) if self.trace_func: - s = '%s:%s:%s <--' % (self.ipaddr, str(self.ipport), str(self.slave_id)) + s = '%s:%s:%s[addr=%s] <--' % (self.ipaddr, str(self.ipport), str(self.slave_id), addr) for c in resp: s += '%02X' % (ord(c)) self.trace_func(s) @@ -461,7 +461,7 @@ def _write(self, addr, data): req += data if self.trace_func: - s = '%s:%s:%s ->' % (self.ipaddr, str(self.ipport), str(self.slave_id)) + s = '%s:%s:%s[addr=%s] ->' % (self.ipaddr, str(self.ipport), str(self.slave_id), addr) for c in req: s += '%02X' % (ord(c)) self.trace_func(s) @@ -491,7 +491,7 @@ def _write(self, addr, data): except_code = ord(resp[TCP_HDR_LEN + 2]) if self.trace_func: - s = '%s:%s:%s <--' % (self.ipaddr, str(self.ipport), str(self.slave_id)) + s = '%s:%s:%s[addr=%s] <--' % (self.ipaddr, str(self.ipport), str(self.slave_id), addr) for c in resp: s += '%02X' % (ord(c)) self.trace_func(s)