python-seabreeze
python-seabreeze copied to clipboard
pyseabreeze: OBPProtocol.receive docstring is incorrect
spectrometer and system information
- model: (FX, and other models which use OBP protocol)
- operating system: (Ubuntu 20.04 64 bit)
- python version: (3.8.5)
- python-seabreeze version: (current master)
- installed-via: (python setup.py install)
current problem
Attempted to add Ocean FX support to pyseabreeze, but the communications were timing out. Seemed like messages or responses might be incorrect sizes. Looked at code and saw this in the pyseabreeze.protocol.OBP.receive() method:
def receive(self, size=None, timeout_ms=None, **kwargs):
"""receive data from the spectrometer
Parameters
----------
size : int, optional
number of bytes to receive. if `None` (default) uses the
default size as specified in the transport layer.
timeout_ms : int, optional
the timeout after which the transport layer should error.
`None` means no timeout (default)
kwargs :
ignored and only present to provide compatible caller interfaces
Returns
-------
data : str
data returned from the spectrometer
"""
response = self.transport.read(size=64, timeout_ms=timeout_ms)
Clearly the size parameter is not doing what it says it should do...
Not sure if it's related to my problem, but worth raising the issue...
Hi @ptapping
this is an issue with the docstring for the OBPProtocol. The size parameter isn't used in the receive method.
The first read of 64bytes is enough to parse the header of the reply sent by the spectrometer and determine if the spectrometer needs to read more data.
https://github.com/ap--/python-seabreeze/blob/ff806a834019e2d5a548d2af629d01c90646fea8/src/seabreeze/pyseabreeze/protocol.py#L294-L345 is basically a minimal implementation of https://github.com/ap--/python-seabreeze/blob/ff806a834019e2d5a548d2af629d01c90646fea8/src/libseabreeze/src/vendors/OceanOptics/protocols/obp/exchanges/OBPTransaction.cpp#L74-L222
This should be better documented...
Cheers, Andreas 😃