Skip to content

Commit

Permalink
Merge pull request micro-manager#474 from kmdouglass/flycap-add-trigg…
Browse files Browse the repository at this point in the history
…er-options

Expose trigger polarity to Micro-Manager in Point Grey device adapter
  • Loading branch information
marktsuchida authored Jul 5, 2024
2 parents 3f240a0 + 2d2037b commit 36c45e6
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
112 changes: 112 additions & 0 deletions DeviceAdapters/PointGrey/PointGrey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const char* g_InternalTrigger = "Internal";
const char* g_ExternalTrigger = "External";
const char* g_SoftwareTrigger = "Software";
const char* g_CameraTime = "CameraTime";
const char* g_PolarityLow = "Low";
const char* g_PolarityHigh = "High";


/////////////////////////////////////////////////////

Expand Down Expand Up @@ -190,6 +193,7 @@ PointGrey::PointGrey(const char* deviceName) :
isCapturing_(false),
f7InUse_(false),
triggerMode_(TRIGGER_INTERNAL),
triggerPolarity_(TRIGGER_POLARITY_LOW),
externalTriggerGrabTimeout_(60000),
bytesPerPixel_(1),
imgBuf_(0),
Expand Down Expand Up @@ -686,6 +690,14 @@ int PointGrey::Initialize()
}
}

if (triggerModeInfo.polaritySupported == true)
{
CPropertyAction* pAct = new CPropertyAction(this, &PointGrey::OnTriggerPolarity);
CreateProperty("TriggerPolarity", g_PolarityLow, MM::String, false, pAct, false);
AddAllowedValue("TriggerPolarity", g_PolarityLow);
AddAllowedValue("TriggerPolarity", g_PolarityHigh);
}

// We most likely want little endian bit order
ret = SetEndianess(true);
if (ret != DEVICE_OK)
Expand Down Expand Up @@ -1823,6 +1835,65 @@ int PointGrey::OnTriggerMode(MM::PropertyBase* pProp, MM::ActionType eAct)
return DEVICE_OK;
}

/***************************************************************
* Handles Trigger Polarity
*
* This property determines whether an external trigger must be
* in the high or low state to start an exposure..
*/
int PointGrey::OnTriggerPolarity(MM::PropertyBase* pProp, MM::ActionType eAct)
{
if (eAct == MM::AfterSet)
{
Error error = cam_.StopCapture();
// if camera is not capturing, StopCapture will return an error.
// probably safe to ignore, it is bad to return
if (error != PGRERROR_OK && error != PGRERROR_ISOCH_NOT_STARTED)
{
SetErrorText(ALLERRORS, error.GetDescription());
return ALLERRORS;
}

std::string polarity;
pProp->Get(polarity);

int ret = DEVICE_OK;
unsigned short newPolarity;
if ( polarity == g_PolarityLow ) {
newPolarity = 0;
ret = SetTriggerPolarity(newPolarity);
}
else {
newPolarity = 1;
ret = SetTriggerPolarity(newPolarity);
}
if ( ret != DEVICE_OK )
{
return ret;
}
error = cam_.StartCapture();
if ( error != PGRERROR_OK )
{
SetErrorText(ALLERRORS, error.GetDescription());
return ALLERRORS;
}

triggerPolarity_ = newPolarity;
}
else if ( eAct == MM::BeforeGet )
{
if (triggerPolarity_ == TRIGGER_POLARITY_LOW)
{
pProp->Set(g_PolarityLow);
}
else {
pProp->Set(g_PolarityHigh);
}
}

return DEVICE_OK;
}

/***********************************************************************
* Sets a register in the camera to indicate the endianness of the
* output. It seems that MM wants little endian, most likely since
Expand Down Expand Up @@ -2264,6 +2335,47 @@ int PointGrey::SetTriggerMode(const unsigned short newMode)
return DEVICE_OK;
}

int PointGrey::SetTriggerPolarity(const unsigned short newPolarity)
{
if ((newPolarity != 0) && (newPolarity != 1))
{
return ERR_INVALID_TRIGGER_POLARITY;
}

if (triggerPolarity_ != newPolarity)
{
// Get current trigger settings
TriggerMode triggerMode;
Error error = cam_.GetTriggerMode(&triggerMode);
if (error != PGRERROR_OK) {
}
else
{
triggerMode.polarity = newPolarity;
error = cam_.SetTriggerMode(&triggerMode);
if (error != PGRERROR_OK)
{
SetErrorText(ALLERRORS, error.GetDescription());
return ALLERRORS;
}

if (triggerMode.source == 7) // 7 for software trigger
{
// Poll to ensure camera is ready
int ret = PollForTriggerReady(2000);
if (ret != DEVICE_OK)
{
return ret;
}
}

triggerPolarity_ = newPolarity;
}
}

return DEVICE_OK;
}

int PointGrey::SetGrabTimeout(const unsigned long timeoutMs)
{
FC2Config config;
Expand Down
8 changes: 8 additions & 0 deletions DeviceAdapters/PointGrey/PointGrey.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@
#define ERR_NOT_READY_FOR_SOFTWARE_TRIGGER 12301
#define ERR_UNAVAILABLE_TRIGGER_MODE_REQUESTED 12302
#define ERR_UNKNOWN_TRIGGER_MODE_STRING 12303
#define ERR_INVALID_TRIGGER_POLARITY 12304

// Trigger modes
#define TRIGGER_INTERNAL 0
#define TRIGGER_EXTERNAL 1
#define TRIGGER_SOFTWARE 2

// Trigger polarities
#define TRIGGER_POLARITY_LOW 0
#define TRIGGER_POLARITY_HIGH 1

using namespace FlyCapture2;

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -112,6 +117,7 @@ class PointGrey : public CCameraBase<PointGrey>
int OnPixelType(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnFormat7Mode(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnTriggerMode(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnTriggerPolarity(MM::PropertyBase* pProp, MM::ActionType eAct);

private:
void updatePixelFormats(unsigned int pixelFormatBitField);
Expand All @@ -121,6 +127,7 @@ class PointGrey : public CCameraBase<PointGrey>
int PollForTriggerReady(const unsigned long timeoutMs);
bool FireSoftwareTrigger();
int SetTriggerMode(const unsigned short newMode);
int SetTriggerPolarity(const unsigned short newPolarity);
int SetGrabTimeout(const unsigned long timeoutMs);
int PowerCameraOn(const unsigned int timeoutMs);
int TriggerModeFromString(std::string mode, unsigned short& tMode);
Expand Down Expand Up @@ -148,6 +155,7 @@ class PointGrey : public CCameraBase<PointGrey>
bool f7InUse_;
double exposureTimeMs_;
unsigned short triggerMode_;
unsigned short triggerPolarity_;
unsigned short snapTriggerMode_;
unsigned long externalTriggerGrabTimeout_;
unsigned short bytesPerPixel_;
Expand Down

0 comments on commit 36c45e6

Please sign in to comment.