Skip to content
Permalink
Browse files

early logging in OPP. more debug output

  • Loading branch information...
jabdoa2 committed Jul 20, 2019
1 parent 5ce27ba commit 9262983dd8b207aa5ae546cd6d9e7672b1b9d64c
Showing with 39 additions and 23 deletions.
  1. +28 −15 mpf/platforms/base_serial_communicator.py
  2. +11 −8 mpf/platforms/opp/opp_serial_communicator.py
@@ -98,8 +98,34 @@ def readuntil(self, separator, min_chars: int = 0):
char = yield from self.reader.readexactly(1)
buffer += char
if char == separator and len(buffer) > min_chars:
if self.debug:
self.log.debug("%s received: %s (%s)", self, buffer, "".join(" 0x%02x" % b for b in buffer))
return buffer

@asyncio.coroutine
def read(self, n=-1):
"""Read up to `n` bytes from the stream and log the result if debug is true.
See :func:`StreamReader.read` for details about read and the `n` parameter.
"""
try:
resp = yield from self.reader.read(n)
except asyncio.CancelledError: # pylint: disable-msg=try-except-raise
raise
except Exception as e: # pylint: disable-msg=broad-except
self.log.warning("Serial error: {}".format(e))
return None

# we either got empty response (-> socket closed) or and error
if not resp:
self.log.warning("Serial closed.")
self.machine.stop("Serial {} closed.".format(self.port))
return None

if self.debug:
self.log.debug("%s received: %s (%s)", self, resp, "".join(" 0x%02x" % b for b in resp))
return resp

@asyncio.coroutine
def _identify_connection(self):
"""Initialise and identify connection."""
@@ -142,20 +168,7 @@ def __repr__(self):
@asyncio.coroutine
def _socket_reader(self):
while True:
try:
resp = yield from self.reader.read(100)
except asyncio.CancelledError: # pylint: disable-msg=try-except-raise
raise
except Exception as e: # pylint: disable-msg=broad-except
self.log.warning("Serial error: {}".format(e))
resp = None

# we either got empty response (-> socket closed) or and error
if not resp:
self.log.warning("Serial closed.")
self.machine.stop("Serial {} closed.".format(self.port))
resp = yield from self.read(128)
if resp is None:
return

if self.debug:
self.log.debug("%s received: %s (%s)", self, resp, "".join(" 0x%02x" % b for b in resp))
self._parse_msg(resp)
@@ -35,17 +35,17 @@ def _identify_connection(self):
# keep looping and wait for an ID response
count = 0
# read and discard all messages in buffer
self.writer.write(OppRs232Intf.EOM_CMD)
self.send(OppRs232Intf.EOM_CMD)
yield from asyncio.sleep(.01, loop=self.machine.clock.loop)
yield from self.reader.read(1000)
yield from self.read(1000)
while True:
if (count % 10) == 0:
self.log.debug("Sending EOM command to port '%s'",
self.port)
count += 1
self.writer.write(OppRs232Intf.EOM_CMD)
self.send(OppRs232Intf.EOM_CMD)
yield from asyncio.sleep(.01, loop=self.machine.clock.loop)
resp = yield from self.reader.read(30)
resp = yield from self.read(30)
if resp.startswith(OppRs232Intf.EOM_CMD):
break
if count == 100:
@@ -62,7 +62,7 @@ def _identify_connection(self):
cmd = bytes(msg)

self.log.debug("Sending inventory command: %s", "".join(" 0x%02x" % b for b in cmd))
self.writer.write(cmd)
self.send(cmd)

resp = yield from self.readuntil(b'\xff')

@@ -90,14 +90,17 @@ def _identify_connection(self):
self._create_vers_str(self.platform.minVersion)))

# get initial value for inputs
self.writer.write(self.platform.read_input_msg[self.chain_serial])
self.log.debug("Getting initial inputs states for %s", self.chain_serial)
self.send(self.platform.read_input_msg[self.chain_serial])
cards = len([x for x in self.platform.opp_inputs if x.chain_serial == self.chain_serial])
while True:
resp = yield from self.readuntil(b'\xff')
cards -= self._parse_msg(resp)
if cards <= 0:
break
self.log.debug("Waiting for another %s cards", cards)

self.log.info("Init of OPP board %s done", self.chain_serial)
self.platform.register_processor_connection(self.chain_serial, self)

def send_get_gen2_cfg_cmd(self):
@@ -117,7 +120,7 @@ def send_get_gen2_cfg_cmd(self):
whole_msg.extend(OppRs232Intf.EOM_CMD)
cmd = bytes(whole_msg)
self.log.debug("Sending get Gen2 Cfg command: %s", "".join(" 0x%02x" % b for b in cmd))
self.writer.write(cmd)
self.send(cmd)

def send_vers_cmd(self):
"""Send get firmware version message."""
@@ -136,7 +139,7 @@ def send_vers_cmd(self):
whole_msg.extend(OppRs232Intf.EOM_CMD)
cmd = bytes(whole_msg)
self.log.debug("Sending get version command: %s", "".join(" 0x%02x" % b for b in cmd))
self.writer.write(cmd)
self.send(cmd)

@classmethod
def _create_vers_str(cls, version_int): # pragma: no cover

0 comments on commit 9262983

Please sign in to comment.
You can’t perform that action at this time.