-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Proof-of-concept: Add network support (IPv4Transport) #243
Conversation
for more information, see https://pre-commit.ci
removing hard-coded default values
according to "Firmware and Advanced Communications: OCEAN HDX Firmware"
…breeze into IPv4Transport-support
for more information, see https://pre-commit.ci
I have been playing around with multicast, both the feature accessible via OBP and as a means to discover connected spectrometers. With the feature implementation, I ran into unexpected issues: the message types in my version of the "Firmware and Advanced Communications: OCEAN HDX Firmware" for retrieving multicast settings from the device are only triggering a "unknown message type" error. The only command of those working is The discovery via multicast looks promising and I hope to add a commit implementing a first version of that soon. Then I will be looking into the failing tests and pre-commit CI checks... |
Ok, I believe that I have multicast discovery working now :) |
…breeze into IPv4Transport-support
allows to match to correct model via known USB parameters
Thank you so much for contributing @hperrey ❤️ This looks great already. I don't have access to an HDX spectrometer (or any ocean optics/insight spectrometer with ethernet support), so I won't be able to test this, but it seems you have the important parts already running 👏 🎉 I'm currently traveling, but will allocate some time tomorrow afternoon to review your PR! Cheers, |
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 looks really great already. I made several comments.
We'd still need to expose this in seabreeze.spectrometers.list_devices
or as a new. I wonder what the nicest interface would be.
if no `network_adapter` argument has been provided. This will send the multicast request on an "appropriate" interface, usually the one with the highest metric.
improve style Co-authored-by: Andreas Poehlmann <[email protected]>
…breeze into IPv4Transport-support
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
+ fixes `mypy` errors
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
fixes `src/seabreeze/pyseabreeze/devices.py:317: error: "ABCMeta" has no attribute "supported_model" [attr-defined]`
protects against repeated runs of `list_devices` failing
All type errors are now fixed :) |
- change argument to handle from socket to ip+port - manage opening socket in handle - close socket in `list_devices`
I have changed how the socket is managed and now the interface works almost as expected:
The call to |
backend configThe way to do the configuration of a backend in the current design would be the following: python-seabreeze/src/seabreeze/backends.py Lines 60 to 67 in a8fef98
here we would need to add code like: if backend == "pyseabreeze":
if "pyusb_backend" in kwargs:
pyusb_backend = kwargs.pop("pyusb_backend")
BackendConfig.api_kwargs["pyusb_backend"] = pyusb_backend
if "network_adapter" in kwargs:
network_adapter = kwargs.pop("network_adapter")
BackendConfig.api_kwargs["network_adapter"] = network_adapter
... Then using the ethernet discovery would look like this in code: import seabreeze
seabreeze.use("pyseabreeze", network_adapter="192.168.1.200")
from seabreeze.spectrometers import Spectrometer
spec = Spectrometer.from_serial_number("...") adding lazy backend retrievalWith a small change to python-seabreeze/src/seabreeze/spectrometers.py Lines 22 to 23 in a8fef98
should be lazy: # get the backend and add some functions/classes to this module
_lib: SeaBreezeBackend
def __getattr__(name):
global _lib
if name == "_lib":
_lib = seabreeze.backends.get_backend()
return _lib
elif name == "SeabreezeDevice":
... # same for this one (right now they are eagerly created)
elif name == "SeabreezeError":
... # same for this one
else:
raise AttributeError(name) This should allow us to write code like this: import seabreeze
from seabreeze.spectrometer import Spectrometer
seabreeze.use("pyseabreeze", network_adapter="192.168.1.200")
spec = Spectrometer.from_serial_number("...") |
Yes, this approach works!
The approach with lazy loading would require to create For now, I think I am satisfied with what 0e5a59b brings to the table. The tests still fail though, mainly due to the |
I have tried connecting to the HDX using my Ubuntu laptop but ran into #133 .. ethernet, on the other hand, works fine :) |
This is great! I am happy to merge this. For now I would remove the extra functionality you added to the Multicast Feature (the 3 methods the tests complain about), to keep feature parity with cseabreeze. (Although it might not really be enabled at all there...) We can add it back later down the line. I will add some text to the readme with a code snippet example. fyi, the multicast get state / set state feature in cseabreeze uses these two command codes: Lines 86 to 87 in a8fef98
Lines 38 to 44 in a8fef98
Lines 39 to 47 in a8fef98
Let me know if you still want to make changes, or if I should take over and merge and prepare a new release! Cheers, |
Great! I'd be more than fine with you going forward with the merge and release -- thank you! I might revisit the multicast feature, but more importantly I would like to work with the buffered readout that the HDX allows. But that is for another day and PR :) |
This PR adds basic support for a network transport by adding the necessary classes
IPv4Transport
andIPv4TransportHandle
that communicate oversocket
to thepyseabreeze
backend.It supports multicast to discover devices on the local network. Tests were done using an HDX spectrometer connected via ethernet (direct link).
Please note that this is a best-effort proof-of-concept at this point:
nofew exceptions from thesocket
library are handled yetthere is no discovery of devices, only registration of known devices viaapi.add_ipv4_device_location
; this could be replaced by multicast discoverytheHDX
device is hard-coded toIPv4Transport
; having both transports there caused issuessome methods are basically placeholders and still require implementationFeedback on proper integration into the framework and best-practices welcome!
Sample run:
(note that I replaced the serial in the output above)
Left to be done:
shutdown
andinitialize
ofIPv4Transport
(or removeTODO
comment)Addresses #240.