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

Micropython/patch1 #212

Merged
merged 2 commits into from
Dec 27, 2022
Merged

Conversation

drbitboy
Copy link
Contributor

Refactor currently moot approach to dict pylogix.lgx_device.vendors for Micropython

Goal is minimal changes to existing code

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • I have read the docs/CONTRIBUTING.md document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read tests/README.md.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

What is the change?

An alternate approach to performing vendorID=>vendorNAME lookup for Micropython.

What does it fix/add?

Remove unnecessary mess of code in pylogix/lgx_device.Device.get_vendor(vendorID) method.

Test Configuration

  • PLC Model
  • PLC Firmware
  • pylogix version
  • python version
  • OS type and version

@drbitboy
Copy link
Contributor Author

FYI: there is a new Python source file under pylogix/ named lgx_uvendors.py.

I did not convert that to a .mpy file under upylogix/; the corresponding lgx_uvendors.mpy file under upylogix/ is empty and is intended as a placeholder only.

package.json has been modified to put the contents of upylogix/vendors.txt into a file named upylogix/lgx_uvendors.py.txt, which I hope will make finding that file easier when the open(".../lgx_uvendors.py.txt") call is made.

@TheFern2
Copy link
Collaborator

TheFern2 commented Dec 27, 2022

I like the approach followed here, so my first question would be has any of this been tested on a device?

A few comments on this PR:

  • The path when mip is used is pylogix, not upylogix.
  • os module on micropython has no __file__ so lgx_uvendors will definitely fail on look up
  • in order to make PRs for micropython please test on device before submitting the PR

@TheFern2
Copy link
Collaborator

TheFern2 commented Dec 27, 2022

For the purposes of micropython which has limited modules, please test as follow before submitting PR:

  • make changes
  • run build_mpy.sh (might need to make another bat file for windows)
  • have latest python2 and 3 on machine
  • run tox unittests (this will ensure python still working as before)
  • run micropython unix/port tests (I dunno how to do this on wsl but I made a comment on tests/README)
  • If all this passes then test on device, everything can be tested on unix port except the discover stuff since unix/port has no network module. And network module is needed to get current device ip.
  • If you commit your changes to your branch, you can then use mip and see how things are going.

@drbitboy
Copy link
Contributor Author

drbitboy commented Dec 27, 2022

* os module on micropython has no `__file__` so lgx_uvendors will definitely fail on look up

__file__ is not part of os; every python module has __file__ and __name__ variables, at least in the non-microcontroller (e.g. WSL/Ubuntu) micropython environments. Whether that works on a microcontroller will have to wait until I actually have one.

@drbitboy
Copy link
Contributor Author

I like the approach followed here, so my first question would be has any of this been tested on a device?

no, I don't have one; I have run it in the micropython repl under WSL2, which I had hoped was close to what the environment would be under a device.

Can you recommend a device?

@drbitboy
Copy link
Contributor Author

drbitboy commented Dec 27, 2022

run build_mpy.sh (might need to make another bat file for windows)

where do I find mpy-cross?

Update: never mind, got it.

@TheFern2
Copy link
Collaborator

Can you recommend a device?

I like the esp32 with the wifi module, also the raspberry pi pico.

@drbitboy
Copy link
Contributor Author

drbitboy commented Dec 27, 2022

Either way, the .keys() should be dropped from vendorID in vendors.keys() in lgx_device.Device.get_vendor as it is both slow (possibly O(N) vs O(logN)) and unnecessary.

@TheFern2 TheFern2 merged commit 8f44878 into dmroeder:micropython/patch1 Dec 27, 2022
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