-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger_input.py
More file actions
76 lines (54 loc) · 1.96 KB
/
trigger_input.py
File metadata and controls
76 lines (54 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Copyright (C) 2025 Allied Vision Technologies. All Rights Reserved.
Subject to the BSD 3-Clause License.
"""
import sys
from vmbpy import *
from vmbpy.camera import CamerasTuple
def print_preamble() -> None:
print('////////////////////////////////////////')
print('/// Smart Camera Trigger Input Example ///')
print('////////////////////////////////////////\n')
def print_usage() -> None:
print('Usage:')
print(' python trigger_input.py')
print(' python trigger_input.py -h')
print()
def abort(reason: str, return_code: int = 1, usage: bool = False) -> None:
print(reason + '\n')
if usage:
print_usage()
sys.exit(return_code)
def parse_args() -> None:
args = sys.argv[1:]
argc = len(args)
for arg in args:
if arg == '-h':
print_usage()
sys.exit(0)
if argc > 0:
abort(reason="Invalid number of arguments. Abort.", return_code=2, usage=True)
def frame_handler(camera: Camera, stream: Stream, frame: Frame) -> None:
print('{} acquired {}'.format(camera, frame), flush=True)
camera.queue_frame(frame)
if __name__ == '__main__':
print_preamble()
parse_args()
with VmbSystem.get_instance() as vmb_system:
cameras: CamerasTuple = vmb_system.get_all_cameras()
if len(cameras) == 0:
abort('No camera found.')
with cameras[0] as camera:
camera.LineSelector.set("Line0")
try:
camera.LineMode.set("Input")
except:
pass
camera.TriggerSelector.set("FrameStart")
camera.TriggerSource.set("Line0")
camera.TriggerMode.set("On")
print('\n Toggle the trigger input line between high and low to acquire a frame.')
print('Press <enter> to stop frame acquisition.')
camera.start_streaming(handler=frame_handler)
input()
camera.stop_streaming()