accessi
Advanced tools
+1
-1
| Metadata-Version: 2.1 | ||
| Name: accessi | ||
| Version: 0.0.2 | ||
| Version: 0.0.3 | ||
| Summary: Library for Siemens Access-i MR Scanner Interface to integrate and control the MR Scanner. | ||
@@ -5,0 +5,0 @@ Author-email: Martin Reinok <m.reinok@student.utwente.nl> |
+1
-1
| [project] | ||
| name = "accessi" | ||
| version = "0.0.2" | ||
| version = "0.0.3" | ||
| authors = [ | ||
@@ -5,0 +5,0 @@ { name="Martin Reinok", email="m.reinok@student.utwente.nl" }, |
| Metadata-Version: 2.1 | ||
| Name: accessi | ||
| Version: 0.0.2 | ||
| Version: 0.0.3 | ||
| Summary: Library for Siemens Access-i MR Scanner Interface to integrate and control the MR Scanner. | ||
@@ -5,0 +5,0 @@ Author-email: Martin Reinok <m.reinok@student.utwente.nl> |
+7
-4
@@ -5,2 +5,3 @@ """ | ||
| """ | ||
| import asyncio | ||
| # TODO: TemplateSelection Service Not implemented. | ||
@@ -661,4 +662,2 @@ # TODO: Patient Service Not implemented. | ||
| response = message.get('response', '') | ||
| print("Service:", service) | ||
| print("Request:", request) | ||
| except json.JSONDecodeError as e: | ||
@@ -669,3 +668,6 @@ print("Error decoding JSON:", e) | ||
| async def connect_websocket(config, callback_function): | ||
| async def connect_websocket(queue: asyncio.Queue, websocket_connected: asyncio.Event): | ||
| """ | ||
| Can use any asyncio queue | ||
| """ | ||
| url = f"wss://{config.ip_address}:{config.websocket_port}/SRC?sessionId={config.session_id}" | ||
@@ -679,6 +681,7 @@ if not config.ssl_verify: | ||
| async with websockets.connect(url, ssl=ssl_context) as websocket: | ||
| websocket_connected.set() | ||
| while True: | ||
| message = await websocket.recv() | ||
| decoded_message = handle_websocket_message(message) | ||
| await callback_function(decoded_message) | ||
| await queue.put(decoded_message) | ||
@@ -685,0 +688,0 @@ |
+50
-37
@@ -6,5 +6,5 @@ """ | ||
| import json | ||
| from asyncio import LifoQueue | ||
| from types import SimpleNamespace | ||
| import src as Access | ||
| from src import accessi as Access | ||
| import threading | ||
@@ -14,3 +14,2 @@ import asyncio | ||
| Access.config.ip_address = "127.0.0.1" | ||
@@ -92,4 +91,9 @@ Access.config.version = "v2" | ||
| """ | ||
| template = Access.TemplateExecution.get_templates().value[0] | ||
| print(f"get_template [0]: {template.label}") | ||
| # Find interactive template | ||
| i = 0 | ||
| template = Access.TemplateExecution.get_templates().value[i] | ||
| while not template.isInteractive: | ||
| i += 1 | ||
| template = Access.TemplateExecution.get_templates().value[i] | ||
| print(f"get_template [{i}]: {template.label}") | ||
| template_id = template.id | ||
@@ -174,42 +178,51 @@ assert template_id is not None | ||
| async def demo_callback_function(image_data): | ||
| if "imageStream" in image_data: | ||
| image_data = json.loads(json.dumps(image_data), object_hook=lambda d: SimpleNamespace(**d)) | ||
| print(f"Websocket callback image dimensions: " | ||
| f"{image_data[2].value.image.dimensions.columns}," | ||
| f"{image_data[2].value.image.dimensions.rows} ") | ||
| async def demo_callback_function(queue: asyncio.Queue): | ||
| while True: | ||
| image_data = await queue.get() | ||
| while not queue.empty(): | ||
| await queue.get() | ||
| if "imageStream" in image_data: | ||
| image_data = json.loads(json.dumps(image_data), object_hook=lambda d: SimpleNamespace(**d)) | ||
| print(f"Websocket callback image dimensions: " | ||
| f"{image_data[2].value.image.dimensions.columns}," | ||
| f"{image_data[2].value.image.dimensions.rows} ") | ||
| def run_websocket_in_thread(config, callback_function): | ||
| loop = asyncio.new_event_loop() | ||
| asyncio.set_event_loop(loop) | ||
| try: | ||
| loop.run_until_complete(Access.connect_websocket(config, callback_function)) | ||
| except Exception as error: | ||
| print(f"Websocket was unexpectedly closed (this is fine), {error}") | ||
| async def main(): | ||
| lifo_queue = LifoQueue() | ||
| # Run websocket | ||
| websocket_connected_event = asyncio.Event() | ||
| asyncio.create_task(Access.connect_websocket(lifo_queue, websocket_connected_event)) | ||
| await websocket_connected_event.wait() | ||
| thread = threading.Thread(target=run_websocket_in_thread, args=(Access.config, demo_callback_function)) | ||
| thread.start() | ||
| # Connect the image service to websocket | ||
| websocket = Access.Image.connect_to_default_web_socket() | ||
| print(f"connect_to_default_web_socket: {websocket}") | ||
| assert websocket.result.success is True | ||
| websocket = Access.Image.connect_to_default_web_socket() | ||
| print(f"connect_to_default_web_socket: {websocket}") | ||
| assert websocket.result.success is True | ||
| # Start template | ||
| output = Access.TemplateExecution.start(template_id).result.success | ||
| print(f"start: {output}") | ||
| assert output is True | ||
| output = Access.TemplateExecution.start(template_id).result.success | ||
| print(f"start: {output}") | ||
| assert output is True | ||
| # Start image processing thread | ||
| asyncio.create_task(demo_callback_function(lifo_queue)) | ||
| print("Sleeping 5 seconds") | ||
| time.sleep(5) | ||
| while True: | ||
| await asyncio.sleep(5) | ||
| """ | ||
| Done, cleanup | ||
| """ | ||
| """ | ||
| Done, cleanup | ||
| """ | ||
| print("Tests done, cleaning up") | ||
| Access.TemplateExecution.stop() | ||
| Access.TemplateModification.close() | ||
| Access.HostControl.release_host_control() | ||
| Access.Authorization.deregister() | ||
| print("It works!") | ||
| raise SystemExit | ||
| Access.TemplateExecution.stop() | ||
| Access.TemplateModification.close() | ||
| Access.HostControl.release_host_control() | ||
| Access.Authorization.deregister() | ||
| print("It works!") | ||
| SystemExit() | ||
| print("Running websocket for 5 seconds") | ||
| asyncio.run(main()) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
38443
1.46%802
2.17%