Camera.hpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*=============================================================================
  2. Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
  3. Redistribution of this file, in original or modified form, without
  4. prior written consent of Allied Vision Technologies is prohibited.
  5. -------------------------------------------------------------------------------
  6. File: Camera.hpp
  7. Description: Inline wrapper functions for class AVT::VmbAPI::Camera.
  8. -------------------------------------------------------------------------------
  9. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  10. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
  11. NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  12. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  13. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  15. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  16. AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  17. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  18. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19. =============================================================================*/
  20. #ifndef AVT_VMBAPI_CAMERA_HPP
  21. #define AVT_VMBAPI_CAMERA_HPP
  22. //
  23. // Inline wrapper functions that allocate memory for STL objects in the application's context
  24. // and to pass data across DLL boundaries using arrays
  25. //
  26. // HINT: This information remains static throughout the object's lifetime
  27. inline VmbErrorType Camera::GetID( std::string &rStrID ) const
  28. {
  29. VmbErrorType res;
  30. VmbUint32_t nLength;
  31. res = GetID( NULL, nLength );
  32. if ( VmbErrorSuccess == res )
  33. {
  34. if ( 0 != nLength )
  35. {
  36. try
  37. {
  38. std::vector<std::string::value_type>tmpID( nLength + 1,'\0');
  39. res = GetID( &tmpID[0], nLength );
  40. if( VmbErrorSuccess == res)
  41. {
  42. rStrID = &*tmpID.begin();
  43. }
  44. }
  45. catch(...)
  46. {
  47. res = VmbErrorResources;
  48. }
  49. }
  50. else
  51. {
  52. rStrID.clear();
  53. }
  54. }
  55. return res;
  56. }
  57. // HINT: This information remains static throughout the object's lifetime
  58. inline VmbErrorType Camera::GetName( std::string &rStrName ) const
  59. {
  60. VmbErrorType res;
  61. VmbUint32_t nLength;
  62. res = GetName( NULL, nLength );
  63. if ( VmbErrorSuccess == res )
  64. {
  65. if( 0 != nLength)
  66. {
  67. try
  68. {
  69. std::vector<std::string::value_type> tmpName( nLength + 1,'\0' );
  70. res = GetName( &tmpName[0], nLength );
  71. if( VmbErrorSuccess == res)
  72. {
  73. rStrName = &*tmpName.begin();
  74. }
  75. }
  76. catch(...)
  77. {
  78. res = VmbErrorResources;
  79. }
  80. }
  81. else
  82. {
  83. rStrName.clear();
  84. }
  85. }
  86. return res;
  87. }
  88. // HINT: This information remains static throughout the object's lifetime
  89. inline VmbErrorType Camera::GetModel( std::string &rStrModel ) const
  90. {
  91. VmbErrorType res;
  92. VmbUint32_t nLength;
  93. res = GetModel( NULL, nLength );
  94. if ( VmbErrorSuccess == res )
  95. {
  96. if( 0 != nLength)
  97. {
  98. try
  99. {
  100. std::vector<std::string::value_type> tmpModel( nLength + 1,'\0');
  101. res = GetModel( &tmpModel[0], nLength );
  102. if( VmbErrorSuccess == res )
  103. {
  104. rStrModel = &*tmpModel.begin();
  105. }
  106. }
  107. catch(...)
  108. {
  109. res = VmbErrorResources;
  110. }
  111. }
  112. else
  113. {
  114. rStrModel.clear();
  115. }
  116. }
  117. return res;
  118. }
  119. // HINT: This information remains static throughout the object's lifetime
  120. inline VmbErrorType Camera::GetSerialNumber( std::string &rStrSerial ) const
  121. {
  122. VmbErrorType res;
  123. VmbUint32_t nLength;
  124. res = GetSerialNumber( NULL, nLength );
  125. if ( VmbErrorSuccess == res )
  126. {
  127. if ( 0 != nLength )
  128. {
  129. try
  130. {
  131. std::vector<std::string::value_type> tmpSerial( nLength + 1,'\0');
  132. res = GetSerialNumber( &tmpSerial[0], nLength );
  133. if( VmbErrorSuccess == res )
  134. {
  135. rStrSerial = &*tmpSerial.begin();
  136. }
  137. }
  138. catch(...)
  139. {
  140. res = VmbErrorResources;
  141. }
  142. }
  143. else
  144. {
  145. rStrSerial.clear();
  146. }
  147. }
  148. return res;
  149. }
  150. // HINT: This information remains static throughout the object's lifetime
  151. inline VmbErrorType Camera::GetInterfaceID( std::string &rStrInterfaceID ) const
  152. {
  153. VmbErrorType res;
  154. VmbUint32_t nLength;
  155. res = GetInterfaceID( NULL, nLength );
  156. if ( VmbErrorSuccess == res )
  157. {
  158. if ( 0 != nLength )
  159. {
  160. try
  161. {
  162. std::vector<std::string::value_type> tmpID( nLength + 1,'\0');
  163. res = GetInterfaceID( &tmpID[0], nLength );
  164. if( VmbErrorSuccess == res )
  165. {
  166. rStrInterfaceID = &*tmpID.begin();
  167. }
  168. }
  169. catch(...)
  170. {
  171. res = VmbErrorResources;
  172. }
  173. }
  174. else
  175. {
  176. rStrInterfaceID.clear();
  177. }
  178. }
  179. return res;
  180. }
  181. inline VmbErrorType Camera::AcquireMultipleImages( FramePtrVector &rFrames, VmbUint32_t nTimeout, FrameAllocationMode allocationMode )
  182. {
  183. VmbErrorType res;
  184. VmbUint32_t i;
  185. res = AcquireMultipleImages( rFrames, nTimeout, i, allocationMode );
  186. if ( rFrames.size() != i )
  187. {
  188. res = VmbErrorInternalFault;
  189. }
  190. return res;
  191. }
  192. inline VmbErrorType Camera::AcquireMultipleImages( FramePtrVector &rFrames, VmbUint32_t nTimeout, VmbUint32_t &rNumFramesCompleted, FrameAllocationMode allocationMode )
  193. {
  194. if ( true == rFrames.empty() )
  195. {
  196. return VmbErrorBadParameter;
  197. }
  198. return AcquireMultipleImages( &rFrames[0], (VmbUint32_t)rFrames.size(), nTimeout, &rNumFramesCompleted, allocationMode );
  199. }
  200. // HINT: Size of address determines how many registers to read. Size of data has to be large enough to hold the requested information
  201. inline VmbErrorType Camera::ReadRegisters( const Uint64Vector &rAddresses, Uint64Vector &rBuffer ) const
  202. {
  203. VmbUint32_t i;
  204. return ReadRegisters( rAddresses, rBuffer, i );
  205. }
  206. inline VmbErrorType Camera::ReadRegisters( const Uint64Vector &rAddresses, Uint64Vector &rBuffer, VmbUint32_t &rCompletedReads ) const
  207. {
  208. if ( true == rAddresses.empty()
  209. || true == rBuffer.empty()
  210. || rAddresses.size() > rBuffer.size() )
  211. {
  212. return VmbErrorBadParameter;
  213. }
  214. return ReadRegisters( &rAddresses[0], (VmbUint32_t)rAddresses.size(), &rBuffer[0], &rCompletedReads );
  215. }
  216. // HINT: Size of address determines how many registers to write.
  217. inline VmbErrorType Camera::WriteRegisters( const Uint64Vector &rAddresses, const Uint64Vector &rBuffer )
  218. {
  219. VmbUint32_t i;
  220. return WriteRegisters( rAddresses, rBuffer, i );
  221. }
  222. inline VmbErrorType Camera::WriteRegisters( const Uint64Vector &rAddresses, const Uint64Vector &rBuffer, VmbUint32_t &rCompletedWrites )
  223. {
  224. if ( true == rAddresses.empty()
  225. || true == rBuffer.empty()
  226. || rAddresses.size() != rBuffer.size() )
  227. {
  228. return VmbErrorBadParameter;
  229. }
  230. return WriteRegisters( &rAddresses[0], (VmbUint32_t)rAddresses.size(), &rBuffer[0], &rCompletedWrites );
  231. }
  232. // HINT: Size of buffer determines how many bytes to read.
  233. inline VmbErrorType Camera::ReadMemory( const VmbUint64_t &rAddress, UcharVector &rBuffer ) const
  234. {
  235. VmbUint32_t i;
  236. return ReadMemory( rAddress, rBuffer, i );
  237. }
  238. inline VmbErrorType Camera::ReadMemory( const VmbUint64_t &rAddress, UcharVector &rBuffer, VmbUint32_t &rCompletedReads ) const
  239. {
  240. if ( true == rBuffer.empty() )
  241. {
  242. return VmbErrorBadParameter;
  243. }
  244. return ReadMemory( rAddress, &rBuffer[0], (VmbUint32_t)rBuffer.size(), &rCompletedReads );
  245. }
  246. // HINT: Size of buffer determines how many bytes to write.
  247. inline VmbErrorType Camera::WriteMemory( const VmbUint64_t &rAddress, const UcharVector &rBuffer )
  248. {
  249. VmbUint32_t i;
  250. return WriteMemory( rAddress, rBuffer, i );
  251. }
  252. inline VmbErrorType Camera::WriteMemory( const VmbUint64_t &rAddress, const UcharVector &rBuffer, VmbUint32_t &rCompletedWrites )
  253. {
  254. if ( true == rBuffer.empty() )
  255. {
  256. return VmbErrorBadParameter;
  257. }
  258. return WriteMemory( rAddress, &rBuffer[0], (VmbUint32_t)rBuffer.size(), &rCompletedWrites );
  259. }
  260. inline VmbErrorType Camera::SaveCameraSettings( std::string strFileName, VmbFeaturePersistSettings_t *pSettings ) const
  261. {
  262. // parameter check
  263. if( true == strFileName.empty() )
  264. {
  265. return VmbErrorBadParameter;
  266. }
  267. return SaveCameraSettings( strFileName.c_str(), pSettings );
  268. }
  269. inline VmbErrorType Camera::LoadCameraSettings( std::string strFileName, VmbFeaturePersistSettings_t *pSettings ) const
  270. {
  271. // parameter check
  272. if( true == strFileName.empty() )
  273. {
  274. return VmbErrorBadParameter;
  275. }
  276. return LoadCameraSettings( strFileName.c_str(), pSettings );
  277. }
  278. #endif