pawel1010 / Openflexure-confocal-microscope

1 stars 0 forks source link

First attempt to start #1

Open pawel1010 opened 2 years ago

pawel1010 commented 2 years ago

I installed Raspbian-OpenFlexure system on my RPi 3, I installed required repo for ADC with pip. Then I've downloaded example extension folder and placed it in /var/openflexure/extensions/microscope_extensions and I pasted code of stage.py inside file /src/ofm_example_extension/extension.py. Then I run on my RPi 3 command ofm serve and then on my computer I run program main.py and I get an error:

[pawel@phantom confocal]$ python3 main.py
Current position: {"x": 0, "y": 0, "z": 0}
Homing
Traceback (most recent call last):
  File "main.py", line 63, in <module>
    values = microscope.moveMeasure(microscope, pos, 5)
  File "main.py", line 36, in mm
    response = self.post_json("/actions/stage/move-measure", pos)
  File "/usr/local/lib/python3.6/site-packages/openflexure_microscope_client/microscope_client.py", line 64, in post_json
    r.raise_for_status()
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 405 Client Error: METHOD NOT ALLOWED for url: http://192.168.0.226:5000/api/v2/actions/stage/move-measure
[pawel@phantom confocal]$ 
rwb27 commented 2 years ago

Hi @pawel1010 this looks like a really cool project! I've skimmed over your extension code and I think the problem might be that the extension definition isn't finished - you define some MethodView subclasses, but they are not attached to a BasePlugin subclass, so I don't think they will ever actually be exposed via the HTTP interface.

I am currently working on a nicer way to define all this, but it will be a while before it's properly ready. In the meantime, you probably want to:

  1. define a subclass of BasePlugin
  2. call self.add_view in the __init__ method for each action you want to expose
  3. Ideally, include a line that says LABTHINGS_EXTENSIONS = [MyExtension] so the extension class is picked up properly (there is a work-around in the code, so this shouldn't stop it working if you omit it).

Also, I notice you're initialising some of the hardware at import time: it will work more nicely, especially with my plans to improve extensions in the future, if you initialise the hardware in the __init__ method of your BaseExtension subclass. If you swap your MethodView subclasses to be ActionView subclasses, you'll be able to access the extension object as self.extension.

A useful example would be the camera-stage mapping extension or indeed any of the default ones.

rwb27 commented 2 years ago

Also, are you using the camera at all, or just the stage? If it's the latter, it's worth mentioning the Sangaboard firmware has some built-in support for an ADS1115 already, so it's possible to just connect to the Sangaboard on USB, and avoid the Python server altogether. This loses you most of the functionality of the microscope server, but is worth mentioning in case that's a hindrance rather than a help!

pawel1010 commented 2 years ago

Thank you for your answer. I'm using only ADC ADS1115 (not camera) which is collecting the data.

pawel1010 commented 2 years ago

I've updated file stage.py. I get another error:

pi@microscope:~ $ ofm journal
-- Logs begin at Sat 2022-06-25 00:30:14 CEST. --
cze 25 00:30:33 microscope python[484]:   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
cze 25 00:30:33 microscope python[484]:   File "/var/openflexure/extensions/microscope_extensions/stage.py", line 10, in <module>
cze 25 00:30:33 microscope python[484]:     import board
cze 25 00:30:33 microscope python[484]: ModuleNotFoundError: No module named 'board'
cze 25 00:30:37 microscope python[484]: INFO:root:Starting OpenFlexure Microscope Server...
cze 25 00:35:32 microscope systemd[1]: Stopping Flask instance to serve the OpenFlexure Microscope API...
cze 25 00:35:33 microscope systemd[1]: openflexure-microscope-server.service: Main process exited, code=killed, status=15/TERM
cze 25 00:35:33 microscope systemd[1]: openflexure-microscope-server.service: Succeeded.
cze 25 00:35:33 microscope systemd[1]: Stopped Flask instance to serve the OpenFlexure Microscope API.
cze 25 00:36:00 microscope systemd[1]: Started Flask instance to serve the OpenFlexure Microscope API.
cze 25 00:36:05 microscope python[1031]: INFO:root:Running with data path /var/openflexure
cze 25 00:36:05 microscope python[1031]: INFO:root:Loading /var/openflexure/settings/microscope_configuration.json...
cze 25 00:36:05 microscope python[1031]: INFO:root:Creating camera
cze 25 00:36:05 microscope python[1031]: INFO:root:Setting stage
cze 25 00:36:05 microscope python[1031]: INFO:root:Trying SangaDeltaStage
cze 25 00:36:05 microscope python[1031]: INFO:root:Initialising ExtensibleSerialInstrument on port None
cze 25 00:36:05 microscope python[1031]: INFO:root:Updating ESI port settings
cze 25 00:36:05 microscope python[1031]: INFO:root:Opening ESI connection to port None
cze 25 00:36:05 microscope python[1031]: INFO:root:Trying port /dev/ttyUSB0
cze 25 00:36:05 microscope python[1031]: INFO:root:Creating serial.Serial instance...
cze 25 00:36:05 microscope python[1031]: INFO:root:Created Serial<id=0x73c8c690, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
cze 25 00:36:05 microscope python[1031]: INFO:root:Testing communication to SangaBoard
cze 25 00:36:05 microscope python[1031]: INFO:root:Running firmware checks...
cze 25 00:36:06 microscope python[1031]: INFO:root:Firmware response: Sangaboard Firmware v0.5.1
cze 25 00:36:06 microscope python[1031]: INFO:root:Success!
cze 25 00:36:06 microscope python[1031]: INFO:root:Creating serial.Serial instance...
cze 25 00:36:06 microscope python[1031]: INFO:root:Created Serial<id=0x73d11cb0, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
cze 25 00:36:06 microscope python[1031]: INFO:root:Testing communication to SangaBoard
cze 25 00:36:06 microscope python[1031]: INFO:root:Running firmware checks...
cze 25 00:36:08 microscope python[1031]: INFO:root:Firmware response: Sangaboard Firmware v0.5.1
cze 25 00:36:08 microscope python[1031]: INFO:root:Opened ESI connection to port None
cze 25 00:36:08 microscope python[1031]: INFO:root:Checking valid firmware...
cze 25 00:36:08 microscope python[1031]: INFO:root:Running firmware checks...
cze 25 00:36:08 microscope python[1031]: INFO:root:Firmware response: Sangaboard Firmware v0.5.1
cze 25 00:36:08 microscope python[1031]: INFO:root:Loading modules...
cze 25 00:36:08 microscope python[1031]: INFO:root:Saving new SangaDeltaStage type configuration
cze 25 00:36:08 microscope python[1031]: INFO:root:Saving /var/openflexure/settings/microscope_configuration.json...
cze 25 00:36:08 microscope python[1031]: INFO:root:Handling fallbacks
cze 25 00:36:08 microscope python[1031]: INFO:root:Waiting for frames
cze 25 00:36:09 microscope python[1031]: INFO:root:Creating locks
cze 25 00:36:09 microscope python[1031]: INFO:root:Loading /var/openflexure/settings/microscope_settings.json...
cze 25 00:36:09 microscope python[1031]: INFO:root:0 capture files found on disk
cze 25 00:36:09 microscope python[1031]: INFO:root:0 capture files successfully reloaded
cze 25 00:36:09 microscope python[1031]: INFO:root:Creating app
cze 25 00:36:09 microscope python[1031]: ERROR:root:Exception in extension path /var/openflexure/extensions/microscope_extensions/stage.py:
cze 25 00:36:09 microscope python[1031]: Traceback (most recent call last):
cze 25 00:36:09 microscope python[1031]:   File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.7/site-packages/labthings/extensions.py", line 262, in find_extensions_in_file
cze 25 00:36:09 microscope python[1031]:     spec.loader.exec_module(mod)  # type: ignore
cze 25 00:36:09 microscope python[1031]:   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
cze 25 00:36:09 microscope python[1031]:   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
cze 25 00:36:09 microscope python[1031]:   File "/var/openflexure/extensions/microscope_extensions/stage.py", line 10, in <module>
cze 25 00:36:09 microscope python[1031]:     import board
cze 25 00:36:09 microscope python[1031]: ModuleNotFoundError: No module named 'board'
cze 25 00:36:12 microscope python[1031]: INFO:root:Starting OpenFlexure Microscope Server...
pawel1010 commented 2 years ago

I figured it out, that running ofm activate and installing with pip required packages probably solves the problem. Now I get UserWarning:

pi@microscope:~ $ ofm journal
-- Logs begin at Thu 2019-02-14 11:11:59 CET. --
cze 25 02:03:29 microscope python[1447]: INFO:root:Setting stage
cze 25 02:03:29 microscope python[1447]: INFO:root:Trying SangaDeltaStage
cze 25 02:03:29 microscope python[1447]: INFO:root:Initialising ExtensibleSerialInstrument on port None
cze 25 02:03:29 microscope python[1447]: INFO:root:Updating ESI port settings
cze 25 02:03:29 microscope python[1447]: INFO:root:Opening ESI connection to port None
cze 25 02:03:29 microscope python[1447]: INFO:root:Trying port /dev/ttyUSB0
cze 25 02:03:29 microscope python[1447]: INFO:root:Creating serial.Serial instance...
cze 25 02:03:29 microscope python[1447]: INFO:root:Created Serial<id=0x73be22b0, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
cze 25 02:03:29 microscope python[1447]: INFO:root:Testing communication to SangaBoard
cze 25 02:03:29 microscope python[1447]: INFO:root:Running firmware checks...
cze 25 02:03:30 microscope python[1447]: INFO:root:Firmware response: Sangaboard Firmware v0.5.1
cze 25 02:03:30 microscope python[1447]: INFO:root:Success!
cze 25 02:03:30 microscope python[1447]: INFO:root:Creating serial.Serial instance...
cze 25 02:03:30 microscope python[1447]: INFO:root:Created Serial<id=0x7426f490, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
cze 25 02:03:30 microscope python[1447]: INFO:root:Testing communication to SangaBoard
cze 25 02:03:30 microscope python[1447]: INFO:root:Running firmware checks...
cze 25 02:03:32 microscope python[1447]: INFO:root:Firmware response: Sangaboard Firmware v0.5.1
cze 25 02:03:32 microscope python[1447]: INFO:root:Opened ESI connection to port None
cze 25 02:03:32 microscope python[1447]: INFO:root:Checking valid firmware...
cze 25 02:03:32 microscope python[1447]: INFO:root:Running firmware checks...
cze 25 02:03:32 microscope python[1447]: INFO:root:Firmware response: Sangaboard Firmware v0.5.1
cze 25 02:03:32 microscope python[1447]: INFO:root:Loading modules...
cze 25 02:03:32 microscope python[1447]: INFO:root:Saving new SangaDeltaStage type configuration
cze 25 02:03:32 microscope python[1447]: INFO:root:Saving /var/openflexure/settings/microscope_configuration.json...
cze 25 02:03:32 microscope python[1447]: INFO:root:Handling fallbacks
cze 25 02:03:32 microscope python[1447]: INFO:root:Waiting for frames
cze 25 02:03:33 microscope python[1447]: INFO:root:Creating locks
cze 25 02:03:33 microscope python[1447]: INFO:root:Loading /var/openflexure/settings/microscope_settings.json...
cze 25 02:03:33 microscope python[1447]: INFO:root:0 capture files found on disk
cze 25 02:03:33 microscope python[1447]: INFO:root:0 capture files successfully reloaded
cze 25 02:03:33 microscope python[1447]: INFO:root:Creating app
cze 25 02:03:33 microscope python[1447]: Auto-scanning ports
cze 25 02:03:36 microscope python[1447]: /var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.7/site-packages/apispec/ext/marshmallow/common.py:131: UserWarning: Multiple schemas resolved to the name MoveStageAPIInput. The name has been modified. Either manually add each of the schemas with a different name or provide a custom schema_name_resolver.
cze 25 02:03:36 microscope python[1447]:   UserWarning,
cze 25 02:03:36 microscope python[1447]: INFO:root:Starting OpenFlexure Microscope Server...
rwb27 commented 2 years ago

hmm - that is odd; does it appear to work, or do you think the warning suggests something is broken? I think the fact that the warning appears probably means something's not quite right, but it may not actually prevent it from functioning as intended.