Skip to content

Commit

Permalink
Merge pull request #10 from bbinet/trace-addr
Browse files Browse the repository at this point in the history
Add modbus address in the debug trace
  • Loading branch information
bobfox authored Feb 13, 2017
2 parents 497d0b1 + 81aa282 commit 16b9da5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sunspec/core/modbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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)
Expand All @@ -181,7 +181,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)
Expand Down Expand Up @@ -232,7 +232,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)
Expand All @@ -259,7 +259,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)
Expand Down Expand Up @@ -393,7 +393,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)
Expand Down Expand Up @@ -423,7 +423,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)
Expand Down Expand Up @@ -477,7 +477,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)
Expand Down Expand Up @@ -507,7 +507,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)
Expand Down

0 comments on commit 16b9da5

Please sign in to comment.