python-microscope / microscope

Python library for control of microscope devices, supporting hardware triggers and distribution of devices over the network for performance and flexibility.
https://www.python-microscope.org
GNU General Public License v3.0
69 stars 41 forks source link

floating devices requires init of all possible devices #153

Open carandraug opened 4 years ago

carandraug commented 4 years ago

Floating devices are devices where we can't specify which device to actually control. After construction and initialization, we get one of those devices and must check via get_id to find which one we got. The way this is handled in deviceserver is the following:

  1. we group all device definitions by class
  2. we create a map of their uid (serial number) to the desired host and port.
  3. we then construct and initialize a device, get its uid, and then check on the previously constructed map which host and port to use.

For this to work we are assuming that all available devices will be served (and that they will be served by the same root deviceserver), which means we require all devices that can be controlled by that class to be init.

For example, if we have three cameras connected but we only want to serve two of them, then deviceserver might get the two cameras we want and everything works. But deviceserver might also get the other camera in which case it will fail with "Host or port not found for device X" error and without a way to select the other camera.

In addition, if we have two floating devices connected and we only list one for the device server, then we don't even check the map and we will serve whatever we got without checking its uid (the code that checks its uid is on this block):

        if (isinstance(self._device, microscope.devices.FloatingDeviceMixin)
            and len(self._id_to_host) > 1):
carandraug commented 4 years ago

Proposed fix for the "only one floating device listed on config" case on my 153-always-check-floating-device-uid branch (it effectively removes the len(self._id_to_host) > 1 check mentioned previously.

Not sure how to address the broader issue of not being able to get the device one wants though, this seems to be a limitation of using FloatingDevice.

carandraug commented 4 years ago

After this morning meeting, I pushed the change that checks the UID even for a single floating device. This means that deviceserver now always requires the user to specify the correct UID for floating devices.