Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-detect Arduinos attached to USB serial ports #280

Merged

Conversation

jamessynge
Copy link
Contributor

Fix #277.

This is only lightly tested. I still need to connect a suitable Arduino to my laptop for proper testing.

@jamessynge jamessynge requested a review from wtgee December 31, 2017 01:44
@codecov
Copy link

codecov bot commented Dec 31, 2017

Codecov Report

Merging #280 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #280   +/-   ##
========================================
  Coverage    80.66%   80.66%           
========================================
  Files           46       46           
  Lines         3207     3207           
  Branches       411      411           
========================================
  Hits          2587     2587           
  Misses         474      474           
  Partials       146      146

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ab386f...cb14947. Read the comment docs.

Copy link
Member

@wtgee wtgee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm going to approve but we should consider using the list_ports.comports() as mentioned below.


self.db = None
self.messaging = None

# Store each serial reader
self.serial_readers = dict()

if auto_detect:
if auto_detect or self.config['environment'].get('auto_detect', False):
self.logger.debug('Performing auto-detect')
for port_num in range(9):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also grab connected ports and just check those: https://pythonhosted.org/pyserial/tools.html?highlight=comport#serial.tools.list_ports.comports. We could then check vendor id and product id. The arduino uno even reports a serial_number correctly although I don't think the micros do.

That could probably help clean up some of the _auto_detect_port below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted #284 for this.

@@ -141,20 +150,20 @@ def capture(self, use_mongo=True, send_message=True):
if send_message:
self.send_message({'data': data}, channel='environment')
except yaml.parser.ParserError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I didn't know this when I wrote this a long time ago, but you can pass a tuple for except:

except (yaml.parser.ParserError, ValueError, TypeError, Exception) as e:

However if we have Exception at the end and we are not doing anything different for the different exceptions then really we just need to capture the generic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I didn't know that either, though as you say it doesn't do much to include both a class and super-class in the the same tuple.

@jamessynge jamessynge merged commit 0ac5828 into panoptes:develop Dec 31, 2017
@jamessynge jamessynge deleted the issue-277-auto-detect-arduinos branch January 1, 2018 02:32
@wtgee wtgee mentioned this pull request Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants