-
Notifications
You must be signed in to change notification settings - Fork 13
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
Identifying juami #133
base: master
Are you sure you want to change the base?
Identifying juami #133
Conversation
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it print that the pytenstiostat is connected to the port after telling you that the board is not a pytentiostat.
…inux machine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it print that the pytenstiostat is connected to the port after telling you that the board is not a pytentiostat." This reverts commit 0cca2c8.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it allows you to run the config file after telling you that the board is not a pytentiostat.
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.
nice changes @dimacio thanks so much.
Before merging we need to guard against unexpected behavior and make sure this doesn't break the operations of the JUAMI potentiostats. @dimacio Please could you try and write some tests that try and break this and make sure it doesn't break. Do you know how to write tests? We are using pytest. @aplymill7 @jlhitt1993 @mspence2 , please could one of you try an run one of our JUAMI built potentiostats from this code and make sure it works?
pytentiostat/routines.py
Outdated
if re.match(r'tty|Arduino|COM',p.description) is not None: | ||
com = p.device | ||
n_arduinos += 1 |
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 believe this gives false positives of Arduinos connected if this regular expression matches anythin with tty OR Arduino OR COM. Unless I'm reading the expression incorrectly, can we make this more specific so it more precisely identifies if it is an Arduino that is connected?
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.
This was done to solve my problem to recognize the board in linux. The identification was performed in the 46 and 47
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 should move that part into load_arduino (right after this) then cause we iterate number of arduinos here.
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 have done it to recognize my port
@@ -38,14 +38,16 @@ def _initialize_arduino(com): | |||
Creates board object with Arduino(). If the connection fails it prints an error message and exits. | |||
Parameters | |||
---------- | |||
com: string |
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.
Not sure why this part of doc string is deleted.
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.
Sorry, that was an error.
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.
that was a mistake
pytentiostat/routines.py
Outdated
print("Pytentiostat connected to {}.\n".format( | ||
if board.firmware == 'pytentiostat_firmata.ino': | ||
print("Pytentiostat connected to {}.\n".format( | ||
com)) | ||
else: | ||
print('the board is not a Pytentiostat') |
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.
Ah okay this is good way to check if it is a pytentiostat.
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.
Yes, this is the true change.
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.
This is a good addition 👍 Right now you are working on the code that runs entirely in the command line but we have another version in the GUI folder that has a GUI and works differently. I think it would be great if you could implement this functionality there as well.
Appears to work on my end with some brief testing, but a few more comments:
|
@dimacio this seems to be failing tests. |
Thanks @aplymill7 for the feedback. I will pass the code to load_arduino () and study pytest to adapt the checkpoint to this new condition. |
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it print that the pytenstiostat is connected to the port after telling you that the board is not a pytentiostat.
…inux machine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it print that the pytenstiostat is connected to the port after telling you that the board is not a pytentiostat." This reverts commit 0cca2c8.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it allows you to run the config file after telling you that the board is not a pytentiostat.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
…ing_juami # Conflicts: # pytentiostat/routines.py
Codecov Report
@@ Coverage Diff @@
## master #133 +/- ##
=========================================
Coverage ? 73.22%
=========================================
Files ? 8
Lines ? 295
Branches ? 0
=========================================
Hits ? 216
Misses ? 79
Partials ? 0
Continue to review full report at Codecov.
|
I tried to correct the original code to end the execution when the potentiate is not recognized and adapt the tests to recognize this change. It worked fine on my machine, but when I uploaded the changes I had an error with codecov. Could you please tell me how to solve it? |
@dimacio I haven't seen this error before, but maybe linked with losing track of base commit (https://docs.codecov.io/docs/error-reference#section-missing-base-commit)? Maybe could be problem when you merged another branch onto the pushed branch? Could perhaps revert that commit, and then try to implement the changes on the fork with the base commit directly? |
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.
@dimacio it looks great to me, thanks! I can't test the functionality but I made a couple of comments.
tests/test_routines.py
Outdated
@@ -38,7 +38,7 @@ def test_load_arduino(): | |||
def test_initialize_arduino(): | |||
da = Dummy_arduino() | |||
da.name = "good_arduino" | |||
|
|||
da.firmware = "pytentiostat_firmata.ino" |
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.
this doesn't seem to be tested. We would need some assert statements that test different scenarios.
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 pushed a new version with an assert statement to test. I think that the negative check has been already covered in line 42 of test_routines.py, I'm wrong?
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.
you are testing desired behavior of the app. So answer these questions:
What do you want the program to do if da.firmware is the wrong value?
or None?
or even the right value? Right now we are not really testing anything because we set an attribute to something then ask if it is that thing.
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.
Now I think I got it. Create two different instances, one that has the correct firmware and one that doesn't. The good arduino should return his name and the bad one should raise an error.
pytentiostat/routines.py
Outdated
except: | ||
sys.exit("Error. Could not open COM port") | ||
|
||
if board.firmware == 'pytentiostat_firmata.ino': # check if the board have the right firmware | ||
print("Pytentiostat connected to {}.\n".format( |
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.
why do you end this with a line-break? In general we like to keep any output compact (and minimal). Dislike chatty programs. Prefer better designed internals....
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.
sorry, it was a typing mistake
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.
👍 no need to apologize....
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
@aplymill7 I think I could solve the problem by returning to an earlier version of the master branch. |
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
@dimacio please can you make your commit messages meaningful? It is important for them to describe what is in the commit. To understand why, type |
@sbillinge i changed the commit message according to the numpy workflow. Is clearly enough now? |
Thanks @dimacio that is much better. Please keep it up! We should have a little discussion with @aplymill7 and others in the team about the tests. How do we want the program to behave under different scenarios of the board returning different things to ``initialize_arduino()". Once we have this sorted it will be very quick to write the tests and tweak the code the pass the tests and this can be merged.
|
@dimacio actually rereading the commit message it isn't quite right. First, it seems to be describing the topic of the whole PR and not the topic of that particular commit. Second, it is a bit general and not specific. what functionality? What is the issue with recognizing the potentiostat is it solving? Don't bother changing old commit messages, it is not worth the time here, but I am just trying to nudge you towards the right direction in the workflow. Your contributions are really appreciated, this is not meant to be criticism, but it helps the project to have high quality code, and that includes documentation in the code and around the commits and the releases. Thanks so much for your efforts! |
Ah yes we can discuss this more. I'll look over the logic and start making a comprehensive list of things that can happen and what the expected response should be in each scenario. |
Here's what I came up with what should happen when executing startup routine, in which initialize_arduino is a part of.
If you think there should be edits please let me know! |
just one suggestion to think about. When the program exits always put in
the message ``ERROR: blah blah`` and when it doesn't exit put ``WARNING:
blah blah``. If it is just general chatter put ``INFO: blah blah``
S
…On Thu, Jan 16, 2020 at 1:49 PM aplymill7 ***@***.***> wrote:
Here's what I came up with what should happen when executing startup
routine, in which initialize_arduino is a part of.
1. After ports listed that should correspond with our device are
listed one of the following should happen:
1a) If a single port is connected to an Arduino Uno and the port’s
name is X, print “Arduino Uno found at port X”
1b) If multiple ports are connected to Arduino Unos then print “More
than one Arduino Uno found. Exiting…” and then system exit
1c) If no port is found to be connected to an Arduino Uno then print
“No Arduino Uno found. Exiting…” and then system exit.
2. If starting the board object fails, then print “Error. Could not
open port Arduino Uno is connected to. Exiting…” and then system exit.
3. If the board doesn’t have the correct firmware then the system
should prompt “Arduino Uno connected does not have correct firmware
uploaded. Exiting…” and then system exit.
4. If iterator fails, prompt “Iterator failed to start. Exiting…” and
then system exit.
5. If pin assignment fails, prompt “Failure to assign pins. Exiting…”
and then system exit.
If you think there should be edits please let me know!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#133?email_source=notifications&email_token=ABAOWUKWT2SI5JXRTZH3BZTQ6CT4XA5CNFSM4J4MOPX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJFD7KQ#issuecomment-575291306>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAOWUM24P2X53UMVX47XYDQ6CT4XANCNFSM4J4MOPXQ>
.
--
Professor Simon Billinge
Columbia University
|
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it allows you to run the config file after telling you that the board is not a pytentiostat.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
…hine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. At last I change the test_routines.py to recognized the firmware.
Messages changed to recognize the possible problems in the startup routine.
@aplymill7 I changed the messages according to your suggestion, I didn't do the points 4 and 5 because i want to finished de identifying problem before further changes to keep the branch as granular as possible. I should adjust the test to this new version of the routines? |
@sbillinge The commit messages are more appropriate this time? |
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.
Thanks @dimacio the messages are much better. Please see the inline comments.
pytentiostat/routines.py
Outdated
except: | ||
sys.exit("Error. Could not open COM port") | ||
sys.exit("Error: Could not open port Arduino Uno is connected to. Exiting…") |
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.
ERROR
pytentiostat/routines.py
Outdated
sys.exit("Error: Could not open port Arduino Uno is connected to. Exiting…") | ||
|
||
if board.firmware == 'pytentiostat_firmata.ino': # check if the board have the right firmware | ||
print("INFO: Pytentiostat connected to {}.\n".format(com)) |
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.
pls remove line-break
Messages changed to standardize the alerts.
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.
Thanks @dimacio
The last thing that I think is needed is some more testing. You have made a nice mocked good and bad arduino, but you are not really testing that the code behaves the way you want it to when it retrieves the bad arduino. Also, there is no testing of the regular expression etc. A few more asserts would be great before we merge.
Thanks so much for htis.
pytentiostat/routines.py
Outdated
if re.search("tty|Arduino Uno|COM",p.description) is not None: | ||
com = p.device | ||
n_arduinos += 1 | ||
print("INFO: Arduino Uno found at port.\n".format(com)) |
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.
This increases n_arduinos by 1 for every COM device connected to the computer. It needs to be specific for finding arduinos only. Could you tell us what string does your system return for p.description
when p
is the arduino? Maybe we can help here.
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.
Yes of course, the system return "ttyACM0". I guess that is because I'm using a Linux machine.
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.
Also, we should test the scenario if one of the USBs has a device connected at the same time as an arduino, especially if the port would be listed before the one at the arduino. For instance if we want to use the check description case if opening serial connection or check description fails, should try another port that matched the search. Maybe search should make a list of possibly compatible devices.
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.
After looking on google, it looks like the Arduino Uno description will usually show up in linux as "ttyACMX". On windows it shows up as "Arduino Uno (COMX)". Maybe the best thing to do here is...
if re.search("ttyAMC|Arduino Uno", p.description) is not None: ...
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 guess last one is mac case?
sys.exit("Error. Could not open COM port") | ||
sys.exit("ERROR: Could not open port Arduino Uno is connected to. Exiting…") | ||
|
||
if board.firmware == 'pytentiostat_firmata.ino': # check if the board have the right firmware |
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.
On my system, board.firmware
returns "pytent_firm.ino". Not sure why it's different.
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 don't sure but maybe you could have changed the name of the firmware uploaded in the arduino? I used the one uploaded here https://github.com/juami/potentiostat_firmata.
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.
Oh I see. The name must have changed when we made that repository. I will update mine.
Before getting too deeply into this we might want to think about which use
cases we want to support and behavior we want. For example, it’s OK to just
support one device on one USB etc.
On Sat, Feb 1, 2020 at 3:23 PM aplymill7 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pytentiostat/routines.py:
> + if re.search("tty|Arduino Uno|COM",p.description) is not None:
com = p.device
n_arduinos += 1
+ print("INFO: Arduino Uno found at port.\n".format(com))
Also, we should test the scenario if one of the USBs has a device
connected at the same time as an arduino, especially if the port would be
listed before the one at the arduino. For instance if we want to use the
check description case if opening serial connection or check description
fails, should try another port that matched the search. Maybe search should
make a list of possibly compatible devices.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#133?email_source=notifications&email_token=ABAOWUIGBQTXKKGBJ3WSZWLRAXK3XA5CNFSM4J4MOPX2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCT4ZYVY#discussion_r373800330>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAOWUPAK3P2QZRAT2RHE5DRAXK3XANCNFSM4J4MOPXQ>
.
--
Professor Simon Billinge
Columbia University
|
Yeah that's fine if we want to support one device on one USB. I just wanted to not limit if a user had something else plugged into another port (i. e. not that our program has to work simultaneously with that port, but would it stop one device one usb from working). Like how would it handle if a flash drive is in a usb, or they have some other device connected that might give ours a false positive, but crash when trying to run? |
@aplymill7 For the second part, I think that the firmware check will be pretty robust. It should only fail if someone has another Arduino Uno with the same firmware plugged in. As far as our program messing with other USB devices, it seems like |
Yeah maybe not a problem, I just haven't robustly checked. I know we catch later down the line with firmware check, but if a correct device is still possibly connected, it would be nice if the program connected to the correct device instead of hard exiting after the first device fails the firmware check. |
Right. Right now it is only allowing the user to continue if one and only one Arduino Uno is connected. Seems safe for now but you can create an issue to add functionality to accommodate multiple Arduino Unos in the future. |
This could be ok. Only worry about the more complicated UC if someone
requests it....
…On Sat, Feb 1, 2020 at 4:24 PM Jeremy Hitt ***@***.***> wrote:
Right. Right now it is only allowing the user to continue if one and only
one Arduino Uno is connected. Seems safe for now but you can create an
issue to add functionality to accommodate multiple Arduino Unos in the
future.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#133?email_source=notifications&email_token=ABAOWUN53ABDBYV7752XBI3RAXR7XA5CNFSM4J4MOPX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKRG7SQ#issuecomment-581070794>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAOWUND3M5Y4XMMULVLR4DRAXR7XANCNFSM4J4MOPXQ>
.
--
Professor Simon Billinge
Columbia University
|
Sorry but it is not clear to me how I should continue. The boot version is ok? Should I modify it to restrict the strings accepted in the regular expression? Or should I proceed to develop more accurate tests to control the cases proposed so far? |
Hi @dimacio I think there is a discussion that needs to take place about
how we want the software to behave before we know exactly what needs to be
done next. When that conversation is converged then the path forward is
to write tests that test for that behavior, then to write code until the
tests pass.
For the discussion, my suggestion is to support less, then implement more,
functionality when it is needed/asked for. i.e., implement the mvp
(minimum viable product). I am not sure what that is here....just one
serial device plugged in to a USB?
Whatever we decide, we want the program to be more friendly to the user
rather than less friendly, so if we decide the above, and the user tries to
use it with two devices plugged in, our code could either just crash, or it
could detect two devices and then gently tell the user that this is not
supported yet and would they mind unplugging the non pytentiostat one, for
example. On the whole it is often better to avoid the program doing
magic. That always seems like a good idea, but quickly gets difficult to
debug. These are just general comments. I think Austin and Jeremy and the
team need to just discuss and make some executive decisions here.
Sy
…On Sun, Feb 2, 2020 at 9:58 AM dimacio ***@***.***> wrote:
Sorry but it is not clear to me how I should continue. The boot version is
ok? Should I modify it to restrict the strings accepted in the regular
expression? Or should I proceed to develop more accurate tests to control
the cases proposed so far?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#133?email_source=notifications&email_token=ABAOWUOE35S44USGWDQLAHDRA3NSJA5CNFSM4J4MOPX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKRYXSY#issuecomment-581143499>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAOWUPQCH7ISKCURJPZZDLRA3NSJANCNFSM4J4MOPXQ>
.
--
Professor Simon Billinge
Columbia University
|
I agree with supporting the minimum for now. I would suggest changing line 26 based on the comment I left above and if more than one Arduino Uno is detected, then just let the script print "ERROR: More than one Arduino Uno found. Please unplug any other Arduinos and retry." then exit. |
Yeah support for minimum seems fine. |
Modify the regular expression to recognize only the desired ports
I had to change _load_arduino () to recognize my port in my Linux machine. Then I add a new checkpoint to verify that the firmware correspond to the one we want. I had to remove the declaration of the pin 9 as out in the setup the pytentiostat_firmata.ino to use the board.firmware attribute because with the original it returns None. I don't know if it's a little confusing the result because if the wrong firmata was uploaded into the board it allows you to run the config file after telling you that the board is not a pytentiostat.