-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from NSLS-II-SRX/axis-caproto-ioc
Axis Caproto IOC
- Loading branch information
Showing
11 changed files
with
118 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Axis Cameras Caproto IOC code.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# pylint: disable=duplicate-code | ||
from __future__ import annotations | ||
|
||
import textwrap | ||
from io import BytesIO | ||
|
||
import requests | ||
from caproto import ChannelType | ||
from caproto.server import pvproperty, run, template_arg_parser | ||
from PIL import Image | ||
|
||
from ..base import CaprotoSaveIOC, check_args | ||
from ..utils import now, save_image | ||
|
||
DEFAULT_MAX_LENGTH = 10_000_000 | ||
|
||
|
||
class AxisSaveIOC(CaprotoSaveIOC): | ||
"""Axis caproto save IOC.""" | ||
|
||
key1 = pvproperty( | ||
value="", | ||
string_encoding="utf-8", | ||
dtype=ChannelType.CHAR, | ||
doc="key 1 for data 1", | ||
max_length=255, | ||
) | ||
data1 = pvproperty( | ||
value=0, | ||
dtype=ChannelType.DOUBLE, | ||
doc="data 1", | ||
max_length=DEFAULT_MAX_LENGTH, | ||
) | ||
|
||
def __init__(self, *args, camera_host=None, **kwargs): | ||
self._camera_host = camera_host | ||
print(f"{camera_host = }") | ||
super().__init__(*args, **kwargs) | ||
|
||
async def _get_current_dataset(self, *args, **kwargs): # pylint: disable=unused-argument | ||
url = f"http://{self._camera_host}/axis-cgi/jpg/image.cgi" | ||
resp = requests.get(url, timeout=10) | ||
img = Image.open(BytesIO(resp.content)) | ||
|
||
dataset = img | ||
print(f"{now()}:\n{dataset.size}") | ||
|
||
return dataset | ||
|
||
@staticmethod | ||
def saver(request_queue, response_queue): | ||
"""The saver callback for threading-based queueing.""" | ||
while True: | ||
received = request_queue.get() | ||
filename = received["filename"] | ||
data = received["data"] | ||
# 'frame_number' is not used for this exporter. | ||
try: | ||
save_image(fname=filename, data=data, file_format="jpeg", mode="x") | ||
print(f"{now()}: saved data into:\n {filename}") | ||
|
||
success = True | ||
error_message = "" | ||
except Exception as exc: # pylint: disable=broad-exception-caught | ||
success = False | ||
error_message = exc | ||
print( | ||
f"Cannot save file {filename!r} due to the following exception:\n{exc}" | ||
) | ||
|
||
response = {"success": success, "error_message": error_message} | ||
response_queue.put(response) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser, split_args = template_arg_parser( | ||
default_prefix="", desc=textwrap.dedent(AxisSaveIOC.__doc__) | ||
) | ||
|
||
parser.add_argument( | ||
"-c", | ||
"--camera-host", | ||
help="The camera hostname, e.g., 'xf06bm-cam5'", | ||
required=True, | ||
type=str, | ||
) | ||
|
||
ioc_options, run_options = check_args(parser, split_args) | ||
|
||
print(f"{ioc_options = }") | ||
print(f"{run_options = }") | ||
|
||
ioc = AxisSaveIOC(camera_host=parser.parse_args().camera_host, **ioc_options) | ||
run(ioc.pvdb, **run_options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
""""Example Caproto IOC code.""" | ||
"""Example Caproto IOC code.""" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
""""Zebra Caproto IOC code.""" | ||
"""Zebra Caproto IOC code.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters