Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daheng Galaxy: Much better handling of sequence acquisition #513

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 49 additions & 14 deletions DeviceAdapters/DahengGalaxy/ClassGalaxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ ClassGalaxy::ClassGalaxy() :
sensorReadoutMode_("Undefined"),
shutterMode_("None"),
imgBufferSize_(0),
sequenceRunning_(false),
initialized_(false)
{
// call the base class method to set-up default error codes/messages
Expand Down Expand Up @@ -751,23 +752,25 @@ void ClassGalaxy::CopyToImageBuffer(CImageDataPointer& objImageDataPointer)
}
}

int ClassGalaxy::StartSequenceAcquisition(long /* numImages */, double /* interval_ms */, bool /* stopOnOverflow */) {
int ClassGalaxy::StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow) {
try
{
AddToLog("ReadyMuiltySequenceAcquisition");
ImageHandler_ = new CircularBufferInserter(this);
AddToLog("ReadyMultySequenceAcquisition");
ImageHandler_ = new CircularBufferInserter(this, numImages, stopOnOverflow);
//camera_->RegisterImageEventHandler(ImageHandler_, RegistrationMode_Append, Cleanup_Delete);
m_objStreamPtr->RegisterCaptureCallback(ImageHandler_, this);

//camera_->StartGrabbing(numImages, GrabStrategy_OneByOne, GrabLoop_ProvidedByInstantCamera);
m_objFeatureControlPtr->GetCommandFeature("AcquisitionStart")->Execute();
//开启流层采集
m_objStreamPtr->StartGrab();

int ret = GetCoreCallback()->PrepareForAcq(this);
if (ret != DEVICE_OK) {
return ret;
}
sequenceRunning_ = true;

//camera_->StartGrabbing(numImages, GrabStrategy_OneByOne, GrabLoop_ProvidedByInstantCamera);
m_objFeatureControlPtr->GetCommandFeature("AcquisitionStart")->Execute();
//开启流层采集
m_objStreamPtr->StartGrab();

AddToLog("StartSequenceAcquisition");
}
Expand All @@ -778,6 +781,7 @@ int ClassGalaxy::StartSequenceAcquisition(long /* numImages */, double /* interv
m_objFeatureControlPtr->GetCommandFeature("AcquisitionStop")->Execute();
//关闭流层采集
m_objStreamPtr->StopGrab();
sequenceRunning_ = false;
return DEVICE_ERR;
}
catch (const std::exception& e)
Expand All @@ -786,10 +790,13 @@ int ClassGalaxy::StartSequenceAcquisition(long /* numImages */, double /* interv
m_objFeatureControlPtr->GetCommandFeature("AcquisitionStop")->Execute();
//关闭流层采集
m_objStreamPtr->StopGrab();
sequenceRunning_ = false;
return DEVICE_ERR;
}
return DEVICE_OK;
}


int ClassGalaxy::StartSequenceAcquisition(double /* interval_ms */) {
try
{
Expand All @@ -811,6 +818,7 @@ int ClassGalaxy::StartSequenceAcquisition(double /* interval_ms */) {
if (ret != DEVICE_OK) {
return ret;
}
sequenceRunning_ = true;
//camera_->StartGrabbing(numImages, GrabStrategy_OneByOne, GrabLoop_ProvidedByInstantCamera);
m_objFeatureControlPtr->GetCommandFeature("AcquisitionStart")->Execute();
//开启流层采集
Expand All @@ -824,6 +832,7 @@ int ClassGalaxy::StartSequenceAcquisition(double /* interval_ms */) {
m_objFeatureControlPtr->GetCommandFeature("AcquisitionStop")->Execute();
//关闭流层采集
m_objStreamPtr->StopGrab();
sequenceRunning_ = false;
return DEVICE_ERR;
}
catch (const std::exception& e)
Expand All @@ -832,11 +841,13 @@ int ClassGalaxy::StartSequenceAcquisition(double /* interval_ms */) {
m_objFeatureControlPtr->GetCommandFeature("AcquisitionStop")->Execute();
//关闭流层采集
m_objStreamPtr->StopGrab();
sequenceRunning_ = false;
return DEVICE_ERR;
}
return DEVICE_OK;
}


int ClassGalaxy::StopSequenceAcquisition()
{
if (m_objStreamFeatureControlPtr->GetBoolFeature("StreamIsGrabbing")->GetValue())
Expand All @@ -847,13 +858,15 @@ int ClassGalaxy::StopSequenceAcquisition()
//camera_->DeregisterImageEventHandler(ImageHandler_);
m_objStreamPtr->UnregisterCaptureCallback();
}
sequenceRunning_ = false;
AddToLog("StopSequenceAcquisition");
return DEVICE_OK;
}


bool ClassGalaxy::IsCapturing()
{
return m_objStreamFeatureControlPtr->GetBoolFeature("StreamIsGrabbing")->GetValue() ? true : false;
return sequenceRunning_;
}

int ClassGalaxy::PrepareSequenceAcqusition()
Expand Down Expand Up @@ -1847,8 +1860,19 @@ GX_VALID_BIT_LIST ClassGalaxy::GetBestValudBit(GX_PIXEL_FORMAT_ENTRY emPixelForm
}

CircularBufferInserter::CircularBufferInserter(ClassGalaxy* dev) :
dev_(dev)
dev_(dev),
numImages_(-1),
imgCounter_(0),
stopOnOverflow_(false)
{}

CircularBufferInserter::CircularBufferInserter(ClassGalaxy* dev, long numImages, bool stopOnOverflow) :
dev_(dev),
numImages_(numImages),
imgCounter_(0),
stopOnOverflow_(stopOnOverflow)
{}

//---------------------------------------------------------------------------------
/**
\brief 采集回调函数
Expand Down Expand Up @@ -1884,7 +1908,15 @@ void CircularBufferInserter::DoOnImageCaptured(CImageDataPointer& objImageDataPo
(unsigned)dev_->GetImageBytesPerPixel(), 1, md.Serialize().c_str(), FALSE);
if (ret == DEVICE_BUFFER_OVERFLOW) {
//if circular buffer overflows, just clear it and keep putting stuff in so live mode can continue
dev_->GetCoreCallback()->ClearImageBuffer(dev_);
if (stopOnOverflow_)
{
dev_->StopSequenceAcquisition();
dev_->LogMessage("Error inserting image into sequence buffer", false);
}
else
{
dev_->GetCoreCallback()->ClearImageBuffer(dev_);
}
}
}
else if (dev_->colorCamera_)
Expand All @@ -1906,22 +1938,25 @@ void CircularBufferInserter::DoOnImageCaptured(CImageDataPointer& objImageDataPo
dev_->GetCoreCallback()->ClearImageBuffer(dev_);
}
}
imgCounter_++;
if (imgCounter_ == numImages_)
{
dev_->StopSequenceAcquisition();
}
}
else
{
dev_->AddToLog("残帧");
}
}





}
int64_t ClassGalaxy::__GetStride(int64_t nWidth, bool bIsColor)
{
return bIsColor ? nWidth * 3 : nWidth;
}


bool ClassGalaxy::__IsCompatible(BITMAPINFO* pBmpInfo, uint64_t nWidth, uint64_t nHeight)
{
if (pBmpInfo == NULL
Expand Down
5 changes: 5 additions & 0 deletions DeviceAdapters/DahengGalaxy/ClassGalaxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class MODULE_API ClassGalaxy : public CCameraBase<ClassGalaxy>

long imgBufferSize_;
ImgBuffer img_;
bool sequenceRunning_;
bool initialized_;

//图像转换
Expand All @@ -224,9 +225,13 @@ class MODULE_API ClassGalaxy : public CCameraBase<ClassGalaxy>
class CircularBufferInserter : public ICaptureEventHandler {
private:
ClassGalaxy* dev_;
long numImages_;
long imgCounter_;
bool stopOnOverflow_;

public:
CircularBufferInserter(ClassGalaxy* dev);
CircularBufferInserter(ClassGalaxy* dev, long numImages, bool stoponOverflow);

virtual void DoOnImageCaptured(CImageDataPointer& objImageDataPointer, void* pUserParam);
};