Skip to content

Commit

Permalink
Handle Monitor Added
Browse files Browse the repository at this point in the history
  • Loading branch information
TBThomas56 committed Nov 27, 2023
1 parent 642f396 commit cf87c00
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/eiger_fastcs/eiger_controller.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import asyncio
from dataclasses import dataclass
from io import BytesIO
from typing import Any

from attr import Attribute
from fastcs.attributes import AttrR, AttrRW, AttrW
from fastcs.connections import HTTPConnection, IPConnectionSettings
from fastcs.controller import Controller
from fastcs.datatypes import Bool, Float, Int, String
from fastcs.wrappers import command
from fastcs.wrappers import command, scan
from PIL import Image


@dataclass
Expand Down Expand Up @@ -250,3 +252,40 @@ async def start_acquisition(self):
for i in range(self.ntrigger._value):
print(f"Acquisition number: {i+1}")
await self.trigger()

@scan(1)
async def handle_monitor(self):
"""
Calls API every second to check for any new image from detector.
Done until a no new images are available to be viewed.
"""
# collects images from the detector until there is no image.
image_byte = await self.connection.get("monitor/api/1.8.0/images/next")
if image_byte.status != 200:
print("No Image")
return
else:
image = Image.open(BytesIO(image_byte))

# Extract basic metadata of image
image_size = image.size
image_height = image.height
image_width = image.width
image_format = image.format
image_mode = image.mode
image_is_animated = getattr(image, "is_animated", False)
frames_in_image = getattr(image, "n_frames", 1)
bit_depth = image.mode

# Create a dictionary to store the metadata of image for potential
# future access
metadata = {
"size": image_size,
"height": image_height,
"width": image_width,
"format": image_format,
"mode": image_mode,
"is_animated": image_is_animated,
"frames": frames_in_image,
"depth": bit_depth,
}

0 comments on commit cf87c00

Please sign in to comment.