Skip to content

Commit

Permalink
Merge remote-tracking branch 'nclack/testing' into submodule-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aliddell committed May 9, 2023
2 parents 652c401 + b07cbb3 commit df82566
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 49 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 24 additions & 8 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,22 @@ pub struct CameraProperties {
shape: (u32, u32),

#[pyo3(get, set)]
input_triggers: InputTriggers,
input_triggers: Py<InputTriggers>,

#[pyo3(get, set)]
output_triggers: OutputTriggers,
output_triggers: Py<OutputTriggers>,
}

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(),
Expand All @@ -146,8 +152,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,
}
}
}
Expand All @@ -156,6 +162,11 @@ impl TryFrom<capi::CameraProperties> for CameraProperties {
type Error = anyhow::Error;

fn try_from(value: capi::CameraProperties) -> Result<Self, Self::Error> {
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,
Expand All @@ -164,8 +175,8 @@ impl TryFrom<capi::CameraProperties> 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,
})
}
}
Expand All @@ -182,6 +193,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,
Expand All @@ -190,8 +206,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()?,
})
}
}
Expand Down
11 changes: 5 additions & 6 deletions tests/test_dcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import acquire
import pytest
from acquire import DeviceKind, SampleType, Trigger
from acquire import DeviceKind, SampleType


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -33,11 +33,10 @@ 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 = Trigger(enable=True, line=1)
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
assert p.video[0].camera.settings.input_triggers.frame_start.enable is True
assert p.video[0].camera.settings.input_triggers.frame_start.line == 1
31 changes: 15 additions & 16 deletions tests/test_egrabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import acquire
import pytest
from acquire import DeviceKind, SampleType
from acquire.acquire import TriggerEdge
from acquire.acquire import SignalIOKind, Trigger, TriggerEdge


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -62,40 +62,39 @@ 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="Rising"
)
assert p.video[0].camera.settings.input_triggers.frame_start.enable

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="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)

0 comments on commit df82566

Please sign in to comment.