52 lines
No EOL
1.4 KiB
Python
52 lines
No EOL
1.4 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 and stage locks...")
|
|
#with self.microscope.camera.lock, self.microscope.stage.lock:
|
|
print("Acquiring composite microscope lock...")
|
|
with self.microscope.lock:
|
|
for _ in range(t_run):
|
|
n_array.append(random.random())
|
|
time.sleep(1)
|
|
|
|
print("Long-running task finished! Releasing locks.")
|
|
|
|
return n_array |