Device.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2006-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Hartmut Nebelung
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Low Level API: Definition of IPylonDevice
  10. */
  11. #ifndef __DEVICE_H__
  12. #define __DEVICE_H__
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif // _MSC_VER > 1000
  16. #include <pylon/Platform.h>
  17. #ifdef _MSC_VER
  18. # pragma pack(push, PYLON_PACKING)
  19. #endif /* _MSC_VER */
  20. #include <GenICamFwd.h>
  21. #include <Base/GCException.h>
  22. #include <pylon/stdinclude.h>
  23. #include <pylon/PylonBase.h>
  24. #include <pylon/WaitObject.h>
  25. #include <pylon/WaitObjects.h> // for backward compatibility reasons
  26. #include <pylon/DeviceInfo.h>
  27. #include <pylon/EventAdapter.h>
  28. #include <pylon/Callback.h>
  29. #include <pylon/DeviceAccessMode.h>
  30. namespace Pylon
  31. {
  32. interface IStreamGrabber;
  33. interface IEventGrabber;
  34. interface IChunkParser;
  35. interface ISelfReliantChunkParser;
  36. interface IPylonDevice;
  37. /// callback type with a IPylonDevice as parameter
  38. typedef Pylon::Callback1<IPylonDevice*> DeviceCallback;
  39. /// opaque device callback object
  40. typedef void* DeviceCallbackHandle;
  41. class CDeviceInfo;
  42. // -------------------------------------------------------------------------
  43. // interface IDevice
  44. // -------------------------------------------------------------------------
  45. /*! \interface IDevice
  46. \brief Low Level API: The interface implemented by all device objects
  47. \ingroup Pylon_LowLevelApi
  48. */
  49. interface PUBLIC_INTERFACE IDevice
  50. {
  51. /// Opens a device
  52. /**
  53. The open method initializes all involved drivers and establishes a connection
  54. to the device.
  55. A device may support different access modes, e.g. EDeviceAccessMode::Exclusive providing
  56. an exclusive access to the device.
  57. \param mode The desired device access mode
  58. */
  59. virtual void Open( AccessModeSet mode = (Stream | Control | Event) ) = 0;
  60. /// Closes a device
  61. /**
  62. The close method closes all involved drivers and an existing connection to
  63. the device will be released. Other applications now can access the device.
  64. */
  65. virtual void Close() = 0;
  66. /// Checks if a device already is opened
  67. /**
  68. \return true, when the device already has been opened by the calling application.
  69. \note When a device has been opened an application A, IsOpen() will return false
  70. when called by an application B not having called the device's open method.
  71. */
  72. virtual bool IsOpen() const = 0;
  73. /// Returns the access mode used to open the device
  74. virtual AccessModeSet AccessMode( void ) const = 0;
  75. /** \brief Returns the device info object storing information like
  76. the device's name.
  77. \return A reference to the device info object used to create the device by a device factory
  78. */
  79. virtual const CDeviceInfo& GetDeviceInfo() const = 0;
  80. };
  81. // ---------------------------------------------------------------------
  82. // interface IPylonDevice
  83. // ---------------------------------------------------------------------
  84. /** \interface IPylonDevice
  85. \brief Low Level API: Interface for camera objects
  86. \ingroup Pylon_LowLevelApi
  87. */
  88. interface PUBLIC_INTERFACE IPylonDevice : public IDevice
  89. {
  90. public:
  91. /// Returns the number of stream grabbers the camera object provides
  92. virtual uint32_t GetNumStreamGrabberChannels() const = 0;
  93. /// Returns a pointer to a stream grabber
  94. /**
  95. Stream grabbers (IStreamGrabber) are the objects used to grab images
  96. from a camera device. A camera device might be able to send image data
  97. over more than one logical channel called stream. A stream grabber grabs
  98. data from one single stream.
  99. \param index The number of the grabber to return
  100. \return A pointer to a stream grabber, NULL if index is out of range
  101. */
  102. virtual IStreamGrabber* GetStreamGrabber( uint32_t index ) = 0;
  103. /// Returns a pointer to an event grabber
  104. /**
  105. Event grabbers are used to handle events sent from a camera device.
  106. */
  107. virtual IEventGrabber* GetEventGrabber() = 0;
  108. /// Returns the set of camera parameters.
  109. /**
  110. \return Pointer to the GenApi node map holding the parameters
  111. */
  112. virtual GenApi::INodeMap* GetNodeMap() = 0;
  113. /// Returns the set of camera related transport layer parameters.
  114. /**
  115. \return Pointer to the GenApi node holding the transport layer parameter. If
  116. there are no transport layer parameters for the device, NULL is returned.
  117. */
  118. virtual GenApi::INodeMap* GetTLNodeMap() = 0;
  119. /** \brief Creates a chunk parser used to update those camera object members
  120. reflecting the content of additional data chunks appended to the image data.
  121. \return Pointer to the created chunk parser
  122. \note Don't try to delete a chunk parser pointer by calling free or delete. Instead,
  123. use the DestroyChunkParser() method
  124. */
  125. virtual Pylon::IChunkParser* CreateChunkParser() = 0;
  126. /// Deletes a chunk parser
  127. /**
  128. \param pChunkParser Pointer to the chunk parser to be deleted
  129. */
  130. virtual void DestroyChunkParser( Pylon::IChunkParser* pChunkParser ) = 0;
  131. /*!
  132. Creates an Event adapter
  133. */
  134. virtual IEventAdapter* CreateEventAdapter() = 0;
  135. /*!
  136. Deletes an Event adapter
  137. */
  138. virtual void DestroyEventAdapter( IEventAdapter* ) = 0;
  139. /*!
  140. Creates a a self-reliant chunk parser, returns NULL if not supported
  141. */
  142. virtual ISelfReliantChunkParser* CreateSelfReliantChunkParser() = 0;
  143. /*!
  144. Deletes a self-reliant chunk parser
  145. */
  146. virtual void DestroySelfReliantChunkParser( ISelfReliantChunkParser* ) = 0;
  147. /// Registers a surprise removal callback object
  148. /**
  149. \param d reference to a device callback object
  150. \return A handle which must be used to deregister a callback
  151. It is recommended to use one of the RegisterRemovalCallback() helper functions
  152. to register a callback.
  153. Example how to register a C function
  154. \code
  155. void MyRemovalCallback( Pylon::IPylonDevice* pDevice)
  156. {
  157. // handle removal
  158. }
  159. DeviceCallbackHandle h =
  160. Pylon::RegisterRemovalCallback( m_pCamera, &MyRemovalCallback);
  161. \endcode
  162. Example how to register a class member function
  163. \code
  164. class C
  165. {
  166. void MyRemovalCallback( Pylon::IPylonDevice* pDevice )
  167. {
  168. // handle removal
  169. }
  170. } c;
  171. DeviceCallbackHandle h =
  172. Pylon::RegisterRemovalCallback( m_pCamera, c, &C::MyRemovalCallback);
  173. \endcode
  174. */
  175. virtual DeviceCallbackHandle RegisterRemovalCallback( DeviceCallback& d ) = 0;
  176. /// Deregisters a surprise removal callback object
  177. /*!
  178. \param h Handle of the callback to be removed
  179. */
  180. virtual bool DeregisterRemovalCallback( DeviceCallbackHandle h ) = 0;
  181. };
  182. #ifdef _MSC_VER
  183. #pragma warning ( push )
  184. #pragma warning( disable : 4239 ) // nonstandard extension used
  185. #endif
  186. /**
  187. \brief Low Level API: Register a C-function as a removal callback
  188. \ingroup Pylon_LowLevelApi
  189. \see Pylon::IPylonDevice::RegisterRemovalCallback()
  190. \param pDevice Pointer to the device that generates callbacks
  191. \param f The function to be called
  192. */
  193. template<class Function>
  194. DeviceCallbackHandle RegisterRemovalCallback( IPylonDevice* pDevice, Function f )
  195. {
  196. if (NULL == pDevice)
  197. throw RUNTIME_EXCEPTION( "Failed to register removal callback, invalid device object." );
  198. DeviceCallback cb( make_FunctionCallback<Function, Pylon::Callback1<IPylonDevice*>, IPylonDevice* >( f ) );
  199. return pDevice->RegisterRemovalCallback( cb );
  200. }
  201. /**
  202. \brief Low Level API: Register a C++-member function as removal callback
  203. \ingroup Pylon_LowLevelApi
  204. \see Pylon::IPylonDevice::RegisterRemovalCallback()
  205. \param pDevice Pointer to the device that generates callbacks
  206. \param c The client object
  207. \param m The member function to be called
  208. */
  209. template<class Client, class Member>
  210. DeviceCallbackHandle RegisterRemovalCallback( IPylonDevice* pDevice, Client& c, Member m )
  211. {
  212. if (NULL == pDevice)
  213. throw RUNTIME_EXCEPTION( "Failed to register removal callback, invalid device object." );
  214. DeviceCallback x( make_MemberFunctionCallback<Client, Member, DeviceCallback, IPylonDevice*>( c, m ) );
  215. return pDevice->RegisterRemovalCallback( x );
  216. }
  217. #ifdef _MSC_VER
  218. #pragma warning ( pop )
  219. #endif
  220. }
  221. #ifdef _MSC_VER
  222. # pragma pack(pop)
  223. #endif /* _MSC_VER */
  224. #endif //__DEVICE_H__