Skip to content

Commit

Permalink
Merge pull request #457 from nicost/NIDAQ
Browse files Browse the repository at this point in the history
Nidaq: adds property indicating whether sequences transitions happen at the beginning or end of exposure
  • Loading branch information
nicost authored Apr 7, 2024
2 parents f789fed + 542180b commit 3c291c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
33 changes: 33 additions & 0 deletions DeviceAdapters/NIDAQ/NIAnalogOutputPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ NIAnalogOutputPort::NIAnalogOutputPort(const std::string& port) :
minVolts_(0.0),
maxVolts_(5.0),
neverSequenceable_(false),
transitionPostExposure_(false),
task_(0)
{
InitializeDefaultErrorMessages();
Expand Down Expand Up @@ -88,6 +89,13 @@ int NIAnalogOutputPort::Initialize()
if (err != DEVICE_OK)
return err;

pAct = new CPropertyAction(this, &NIAnalogOutputPort::OnSequenceTransition);
err = CreateStringProperty("Sequence Transition Pre-Post Exposure", g_Pre, false, pAct);
if (err != DEVICE_OK)
return err;
AddAllowedValue("Sequence Transition Pre-Post Exposure", g_Pre);
AddAllowedValue("Sequence Transition Pre-Post Exposure", g_Post);

err = StartOnDemandTask(gateOpen_ ? gatedVoltage_ : 0.0);
if (err != DEVICE_OK)
return err;
Expand Down Expand Up @@ -191,6 +199,16 @@ int NIAnalogOutputPort::StartDASequence()
if (task_)
StopTask();

// probably beneficial in all cases to move to the first position,
// essential if we are transitioning post-exposure
double volt0 = sentSequence_[0];
SetSignal(volt0);

if (transitionPostExposure_) {
for (int i = 0; i < sentSequence_.size() - 1; i++) {
sentSequence_[i] = sentSequence_[i + 1];
}
}
sequenceRunning_ = true;

int err = GetHub()->StartAOSequenceForPort(niPort_, sentSequence_);
Expand Down Expand Up @@ -292,6 +310,21 @@ int NIAnalogOutputPort::OnSequenceable(MM::PropertyBase* pProp, MM::ActionType e
return DEVICE_OK;
}

int NIAnalogOutputPort::OnSequenceTransition(MM::PropertyBase* pProp, MM::ActionType eAct)
{
if (eAct == MM::BeforeGet)
{
pProp->Set(transitionPostExposure_ ? g_Post : g_Pre);
}
else if (eAct == MM::AfterSet)
{
std::string s;
pProp->Get(s);
transitionPostExposure_ = (s == g_Post);
}
return DEVICE_OK;
}


int NIAnalogOutputPort::OnVoltage(MM::PropertyBase* pProp, MM::ActionType eAct)
{
Expand Down
3 changes: 2 additions & 1 deletion DeviceAdapters/NIDAQ/NIDAQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ const char* g_On = "On";
const char* g_Off = "Off";
const char* g_Low = "Low";
const char* g_High = "High";

const char* g_Never = "Never";
const char* g_UseHubSetting = "Use hub setting";
const char* g_Post = "Post";
const char* g_Pre = "Pre";

const int ERR_SEQUENCE_RUNNING = 2001;
const int ERR_SEQUENCE_TOO_LONG = 2002;
Expand Down
6 changes: 5 additions & 1 deletion DeviceAdapters/NIDAQ/NIDAQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ extern const char* g_On;
extern const char* g_Off;
extern const char* g_Low;
extern const char* g_High;

extern const char* g_Never;
extern const char* g_Pre;
extern const char* g_Post;
extern const char* g_UseHubSetting;

extern const int ERR_SEQUENCE_RUNNING;
Expand Down Expand Up @@ -286,6 +287,7 @@ class NIAnalogOutputPort : public CSignalIOBase<NIAnalogOutputPort>,
int OnMinVolts(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnMaxVolts(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnSequenceable(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnSequenceTransition(MM::PropertyBase* pProp, MM::ActionType eAct);

// Post-init property action handlers
int OnVoltage(MM::PropertyBase* pProp, MM::ActionType eAct);
Expand All @@ -309,6 +311,8 @@ class NIAnalogOutputPort : public CSignalIOBase<NIAnalogOutputPort>,
double minVolts_; // User-selected for this port
double maxVolts_; // User-selected for this port
bool neverSequenceable_;
bool transitionPostExposure_; // when to transition in a sequence, not that we always transition on a rising flank
// it can be advantaguous to transition post exposure, in which case we have to modify our sequence

TaskHandle task_;

Expand Down

0 comments on commit 3c291c1

Please sign in to comment.