Skip to content
Open
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
20 changes: 4 additions & 16 deletions DeviceAdapters/ASIStage/ASIBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,11 @@
#include "ASIBase.h"

ASIBase::ASIBase(MM::Device* device, const char* prefix) :
core_(nullptr),
device_(device),
port_("Undefined"),
initialized_(false),
oldstage_(false),
version_(Version()),
firmwareVersion_("Undefined"),
firmwareBuild_("Undefined"),
firmwareDate_("Undefined"),
oldstagePrefix_(prefix),
commandPrefix_(""),
serialTerm_("\r\n")
{
oldstagePrefix_(prefix) {
}

ASIBase::~ASIBase()
{
ASIBase::~ASIBase() {
}

// Clear contents of serial port
Expand Down Expand Up @@ -105,8 +93,8 @@ int ASIBase::CheckDeviceStatus() {

int ASIBase::GetVersion(std::string& version) const {
std::string answer;
if (const int error = QueryCommand("V", answer)) {
return error;
if (const int status = QueryCommand("V", answer); status != DEVICE_OK) {
return status;
}
if (answer.size() > 16 && answer.compare(0, 2, ":A") == 0) {
const size_t start = 16; // dash position
Expand Down
39 changes: 18 additions & 21 deletions DeviceAdapters/ASIStage/ASIBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* Jon Daniels (jon@asiimaging.com)
*/

#ifndef ASIBASE_H
#define ASIBASE_H
#pragma once

#include "ASIStage.h"
#include "MMDevice.h"
Expand All @@ -24,7 +23,7 @@
// New version format: ":A Version: USB-9.50 \r\n" (revision is a digit character: '0'-'9')
class Version {
public:
Version() : major_(0), minor_(0), rev_(0) { }
Version() = default;
explicit Version(unsigned int major, unsigned int minor, unsigned int rev)
: major_(major), minor_(minor), rev_(rev) { }

Expand Down Expand Up @@ -78,9 +77,9 @@ class Version {
}

private:
unsigned int major_;
unsigned int minor_;
unsigned int rev_;
unsigned int major_ = 0;
unsigned int minor_ = 0;
unsigned int rev_ = 0;
};

// Note: concrete device classes deriving ASIBase must set core_ in Initialize()
Expand Down Expand Up @@ -111,22 +110,20 @@ class ASIBase {
static constexpr size_t SERIAL_RXBUFFER_SIZE = 2048;
static constexpr size_t CLEAR_BUFFER_SIZE = 255;

MM::Core* core_;
MM::Device* device_;
std::string port_;
MM::Core* core_ = nullptr;
MM::Device* device_ = nullptr;
std::string port_ = "Undefined";

bool initialized_;
bool oldstage_;
bool initialized_ = false;
bool oldstage_ = false;

Version version_;
std::string firmwareVersion_;
std::string firmwareBuild_;
std::string firmwareDate_;
Version version_{};
std::string firmwareVersion_ = "Undefined";
std::string firmwareBuild_ = "Undefined";
std::string firmwareDate_ = "Undefined";

// Stage-specific configuration
std::string oldstagePrefix_; // "1H" or "2H" for LX-4000 stages, empty string for MS-2000 stages
std::string commandPrefix_; // set to oldstagePrefix_ if oldstage_ is true, otherwise empty string
std::string serialTerm_; // changes if oldstage_ is true
// stage-specific configuration
std::string oldstagePrefix_{}; // "1H" or "2H" for LX-4000 stages, empty string for MS-2000 stages
std::string commandPrefix_{}; // set to oldstagePrefix_ if oldstage_ is true, otherwise empty string
std::string serialTerm_ = "\r\n"; // changes if oldstage_ is true
};

#endif // ASIBASE_H
57 changes: 20 additions & 37 deletions DeviceAdapters/ASIStage/ASICRISP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,14 @@ constexpr char SetLockOffset[] = "Set Lock Offset (Advanced Users Only)";
namespace Props = Properties;
} // namespace

CRISP::CRISP() :
ASIBase(this, ""),
axisLetter_("Z"),
focusState_(""),
waitAfterLock_(1000),
answerTimeoutMs_(1000),
// init cached properties
gainMultiplier_(0),
ledIntensity_(0),
numAverages_(0),
numSkips_(0),
calibrationRange_(0),
inFocusRange_(0),
lockRange_(0),
objectiveNA_(0)
{
CRISP::CRISP() : ASIBase(this, "") {
InitializeDefaultErrorMessages();

SetErrorText(ERR_NOT_CALIBRATED, "CRISP is not calibrated. Try focusing close to a coverslip and selecting 'Calibrate'");
SetErrorText(ERR_UNRECOGNIZED_ANSWER, "The ASI controller said something incomprehensible");
SetErrorText(ERR_NOT_LOCKED, "The CRISP failed to lock");

// create pre-initialization properties
// ------------------------------------
// create pre-init properties

// Name
CreateProperty(MM::g_Keyword_Name, g_CRISPDeviceName, MM::String, true);
Expand Down Expand Up @@ -403,12 +387,11 @@ int CRISP::SetFocusState(const std::string& focusState) {
return DEVICE_OK;
}

if (const int error = ForceSetFocusState(focusState)) {
return error;
if (const int status = ForceSetFocusState(focusState); status != DEVICE_OK) {
return status;
}

focusState_ = focusState;

return DEVICE_OK;
}

Expand Down Expand Up @@ -497,8 +480,8 @@ int CRISP::SetContinuousFocusing(bool state)

// Update focusState_ from the controller and check if focus is locked or trying to lock ('F' or 'K' state).
int CRISP::GetContinuousFocusing(bool& state) {
if (const int error = UpdateFocusState()) {
return error;
if (const int status = UpdateFocusState(); status != DEVICE_OK) {
return status;
}
state = (focusState_ == g_CRISP_K) || (focusState_ == g_CRISP_F);
return DEVICE_OK;
Expand Down Expand Up @@ -558,8 +541,8 @@ int CRISP::GetCurrentFocusScore(double& score) {

int CRISP::GetValue(const std::string& command, double& value) {
std::string answer;
if (const int error = QueryCommand(command.c_str(), answer)) {
return error;
if (const int status = QueryCommand(command.c_str(), answer); status != DEVICE_OK) {
return status;
}

if (answer.length() > 2 && answer.compare(0, 2, ":N") == 0) {
Expand All @@ -584,8 +567,8 @@ int CRISP::GetValue(const std::string& command, double& value) {

int CRISP::SetCommand(const std::string& command) {
std::string answer;
if (const int error = QueryCommand(command.c_str(), answer)) {
return error;
if (const int status = QueryCommand(command.c_str(), answer); status != DEVICE_OK) {
return status;
}
if (answer.compare(0, 2, ":A") == 0) {
return DEVICE_OK;
Expand Down Expand Up @@ -621,14 +604,14 @@ int CRISP::OnPort(MM::PropertyBase* pProp, MM::ActionType eAct)
int CRISP::OnFocus(MM::PropertyBase* pProp, MM::ActionType eAct)
{
if (eAct == MM::BeforeGet) {
if (const int error = UpdateFocusState()) {
return error;
if (const int status = UpdateFocusState(); status != DEVICE_OK) {
return status;
}
pProp->Set(focusState_.c_str());
} else if (eAct == MM::AfterSet) {
pProp->Get(focusState_);
if (const int error = SetFocusState(focusState_)) {
return error;
if (const int status = SetFocusState(focusState_); status != DEVICE_OK) {
return status;
}
}
return DEVICE_OK;
Expand Down Expand Up @@ -1016,8 +999,8 @@ void CRISP::CreateStateProperty() {
new MM::ActionLambda([this](MM::PropertyBase* pProp, MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
std::string answer;
if (const int error = QueryCommand("LK X?", answer)) {
return error;
if (const int status = QueryCommand("LK X?", answer); status != DEVICE_OK) {
return status;
}
const char* state = &answer[answer.size() - 1];
if (!pProp->Set(state)) {
Expand Down Expand Up @@ -1056,8 +1039,8 @@ void CRISP::CreateLockOffsetProperty() {
new MM::ActionLambda([this](MM::PropertyBase* pProp, MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
double offset; // Note: autofocus API requires double
if (const int error = GetOffset(offset)) {
return error;
if (const int status = GetOffset(offset); status != DEVICE_OK) {
return status;
}
// cast to long to match integer property
if (!pProp->Set(static_cast<long>(offset))) {
Expand Down Expand Up @@ -1174,8 +1157,8 @@ void CRISP::CreateLogAmpAGCProperty() {
new MM::ActionLambda([this](MM::PropertyBase* pProp, MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
double tmp{}; // Note: response is ":A X=1.000000", parse as double
if (const int error = GetValue("AL X?", tmp)) {
return error;
if (const int status = GetValue("AL X?", tmp); status != DEVICE_OK) {
return status;
}
// cast to long to match integer property
pProp->Set(static_cast<long>(tmp));
Expand Down
31 changes: 14 additions & 17 deletions DeviceAdapters/ASIStage/ASICRISP.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* Jon Daniels (jon@asiimaging.com)
*/

#ifndef ASICRISP_H
#define ASICRISP_H
#pragma once

#include "ASIBase.h"

Expand Down Expand Up @@ -87,24 +86,22 @@ class CRISP : public CAutoFocusBase<CRISP>, public ASIBase {
void CreateSetLogAmpAGCProperty();
void CreateSetLockOffsetProperty();

std::string axisLetter_;
std::string focusState_;
long waitAfterLock_;
std::string axisLetter_ = "Z"; // determined by pre-init property
std::string focusState_{};

int answerTimeoutMs_;
long waitAfterLock_ = 1000;
int answerTimeoutMs_ = 1000;

// cached properties
long gainMultiplier_;
long ledIntensity_;
long numAverages_;
long numSkips_; // update rate (milliseconds)
double calibrationRange_; // microns
double inFocusRange_; // microns
double lockRange_; // millimeters
double objectiveNA_;
long gainMultiplier_ = 0;
long ledIntensity_ = 0;
long numAverages_ = 0;
long numSkips_ = 0; // update rate (milliseconds)
double calibrationRange_ = 0; // microns
double inFocusRange_ = 0; // microns
double lockRange_ = 0; // millimeters
double objectiveNA_ = 0;

static constexpr int SIZE_OF_FC_ARRAY = 24;
std::string focusCurveData_[SIZE_OF_FC_ARRAY];
std::string focusCurveData_[SIZE_OF_FC_ARRAY]{};
};

#endif // ASICRISP_H
15 changes: 2 additions & 13 deletions DeviceAdapters/ASIStage/ASILED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@

#include "ASILED.h"

LED::LED() :
ASIBase(this, ""),
open_(false),
intensity_(20),
name_("LED"),
answerTimeoutMs_(1000),
channel_(0),
channelAxisChar_('X'),
hasDLED_(false)
{
LED::LED() : ASIBase(this, "") {
InitializeDefaultErrorMessages();

// create pre-initialization properties
// ------------------------------------
// create pre-init properties

// Name
CreateProperty(MM::g_Keyword_Name, g_LEDDeviceName, MM::String, true);
Expand Down Expand Up @@ -51,7 +41,6 @@ void LED::GetName(char* name) const
CDeviceUtils::CopyLimitedString(name, g_LEDDeviceName);
}


bool LED::SupportsDeviceDetection()
{
return true;
Expand Down
24 changes: 11 additions & 13 deletions DeviceAdapters/ASIStage/ASILED.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* Jon Daniels (jon@asiimaging.com)
*/

#ifndef ASILED_H
#define ASILED_H
#pragma once

#include "ASIBase.h"

class LED : public CShutterBase<LED>, public ASIBase
{
class LED : public CShutterBase<LED>, public ASIBase {
public:
LED();
~LED();
Expand Down Expand Up @@ -40,13 +38,13 @@ class LED : public CShutterBase<LED>, public ASIBase
int IsOpen(bool* open); // queries the device rather than using a cached value
int CurrentIntensity(long* intensity); // queries the device rather than using a cached value

bool open_;
long intensity_;
std::string name_;
int answerTimeoutMs_;
long channel_;
char channelAxisChar_;
bool hasDLED_;
};
std::string name_ = "LED";
long channel_ = 0;
char channelAxisChar_ = 'X';

bool open_ = false;
bool hasDLED_ = false;

#endif // ASILED_H
long intensity_ = 20;
int answerTimeoutMs_ = 1000;
};
17 changes: 4 additions & 13 deletions DeviceAdapters/ASIStage/ASIMagnifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@

#include "ASIMagnifier.h"

Magnifier::Magnifier() :
ASIBase(this, ""),
axis_("M"), // normally the zoom axis is the M axis
answerTimeoutMs_(1000)
{
Magnifier::Magnifier() : ASIBase(this, "") {
InitializeDefaultErrorMessages();

// create pre-initialization properties
// ------------------------------------
// create pre-init properties

// Name
CreateProperty(MM::g_Keyword_Name, g_MagnifierDeviceName, MM::String, true);
Expand Down Expand Up @@ -110,12 +105,8 @@ int Magnifier::Initialize()
return DEVICE_OK;
}

int Magnifier::Shutdown()
{
if (initialized_)
{
initialized_ = false;
}
int Magnifier::Shutdown() {
initialized_ = false;
return DEVICE_OK;
}

Expand Down
Loading
Loading