serialhdl: Make SerialReader.connect() blocking

Use the greenlet mechanism to wait for the connection to come up in
the serial connect() method.  This simplifies the calling code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-11-27 17:45:58 -05:00
parent 5d805ba550
commit 535c7b99b4
4 changed files with 34 additions and 42 deletions

View file

@ -342,15 +342,8 @@ class MCU:
self._steppersync = self.ffi_lib.steppersync_alloc(
self.serial.serialqueue, stepqueues, len(stepqueues), count)
def connect(self):
state_params = {}
def handle_serial_state(params):
state_params.update(params)
self.serial.register_callback(handle_serial_state, '#state')
self.serial.connect()
while state_params.get('#state') != 'connected':
self._printer.reactor.pause(time.time() + 0.05)
self.serial.unregister_callback('#state')
logging.info("serial connected")
if not self._is_fileoutput:
self.serial.connect()
self._mcu_freq = float(self.serial.msgparser.config['CLOCK_FREQ'])
self.register_msg(self.handle_shutdown, 'shutdown')
self.register_msg(self.handle_shutdown, 'is_shutdown')
@ -358,7 +351,6 @@ class MCU:
def connect_file(self, debugoutput, dictionary, pace=False):
self._is_fileoutput = True
self.serial.connect_file(debugoutput, dictionary)
self._mcu_freq = float(self.serial.msgparser.config['CLOCK_FREQ'])
def dummy_send_config():
for c in self._config_cmds:
self.send(self.create_command(c))