123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- //-----------------------------------------------------------------------------
- // Basler pylon SDK
- // Copyright (c) 2010-2021 Basler AG
- // http://www.baslerweb.com
- // Author: Hartmut Nebelung
- //-----------------------------------------------------------------------------
- /*!
- \file
- \brief An instant camera configuration for triggering via GigE Vision action commands.
- This instant camera configuration is provided as header-only file. The code
- can be copied and modified for creating own configuration classes.
- */
- #ifndef INCLUDED_ACTIONTRIGGERCONFIGURATION_H_4655834
- #define INCLUDED_ACTIONTRIGGERCONFIGURATION_H_4655834
- #include <pylon/Platform.h>
- #ifdef _MSC_VER
- # pragma pack(push, PYLON_PACKING)
- #endif /* _MSC_VER */
- #include <pylon/InstantCamera.h>
- #include <pylon/ParameterIncludes.h>
- #include <pylon/ConfigurationHelper.h>
- namespace Pylon
- {
- /** \addtogroup Pylon_InstantCameraApiUniversal
- * @{
- */
- // Arbitrarily chosen constants for camera selection. For an explanation and
- // tips see the "Multi-Camera Applications and GigE Vision 2.0" White paper
- const uint32_t AllGroupMask( 0xffffffff ); // camera will respond to any mask other than 0
- /*!
- \class CActionTriggerConfiguration
- \brief Changes the configuration of the camera so that it is triggered by the first
- available action command.
- This configuration enables the frame start trigger and disables all other trigger
- types. As trigger source the first available action command is selected, i.e., the
- camera will be triggered by action commands issued by the application.
- In contrast to using the software trigger triggering with action commands allows
- to trigger multiple cameras simultaneously.
- Either register this configuration as an Instant Camera's event handler or apply
- the configuration to the node map of an opened pylon device using one of the
- ApplyConfiguration methods.
- The %CActionTriggerConfiguration is provided as header-only file.
- The code can be copied and modified for creating own configuration classes.
- */
- class CActionTriggerConfiguration : public CConfigurationEventHandler
- {
- public:
- struct ActionParameter
- {
- uint32_t DeviceKey;
- uint32_t GroupKey;
- uint32_t GroupMask;
- ActionParameter()
- : DeviceKey( 0 ), GroupKey( 0 ), GroupMask( AllGroupMask )
- {
- }
- ActionParameter( uint32_t DeviceKey_, uint32_t GroupKey_, uint32_t GroupMask_ = AllGroupMask )
- : DeviceKey( DeviceKey_ ), GroupKey( GroupKey_ ), GroupMask( GroupMask_ )
- {
- }
- };
- // constructors and assignment
- CActionTriggerConfiguration( uint32_t DeviceKey, uint32_t GroupKey, uint32_t GroupMask = AllGroupMask ) :
- m_Parameter( DeviceKey, GroupKey, GroupMask )
- {
- }
- CActionTriggerConfiguration( const ActionParameter& p )
- : m_Parameter( p )
- {
- }
- CActionTriggerConfiguration( const CActionTriggerConfiguration& other ) : CConfigurationEventHandler( other )
- {
- m_Parameter = other.m_Parameter;
- }
- CActionTriggerConfiguration& operator=( const CActionTriggerConfiguration& rhs )
- {
- m_Parameter = rhs.m_Parameter;
- return *this;
- }
- // destructor
- virtual ~CActionTriggerConfiguration()
- {
- }
- /// Apply action trigger configuration to a given camera device node map.
- static void ApplyConfiguration( GenApi::INodeMap& deviceNodeMap, const ActionParameter& p )
- {
- ApplyConfiguration( deviceNodeMap, p.DeviceKey, p.GroupKey, p.GroupMask );
- }
- /// Apply action trigger configuration to a given camera device node map.
- static void ApplyConfiguration( GenApi::INodeMap& deviceNodeMap, uint32_t DeviceKey, uint32_t GroupKey, uint32_t GroupMask = AllGroupMask )
- {
- using namespace GenApi;
- //Disable compression mode.
- CConfigurationHelper::DisableCompression( deviceNodeMap );
- //Disable GenDC streaming.
- CConfigurationHelper::DisableGenDC( deviceNodeMap );
- //Select image component.
- CConfigurationHelper::SelectRangeComponent( deviceNodeMap );
- //////////////////////////////////////////////////////////////////
- // get the nodes we need and do a check before we start changing the camera configuration
- CIntegerParameter actionDeviceKey( deviceNodeMap, "ActionDeviceKey" );
- CIntegerParameter actionGroupKey( deviceNodeMap, "ActionGroupKey" );
- CIntegerParameter actionGroupMask( deviceNodeMap, "ActionGroupMask" );
- CIntegerParameter actionSelector( deviceNodeMap, "ActionSelector" );
- if (!actionDeviceKey.IsWritable() ||
- !actionGroupKey.IsWritable() ||
- !actionGroupMask.IsWritable() ||
- !actionSelector.IsWritable())
- {
- throw RUNTIME_EXCEPTION( "Device doesn't support action commands. The ActionCommand features are not writable." );
- }
- // Get required enumerations to configure triggering on action commands
- CEnumParameter triggerSelector( deviceNodeMap, "TriggerSelector" );
- CEnumParameter triggerSource( deviceNodeMap, "TriggerSource" );
- CEnumParameter triggerMode( deviceNodeMap, "TriggerMode" );
- // to use triggering we need to switch Continuous Grab
- CEnumParameter acquisitionMode( deviceNodeMap, "AcquisitionMode" );
- if (!triggerSelector.IsWritable() ||
- !triggerSource.IsWritable() ||
- !triggerMode.IsWritable())
- {
- throw RUNTIME_EXCEPTION( "Trigger nodes not writable" );
- }
- // Check the available camera trigger mode(s)
- const String_t triggerName( "FrameStart" );
- if (!triggerSelector.CanSetValue( triggerName ))
- {
- throw RUNTIME_EXCEPTION( "Device does not support \"FrameStart\"" );
- }
- if (!acquisitionMode.IsWritable())
- {
- throw RUNTIME_EXCEPTION( "Acquisition mode not writable" );
- }
- //////////////////////////////////////////////////////////////////
- // start changing the camera configuration
- // Select the first action (usually "Action 1")
- actionSelector.SetToMinimum();
- String_t selectedAction = GenICam::gcstring( "Action" ) += actionSelector.ToString();
- actionDeviceKey.SetValue( DeviceKey );
- actionGroupKey.SetValue( GroupKey );
- actionGroupMask.SetValue( GroupMask );
- // The goal is to issue a trigger for each single frame. Configure the
- // corresponding trigger mode, disable all other trigger types.
- {
- // Get all settable enumeration entries of Trigger Selector.
- StringList_t triggerSelectorEntries;
- triggerSelector.GetSettableValues( triggerSelectorEntries );
- const String_t originalSelectorValue = triggerSelector.GetValue();
- // Iterate through all available trigger modes, configure the frame start
- // trigger, disable all other trigger types.
- for (StringList_t::const_iterator it = triggerSelectorEntries.begin(); it != triggerSelectorEntries.end(); ++it)
- {
- // Set Trigger Mode to off if the trigger is available.
- triggerSelector.SetValue( *it );
- if (triggerName == *it)
- {
- // Activate trigger.
- triggerMode.SetValue( "On" );
- // Set the trigger source to the selected action.
- triggerSource.SetValue( selectedAction );
- }
- else
- {
- triggerMode.TrySetValue( "Off" );
- }
- }
- // reset to old value
- triggerSelector.SetValue( originalSelectorValue );
- }
- // Set acquisition mode.
- acquisitionMode.SetValue( "Continuous" );
- }
- private:
- // Apply settings when the camera is opened.
- /* virtual */ void OnOpened( CInstantCamera& camera )
- {
- try
- {
- ApplyConfiguration( camera.GetNodeMap(), m_Parameter );
- // Probe max packet size
- CConfigurationHelper::ProbePacketSize( camera.GetStreamGrabberNodeMap() );
- }
- catch (const GenericException& e)
- {
- throw RUNTIME_EXCEPTION( "Could not apply configuration. Pylon::GenericException caught in OnOpened method msg=%hs", e.what() );
- }
- catch (const std::exception& e)
- {
- throw RUNTIME_EXCEPTION( "Could not apply configuration. std::exception caught in OnOpened method msg=%hs", e.what() );
- }
- catch (...)
- {
- throw RUNTIME_EXCEPTION( "Could not apply configuration. Unknown exception caught in OnOpened method." );
- }
- }
- private:
- ActionParameter m_Parameter;
- };
- /**
- * @}
- */
- }
- #ifdef _MSC_VER
- # pragma pack(pop)
- #endif /* _MSC_VER */
- #endif /* INCLUDED_ACTIONTRIGGERCONFIGURATION_H_4655834 */
|