openflexure-microscope-server/openflexure_microscope/plugins/example/plugin.py
2019-01-24 12:11:01 +00:00

50 lines
No EOL
1.2 KiB
Python

import random
import time
from openflexure_microscope.plugins import MicroscopePlugin
from .api import IdentifyAPI, HelloWorldAPI, LongRunningAPI
class Plugin(MicroscopePlugin):
"""
A set of default plugins
"""
api_views = {
'/identify': IdentifyAPI,
'/hello': HelloWorldAPI,
'/long_running': LongRunningAPI,
}
def identify(self):
"""
Demonstrate access to Microscope.camera, and Microscope.stage
"""
response = "My parent camera is {}, and my parent stage is {}.".format(self.microscope.camera, self.microscope.stage)
print(response)
return response
def hello_world(self):
"""
Demonstrate passive method
"""
return "Hello world!"
def long_running(self, t_run):
"""
Demonstrate a long-running method that requires microscope hardware
"""
print("Starting a long-running task...")
n_array = []
print("Acquiring camera lock...")
with self.microscope.camera.lock:
for _ in range(t_run):
n_array.append(random.random())
time.sleep(1)
print("Long-running task finished! Releasing lock.")
return n_array