-
Notifications
You must be signed in to change notification settings - Fork 50
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
Auto-detect Arduinos attached to USB serial ports #280
Conversation
Fix formatting and add a docstring.
Codecov Report
@@ 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.
|
There was a problem hiding this 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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Fix #277.
This is only lightly tested. I still need to connect a suitable Arduino to my laptop for proper testing.