ap-- / python-seabreeze

Python module for OceanOptics spectrometers
https://python-seabreeze.readthedocs.io
MIT License
211 stars 82 forks source link

pyseabreeze: OBPProtocol.receive docstring is incorrect #109

Open ptapping opened 4 years ago

ptapping commented 4 years ago

spectrometer and system information

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...

ap-- commented 4 years ago

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 😃