From b5bf4f97e341932d8e350bed6647e2c272e3a76d Mon Sep 17 00:00:00 2001 From: Nathan Clack Date: Fri, 5 May 2023 15:29:32 -0700 Subject: [PATCH 1/6] update deps, tests --- acquire-driver-common | 2 +- acquire-driver-egrabber | 2 +- acquire-driver-hdcam | 2 +- acquire-driver-zarr | 2 +- acquire-video-runtime | 2 +- tests/test_dcam.py | 13 ++++--------- tests/test_egrabber.py | 30 ++++++++++++++---------------- 7 files changed, 23 insertions(+), 30 deletions(-) diff --git a/acquire-driver-common b/acquire-driver-common index 4159c15..d2560d0 160000 --- a/acquire-driver-common +++ b/acquire-driver-common @@ -1 +1 @@ -Subproject commit 4159c15297010d517461fa4be163109fd05f12e8 +Subproject commit d2560d0bd828cc75dd60e8a272fdf74905bc85f0 diff --git a/acquire-driver-egrabber b/acquire-driver-egrabber index 4ecf6c2..3ce238d 160000 --- a/acquire-driver-egrabber +++ b/acquire-driver-egrabber @@ -1 +1 @@ -Subproject commit 4ecf6c23b03a006a945e5b514c96a719f063f63e +Subproject commit 3ce238dca245de1a7578a73583fbeb7b753978ea diff --git a/acquire-driver-hdcam b/acquire-driver-hdcam index e1bbec5..3a0c279 160000 --- a/acquire-driver-hdcam +++ b/acquire-driver-hdcam @@ -1 +1 @@ -Subproject commit e1bbec5756b60314c1fc0dbaabf910a2bf9eb2dc +Subproject commit 3a0c279b1328c5aa602386b08d5b438383fb1567 diff --git a/acquire-driver-zarr b/acquire-driver-zarr index f9ac6f7..d42c059 160000 --- a/acquire-driver-zarr +++ b/acquire-driver-zarr @@ -1 +1 @@ -Subproject commit f9ac6f729810136bc96311ca001474e0c9a89f43 +Subproject commit d42c05930860947c987f297e1ca7c5561b5eae56 diff --git a/acquire-video-runtime b/acquire-video-runtime index 45d41ca..9b9c215 160000 --- a/acquire-video-runtime +++ b/acquire-video-runtime @@ -1 +1 @@ -Subproject commit 45d41ca26ef2435ef225d21dcd5ea6fa470251f3 +Subproject commit 9b9c215938f7cc61057cfc620dc15b0a49dfeb0d diff --git a/tests/test_dcam.py b/tests/test_dcam.py index 729fdee..74c4a62 100644 --- a/tests/test_dcam.py +++ b/tests/test_dcam.py @@ -2,7 +2,7 @@ import acquire import pytest -from acquire import DeviceKind, SampleType, TriggerEvent +from acquire import DeviceKind, SampleType @pytest.fixture(scope="module") @@ -34,13 +34,8 @@ def test_ext_triggering(runtime: acquire.Runtime): # Set the camera here so we can query it's triggering capabilities. # This comes in the form of the returned properties. p = runtime.set_configuration(p) - - p.video[0].camera.settings.triggers[1].enable = True - p.video[0].camera.settings.triggers[1].event = TriggerEvent.FrameStart + p.video[0].camera.settings.input_triggers.frame_start.enable = True # Call set_configuration() again to apply the trigger properties p = runtime.set_configuration(p) - - assert p.video[0].camera.settings.triggers[1].enable is True - assert ( - p.video[0].camera.settings.triggers[1].event == TriggerEvent.FrameStart - ) + # Check that it was accepted + assert p.video[0].camera.settings.input_triggers.frame_start.enable is True diff --git a/tests/test_egrabber.py b/tests/test_egrabber.py index 4e0bf9f..57eb414 100644 --- a/tests/test_egrabber.py +++ b/tests/test_egrabber.py @@ -4,7 +4,7 @@ import acquire import pytest from acquire import DeviceKind, SampleType -from acquire.acquire import TriggerEdge +from acquire.acquire import Trigger, TriggerEdge @pytest.fixture(scope="module") @@ -62,40 +62,38 @@ def test_vieworks_configure_triggering(runtime: acquire.Runtime): p = runtime.set_configuration(p) - # There are two defined lines: Line0, and Software - assert len(p.video[0].camera.settings.triggers) == 2 - # When the camera is first selected, triggers should be disabled - assert not p.video[0].camera.settings.triggers[0].enable - assert not p.video[0].camera.settings.triggers[1].enable + assert not p.video[0].camera.settings.input_triggers.frame_start.enable # # Enable Line0: # # There's really own two things to set. On the VP-151MX, there's only # one kind of event that can be triggered - the frame exposure start. - p.video[0].camera.settings.triggers[0].enable = True - p.video[0].camera.settings.triggers[0].edge = TriggerEdge.Rising + p.video[0].camera.settings.input_triggers.frame_start = Trigger( + enable=True, line=0, edge=TriggerEdge.Rising + ) p = runtime.set_configuration(p) - assert p.video[0].camera.settings.triggers[0].enable - assert not p.video[0].camera.settings.triggers[1].enable + assert p.video[0].camera.settings.input_triggers.frame_start.enable + assert p.video[0].camera.settings.input_triggers.frame_start.line == 0 # # Enable Software triggering: # # There's really own two things to set. On the VP-151MX, there's only # one kind of event that can be triggered - the frame exposure start. - p.video[0].camera.settings.triggers[1].enable = True - p.video[0].camera.settings.triggers[1].edge = TriggerEdge.Rising + p.video[0].camera.settings.input_triggers.frame_start = Trigger( + enable=True, line=1, edge=TriggerEdge.Rising + ) p = runtime.set_configuration(p) - assert not p.video[0].camera.settings.triggers[0].enable - assert p.video[0].camera.settings.triggers[1].enable + + assert p.video[0].camera.settings.input_triggers.frame_start.enable + assert p.video[0].camera.settings.input_triggers.frame_start.line == 1 # # Disable triggering: # - p.video[0].camera.settings.triggers[0].enable = False - p.video[0].camera.settings.triggers[1].enable = False + p.video[0].camera.settings.input_triggers.frame_start.enable = False p = runtime.set_configuration(p) From 9cd29151070a8e6edfa9e51495ad0a26847f63e0 Mon Sep 17 00:00:00 2001 From: Nathan Clack Date: Fri, 5 May 2023 15:38:23 -0700 Subject: [PATCH 2/6] testing (wip) --- tests/test_egrabber.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_egrabber.py b/tests/test_egrabber.py index 57eb414..713084e 100644 --- a/tests/test_egrabber.py +++ b/tests/test_egrabber.py @@ -4,7 +4,7 @@ import acquire import pytest from acquire import DeviceKind, SampleType -from acquire.acquire import Trigger, TriggerEdge +from acquire.acquire import SignalIOKind, Trigger, TriggerEdge @pytest.fixture(scope="module") @@ -71,8 +71,9 @@ def test_vieworks_configure_triggering(runtime: acquire.Runtime): # There's really own two things to set. On the VP-151MX, there's only # one kind of event that can be triggered - the frame exposure start. p.video[0].camera.settings.input_triggers.frame_start = Trigger( - enable=True, line=0, edge=TriggerEdge.Rising + enable=True, line=0, edge="Rising" ) + assert p.video[0].camera.settings.input_triggers.frame_start.enable p = runtime.set_configuration(p) assert p.video[0].camera.settings.input_triggers.frame_start.enable @@ -84,7 +85,7 @@ def test_vieworks_configure_triggering(runtime: acquire.Runtime): # There's really own two things to set. On the VP-151MX, there's only # one kind of event that can be triggered - the frame exposure start. p.video[0].camera.settings.input_triggers.frame_start = Trigger( - enable=True, line=1, edge=TriggerEdge.Rising + enable=True, line=1, edge="Rising" ) p = runtime.set_configuration(p) From 6e41aff47b5bdb189e5356e69a3f663b3239fd1f Mon Sep 17 00:00:00 2001 From: Nathan Clack Date: Mon, 8 May 2023 10:00:42 -0700 Subject: [PATCH 3/6] fix trigger assignment --- src/camera.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 801308b..a185277 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,3 +1,5 @@ +use std::process::Output; + use crate::{ capi, components::{macros::impl_plain_old_dict, Direction, SampleType, Trigger}, @@ -128,16 +130,22 @@ pub struct CameraProperties { shape: (u32, u32), #[pyo3(get, set)] - input_triggers: InputTriggers, + input_triggers: Py, #[pyo3(get, set)] - output_triggers: OutputTriggers, + output_triggers: Py, } impl_plain_old_dict!(CameraProperties); impl Default for CameraProperties { fn default() -> Self { + let (input_triggers, output_triggers) = Python::with_gil(|py| { + ( + Py::new(py, InputTriggers::default()).unwrap(), + Py::new(py, OutputTriggers::default()).unwrap(), + ) + }); Self { exposure_time_us: Default::default(), line_interval_us: Default::default(), @@ -146,8 +154,8 @@ impl Default for CameraProperties { pixel_type: Default::default(), offset: Default::default(), shape: (1920, 1080), - input_triggers: Default::default(), - output_triggers: Default::default(), + input_triggers, + output_triggers, } } } @@ -156,6 +164,11 @@ impl TryFrom for CameraProperties { type Error = anyhow::Error; fn try_from(value: capi::CameraProperties) -> Result { + let (input_triggers, output_triggers) = Python::with_gil(|py| -> PyResult<_> { + let tr_in: InputTriggers = value.input_triggers.try_into()?; + let tr_out: OutputTriggers = value.output_triggers.try_into()?; + Ok((Py::new(py, tr_in)?, Py::new(py, tr_out)?)) + })?; Ok(CameraProperties { exposure_time_us: value.exposure_time_us, line_interval_us: value.line_interval_us, @@ -164,8 +177,8 @@ impl TryFrom for CameraProperties { pixel_type: value.pixel_type.try_into()?, offset: (value.offset.x, value.offset.y), shape: (value.shape.x, value.shape.y), - input_triggers: value.input_triggers.try_into()?, - output_triggers: value.output_triggers.try_into()?, + input_triggers, + output_triggers, }) } } @@ -182,6 +195,11 @@ impl TryFrom<&CameraProperties> for capi::CameraProperties { x: src.shape.0, y: src.shape.1, }; + let (input_triggers, output_triggers) = Python::with_gil(|py| -> PyResult<_> { + let input_triggers: InputTriggers = src.input_triggers.extract(py)?; + let output_triggers: OutputTriggers = src.output_triggers.extract(py)?; + Ok((input_triggers, output_triggers)) + })?; Ok(capi::CameraProperties { exposure_time_us: src.exposure_time_us, line_interval_us: src.line_interval_us, @@ -190,8 +208,8 @@ impl TryFrom<&CameraProperties> for capi::CameraProperties { pixel_type: src.pixel_type.into(), offset, shape, - input_triggers: src.input_triggers.as_ref().try_into()?, - output_triggers: src.output_triggers.as_ref().try_into()?, + input_triggers: (&input_triggers).try_into()?, + output_triggers: (&output_triggers).try_into()?, }) } } From afba01d3f7476142b6f0aaf671eca8b05df29ee9 Mon Sep 17 00:00:00 2001 From: Nathan Clack Date: Mon, 8 May 2023 16:41:49 -0700 Subject: [PATCH 4/6] fix packaging --- Cargo.lock | 38 ++++++++++++++++++++++++++++++-------- Cargo.toml | 5 +---- pyproject.toml | 5 +++++ src/camera.rs | 2 -- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bca340..ba23912 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,9 +38,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bindgen" -version = "0.64.0" +version = "0.65.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" dependencies = [ "bitflags", "cexpr", @@ -49,12 +49,13 @@ dependencies = [ "lazycell", "log", "peeking_take_while", + "prettyplease", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn", + "syn 2.0.15", "which", ] @@ -301,6 +302,16 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "prettyplease" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ceca8aaf45b5c46ec7ed39fff75f57290368c1846d33d24a122ca81416ab058" +dependencies = [ + "proc-macro2", + "syn 2.0.15", +] + [[package]] name = "proc-macro2" version = "1.0.56" @@ -369,7 +380,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -380,7 +391,7 @@ checksum = "97daff08a4c48320587b5224cc98d609e3c27b6d437315bd40b605c98eeb5918" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -395,9 +406,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.18" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" dependencies = [ "proc-macro2", ] @@ -461,7 +472,7 @@ checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -487,6 +498,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "target-lexicon" version = "0.12.4" diff --git a/Cargo.toml b/Cargo.toml index 9a70ce1..5e97316 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,6 @@ authors = ["Nathan Clack "] version = "0.1.0" edition = "2021" -[package.metadata.maturin] -python-source = "python" - [lib] name = "acquire" crate-type = ["cdylib"] @@ -27,5 +24,5 @@ serde = { version = "1.0", features = ["derive"] } pythonize = "0.18" [build-dependencies] -bindgen = "0.64" +bindgen = "0.65" cmake = "0.1" diff --git a/pyproject.toml b/pyproject.toml index ba21315..2becc59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,11 @@ acquire-python = [ "acquire.pyi", ] +[tool.maturin] +python-source = "python" +python-packages = ["acquire"] +include = ["**/*/*.so", "**/*/*.dll"] + [tool.black] target-version = ['py39', 'py310', 'py311'] line-length = 79 diff --git a/src/camera.rs b/src/camera.rs index a185277..0f5a881 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,5 +1,3 @@ -use std::process::Output; - use crate::{ capi, components::{macros::impl_plain_old_dict, Direction, SampleType, Trigger}, From bc54ff2f4214b5ecc01eaa622703f53abd5725ba Mon Sep 17 00:00:00 2001 From: Nathan Clack Date: Mon, 8 May 2023 16:57:21 -0700 Subject: [PATCH 5/6] packaging: remove old setuptools options --- pyproject.toml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2becc59..f64ccdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,21 +28,6 @@ testing = [ [project.entry-points."napari.manifest"] acquire-python = "acquire:napari.yaml" -[tool.setuptools.package_data] -acquire-python = [ - "napari.yaml", - "libacquire-driver-common.so", - "libacquire-driver-egrabber.so", - "libacquire-driver-hdcam.so", - "libacquire-driver-zarr.so", - "acquire-driver-common.dll", - "acquire-driver-egrabber.dll", - "acquire-driver-hdcam.dll", - "acquire-driver-zarr.dll", - "__init__.pyi", - "acquire.pyi", -] - [tool.maturin] python-source = "python" python-packages = ["acquire"] From b07cbb370a6db2b29cf1bdc8606498cd9555ff11 Mon Sep 17 00:00:00 2001 From: Nathan Clack Date: Mon, 8 May 2023 17:09:18 -0700 Subject: [PATCH 6/6] get dcam test to pass --- tests/test_dcam.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_dcam.py b/tests/test_dcam.py index 74c4a62..d51537a 100644 --- a/tests/test_dcam.py +++ b/tests/test_dcam.py @@ -33,8 +33,9 @@ def test_ext_triggering(runtime: acquire.Runtime): # Set the camera here so we can query it's triggering capabilities. # This comes in the form of the returned properties. - p = runtime.set_configuration(p) - p.video[0].camera.settings.input_triggers.frame_start.enable = True + p.video[0].camera.settings.input_triggers.frame_start = acquire.Trigger( + enable=True, line=0, edge="Rising" + ) # Call set_configuration() again to apply the trigger properties p = runtime.set_configuration(p) # Check that it was accepted