SoftwareTriggerConfiguration.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2010-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Andreas Gau
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief An instant camera configuration for software trigger,
  10. Use together with Pylon::CInstantCamera::WaitForFrameTriggerReady() and Pylon::CInstantCamera::ExecuteSoftwareTrigger().
  11. This instant camera configuration is provided as header-only file. The code
  12. can be copied and modified for creating own configuration classes.
  13. */
  14. #ifndef INCLUDED_SOFTWARETRIGGERCONFIGURATION_H_4655834
  15. #define INCLUDED_SOFTWARETRIGGERCONFIGURATION_H_4655834
  16. #include <pylon/Platform.h>
  17. #ifdef _MSC_VER
  18. # pragma pack(push, PYLON_PACKING)
  19. #endif /* _MSC_VER */
  20. #include <pylon/InstantCamera.h>
  21. #include <pylon/ParameterIncludes.h>
  22. #include <pylon/ConfigurationHelper.h>
  23. namespace Pylon
  24. {
  25. /** \addtogroup Pylon_InstantCameraApiGeneric
  26. * @{
  27. */
  28. /*!
  29. \class CSoftwareTriggerConfiguration
  30. \brief Changes the configuration of the camera so that the acquisition of frames is triggered by software trigger.
  31. Use together with CInstantCamera::WaitForFrameTriggerReady() and CInstantCamera::ExecuteSoftwareTrigger().
  32. The %CSoftwareTriggerConfiguration is provided as header-only file.
  33. The code can be copied and modified for creating own configuration classes.
  34. */
  35. class CSoftwareTriggerConfiguration : public CConfigurationEventHandler
  36. {
  37. public:
  38. /// Apply software trigger configuration.
  39. static void ApplyConfiguration( GenApi::INodeMap& nodemap )
  40. {
  41. using namespace GenApi;
  42. //Disable compression mode.
  43. CConfigurationHelper::DisableCompression( nodemap );
  44. //Disable GenDC streaming.
  45. CConfigurationHelper::DisableGenDC( nodemap );
  46. //Select image component.
  47. CConfigurationHelper::SelectRangeComponent( nodemap );
  48. // Disable all trigger types except the trigger type used for triggering the acquisition of
  49. // frames.
  50. {
  51. // Get required enumerations.
  52. CEnumParameter triggerSelector( nodemap, "TriggerSelector" );
  53. CEnumParameter triggerMode( nodemap, "TriggerMode" );
  54. // Check the available camera trigger mode(s) to select the appropriate one: acquisition start trigger mode
  55. // (used by older cameras, i.e. for cameras supporting only the legacy image acquisition control mode;
  56. // do not confuse with acquisition start command) or frame start trigger mode
  57. // (used by newer cameras, i.e. for cameras using the standard image acquisition control mode;
  58. // equivalent to the acquisition start trigger mode in the legacy image acquisition control mode).
  59. String_t triggerName( "FrameStart" );
  60. if (!triggerSelector.CanSetValue( triggerName ))
  61. {
  62. triggerName = "AcquisitionStart";
  63. if (!triggerSelector.CanSetValue( triggerName ))
  64. {
  65. throw RUNTIME_EXCEPTION( "Could not select trigger. Neither FrameStart nor AcquisitionStart is available." );
  66. }
  67. }
  68. // Get all enumeration entries of trigger selector.
  69. StringList_t triggerSelectorEntries;
  70. triggerSelector.GetSettableValues( triggerSelectorEntries );
  71. // Turn trigger mode off for all trigger selector entries except for the frame trigger given by triggerName.
  72. for (StringList_t::const_iterator it = triggerSelectorEntries.begin(); it != triggerSelectorEntries.end(); ++it)
  73. {
  74. // Set trigger mode to off.
  75. triggerSelector.SetValue( *it );
  76. if (triggerName == *it)
  77. {
  78. // Activate trigger.
  79. triggerMode.SetValue( "On" );
  80. // The trigger source must be set to 'Software'.
  81. CEnumParameter( nodemap, "TriggerSource" ).SetValue( "Software" );
  82. //// Alternative hardware trigger configuration:
  83. //// This configuration can be copied and modified to create a hardware trigger configuration.
  84. //// Remove setting the 'TriggerSource' to 'Software' (see above) and
  85. //// use the commented lines as a starting point.
  86. //// The camera user's manual contains more information about available configurations.
  87. //// The Basler pylon Viewer tool can be used to test the selected settings first.
  88. //// The trigger source must be set to the trigger input, e.g. 'Line1'.
  89. //CEnumParameter(nodemap, "TriggerSource").SetValue("Line1");
  90. ////The trigger activation must be set to e.g. 'RisingEdge'.
  91. //CEnumParameter(nodemap, "TriggerActivation").SetValue("RisingEdge");
  92. }
  93. else
  94. {
  95. triggerMode.TrySetValue( "Off" );
  96. }
  97. }
  98. // Finally select the frame trigger type (resp. acquisition start type
  99. // for older cameras). Issuing a software trigger will now trigger
  100. // the acquisition of a frame.
  101. triggerSelector.SetValue( triggerName );
  102. }
  103. //Set acquisition mode to "continuous"
  104. CEnumParameter( nodemap, "AcquisitionMode" ).SetValue( "Continuous" );
  105. }
  106. //Set basic camera settings.
  107. virtual void OnOpened( CInstantCamera& camera )
  108. {
  109. try
  110. {
  111. ApplyConfiguration( camera.GetNodeMap() );
  112. // Probe max packet size
  113. CConfigurationHelper::ProbePacketSize( camera.GetStreamGrabberNodeMap() );
  114. }
  115. catch (const GenericException& e)
  116. {
  117. throw RUNTIME_EXCEPTION( "Could not apply configuration. Pylon::GenericException caught in OnOpened method msg=%hs", e.what() );
  118. }
  119. catch (const std::exception& e)
  120. {
  121. throw RUNTIME_EXCEPTION( "Could not apply configuration. std::exception caught in OnOpened method msg=%hs", e.what() );
  122. }
  123. catch (...)
  124. {
  125. throw RUNTIME_EXCEPTION( "Could not apply configuration. Unknown exception caught in OnOpened method." );
  126. }
  127. }
  128. };
  129. /**
  130. * @}
  131. */
  132. }
  133. #ifdef _MSC_VER
  134. # pragma pack(pop)
  135. #endif /* _MSC_VER */
  136. #endif /* INCLUDED_SOFTWARETRIGGERCONFIGURATION_H_4655834 */