diff --git a/documentation/changelog.md b/documentation/changelog.md index e43fdcc..15507de 100644 --- a/documentation/changelog.md +++ b/documentation/changelog.md @@ -1,5 +1,14 @@ # Change Log +## Release 2.16 + +24 Auguts 2016 + +* This is a minor bug fix release + + * Added a 2 second timeout for retrieiving Firmata Firmware Verison + * If the request times out, the application will exit since there is no connectivity to the Arduino. + ## Release 2.15 31 July 2016 diff --git a/pymata_aio/private_constants.py b/pymata_aio/private_constants.py index d04f2ca..9078de9 100644 --- a/pymata_aio/private_constants.py +++ b/pymata_aio/private_constants.py @@ -71,7 +71,7 @@ class PrivateConstants: SYSEX_REALTIME = 0x7F # MIDI Reserved for realtime messages # reserved for PyMata - PYMATA_VERSION = "2.15" + PYMATA_VERSION = "2.16" # each byte represents a digital port # and its value contains the current port settings diff --git a/pymata_aio/pymata_core.py b/pymata_aio/pymata_core.py index 48c9871..fed59d6 100644 --- a/pymata_aio/pymata_core.py +++ b/pymata_aio/pymata_core.py @@ -401,6 +401,35 @@ async def start_aio(self): # get arduino firmware version and print it firmware_version = await self.get_firmware_version() + if not firmware_version: + if self.log_output: + log_string = '*** Firmware Version retrieval timed out. ***' + + logging.exception(log_string) + log_string = '\nDo you have Arduino connectivity and do you ' \ + 'have a Firmata sketch uploaded to the board?' + logging.exception(log_string) + + else: + print('*** Firmware Version retrieval timed out. ***') + print('\nDo you have Arduino connectivity and do you have a ' + 'Firmata sketch uploaded to the board?') + try: + loop = self.loop + for t in asyncio.Task.all_tasks(loop): + t.cancel() + loop.run_until_complete(asyncio.sleep(.1)) + loop.stop() + loop.close() + sys.exit(0) + except RuntimeError: + self.the_task.cancel() + time.sleep(1) + # this suppresses the Event Loop Is Running message, + # which may be a bug in python 3.4.3 + sys.exit(0) + except TypeError: + sys.exit(0) if self.log_output: log_string = "\nArduino Firmware ID: " + firmware_version logging.exception(log_string) @@ -720,10 +749,14 @@ async def get_firmware_version(self): :returns: Firmata firmware version """ + current_time = time.time() if self.query_reply_data.get(PrivateConstants.REPORT_FIRMWARE) == '': await self._send_sysex(PrivateConstants.REPORT_FIRMWARE, None) while self.query_reply_data.get( PrivateConstants.REPORT_FIRMWARE) == '': + elapsed_time = time.time() + if elapsed_time - current_time > 2: + return None await asyncio.sleep(self.sleep_tune) reply = '' for x in self.query_reply_data.get(PrivateConstants.REPORT_FIRMWARE): diff --git a/setup.py b/setup.py index d584c6e..8766cee 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='pymata-aio', - version='2.15', + version='2.16', packages=['pymata_aio'], install_requires=['pyserial==2.7', 'websockets'], url='https://github.com/MrYsLab/pymata-aio/wiki',