ConfigurationHelper.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2010-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Arne Wischmann
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Helper functions for different camera configuration classes.
  10. These helper functions are provided as a header-only file.
  11. The code can be copied and modified for creating your own configuration classes.
  12. */
  13. #ifndef INCLUDED_CONFIGURATIONHELPER_H_6526739
  14. #define INCLUDED_CONFIGURATIONHELPER_H_6526739
  15. #include <pylon/Platform.h>
  16. #ifdef _MSC_VER
  17. # pragma pack(push, PYLON_PACKING)
  18. #endif /* _MSC_VER */
  19. #include <pylon/ParameterIncludes.h>
  20. namespace Pylon
  21. {
  22. /** \addtogroup Pylon_InstantCameraApiGeneric
  23. * @{
  24. */
  25. /*!
  26. \class CConfigurationHelper
  27. \brief Helper functions for different camera configuration classes.
  28. */
  29. class CConfigurationHelper
  30. {
  31. public:
  32. /*!
  33. \brief DisableAllTriggers disables all trigger types that can be
  34. turned off.
  35. */
  36. static void DisableAllTriggers( GenApi::INodeMap& nodemap )
  37. {
  38. //Disable all trigger types.
  39. {
  40. // Get required enumerations.
  41. CEnumParameter triggerSelector( nodemap, "TriggerSelector" );
  42. CEnumParameter triggerMode( nodemap, "TriggerMode" );
  43. if (triggerSelector.IsWritable())
  44. {
  45. // Get all settable enumeration entries of trigger selector.
  46. GenApi::StringList_t triggerSelectorEntries;
  47. triggerSelector.GetSettableValues( triggerSelectorEntries );
  48. const String_t originalSelectorValue = triggerSelector.GetValue();
  49. // Turn trigger mode off for all trigger selector entries.
  50. for (GenApi::StringList_t::const_iterator it = triggerSelectorEntries.begin(); it != triggerSelectorEntries.end(); ++it)
  51. {
  52. // Set trigger mode to off if the trigger is available.
  53. triggerSelector.SetValue( *it );
  54. triggerMode.TrySetValue( "Off" );
  55. }
  56. // reset to original value
  57. triggerSelector.SetValue( originalSelectorValue );
  58. }
  59. }
  60. }
  61. /*!
  62. \brief DisableCompression disables all compressions modes that can be
  63. turned off.
  64. */
  65. static void DisableCompression( GenApi::INodeMap& nodemap )
  66. {
  67. //Disable compression mode (if supported by the camera).
  68. CEnumParameter compressionMode( nodemap, "ImageCompressionMode" );
  69. compressionMode.TrySetValue( "Off" );
  70. }
  71. /*!
  72. \brief DisableGenDC disables GenDC streaming when available.
  73. */
  74. static void DisableGenDC( GenApi::INodeMap& nodemap )
  75. {
  76. CEnumParameter genDCMode( nodemap, "GenDCStreamingMode" );
  77. genDCMode.TrySetValue( "Off" );
  78. }
  79. /*!
  80. \brief Select the 'Range' component.
  81. Some cameras, such as Basler blaze, provide multiple components.
  82. Default is component 'Range' with pixel format 'Mono16' respective 'Mono8'.
  83. */
  84. static void SelectRangeComponent( GenApi::INodeMap& nodemap )
  85. {
  86. CEnumParameter componentSelector = CEnumParameter( nodemap, "ComponentSelector" );
  87. CBooleanParameter enableComponent = CBooleanParameter( nodemap, "ComponentEnable" );
  88. CEnumParameter pixelFormat = CEnumParameter( nodemap, "PixelFormat" );
  89. // if multiple components are supported then enable only the 'range' component.
  90. if (componentSelector.IsWritable())
  91. {
  92. const String_t originalComponentValue = componentSelector.GetValue();
  93. GenApi::StringList_t componentSelectorEntries;
  94. componentSelector.GetSettableValues( componentSelectorEntries );
  95. for (GenApi::StringList_t::iterator it = componentSelectorEntries.begin(), end = componentSelectorEntries.end(); it != end; ++it)
  96. {
  97. const String_t& entry = *it;
  98. componentSelector.SetValue( entry );
  99. // if Range is selected enable it set pixel format to Mono16 of Mono8
  100. if (entry.compare( "Range" ) == 0)
  101. {
  102. enableComponent.TrySetValue( true );
  103. if (!pixelFormat.TrySetValue( "Mono16" ))
  104. {
  105. pixelFormat.TrySetValue( "Mono8" );
  106. }
  107. }
  108. else
  109. { // disable other components
  110. enableComponent.TrySetValue( false );
  111. }
  112. }
  113. // reset the component selector
  114. componentSelector.TrySetValue( originalComponentValue );
  115. }
  116. }
  117. static void ProbePacketSize( GenApi::INodeMap& nodemap )
  118. {
  119. using namespace GenApi;
  120. CCommandParameter probePacketSize( nodemap, "ProbePacketSize" );
  121. probePacketSize.TryExecute( );
  122. }
  123. };
  124. /**
  125. * @}
  126. */
  127. }
  128. #ifdef _MSC_VER
  129. # pragma pack(pop)
  130. #endif /* _MSC_VER */
  131. #endif /* INCLUDED_CONFIGURATIONHELPER_H_6526739 */