aboutsummaryrefslogtreecommitdiff
path: root/test.py
blob: 3dc86432a67192f4186a85e1a1ac15fd0e25f758 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
import vimbastructure as structs
from vimbaobject import VimbaObject
from vimbaexception import VimbaException
from vimbaframe import VimbaFrame
from vimbadll import VimbaDLL
from ctypes import *

# camera features are automatically set as attributes of camera.
class VimbaCamera(VimbaObject):
	"""
	A Vimba camera object. This class provides the minimal access
	to Vimba functions required to control the camera.
	"""
	
	@property
	def cameraIdString(self):
		return self._cameraIdString
	
	# own handle is inherited as self._handle
	def __init__(self, cameraIdString):
		
		# call super constructor
		super(VimbaCamera, self).__init__()
		
		# set ID
		self._cameraIdString = cameraIdString

		# set own info
		self._info = self._getInfo()
		
	def getInfo(self):
		"""
		Get info of the camera. Does not require
		the camera to be opened.
		
		:returns: VimbaCameraInfo object -- camera information.
		"""
		return self._info
	
	def _getInfo(self):
		"""
		Get info of the camera. Does not require
		the camera to be opened.
		
		:returns: VimbaCameraInfo object -- camera information.
		"""
		# args for Vimba call
		cameraInfo = structs.VimbaCameraInfo()
		
		# Vimba DLL will return an error code
		errorCode = VimbaDLL.cameraInfoQuery(self._cameraIdString,
											 byref(cameraInfo),
											 sizeof(cameraInfo))
		if errorCode != 0:
			raise VimbaException(errorCode)
		
		return cameraInfo
	
	def openCamera(self):
		"""
		Open the camera.
		"""
		# args for Vimba call
		cameraAccessMode = 1	# full access (see VmbAccessModeType)

		errorCode = VimbaDLL.cameraOpen(self._cameraIdString,
										cameraAccessMode,
										byref(self._handle))
		if errorCode != 0:
			raise VimbaException(errorCode)
		
	def closeCamera(self):
		"""
		Close the camera.
		"""
		errorCode = VimbaDLL.cameraClose(self._handle)
		if errorCode != 0:
			raise VimbaException(errorCode)
		
	def revokeAllFrames(self):
		"""
		Revoke all frames assigned to the camera.
		"""
		errorCode = VimbaDLL.frameRevokeAll(self._handle)
		if errorCode != 0:
			raise VimbaException(errorCode)

	def startCapture(self):
		"""
		Prepare the API for incoming frames.
		"""
		errorCode = VimbaDLL.captureStart(self._handle)
		if errorCode != 0:
			raise VimbaException(errorCode)
	
	def endCapture(self):
		"""
		Stop the API from being able to receive frames.
		"""
		errorCode = VimbaDLL.captureEnd(self._handle)
		if errorCode != 0:
			raise VimbaException(errorCode)

	def flushCaptureQueue(self):
		"""
		Flush the capture queue.
		"""
		errorCode = VimbaDLL.captureQueueFlush(self._handle)
		if errorCode != 0:
			raise VimbaException(errorCode)
		
	# method for easy frame creation
	def getFrame(self):
		"""
		Creates and returns a new frame object. Multiple frames
		per camera can therefore be returned.
		
		:returns: VimbaFrame object -- the new frame.
		"""
		return VimbaFrame(self)