-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMMALNosepiece.cpp
143 lines (110 loc) · 3.58 KB
/
MMMALNosepiece.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* MMMALNosepiece.cpp
*
* Created on: Jul 13, 2013
* Author: Ji-Yu
*/
#include "MMMALNosepiece.h"
namespace MMMAL
{
const char * const MMMALNosepiece::DeviceName_ = "IXNosepiece";
const char * const MMMALNosepiece::Description_ = "Olympus IX Nosepiece";
MMMALNosepiece::MMMALNosepiece():initialized_(false)
{
InitializeDefaultErrorMessages();
CreateProperty(MM::g_Keyword_Name, DeviceName_, MM::String, true); // Name
CreateProperty(MM::g_Keyword_Description, Description_, MM::String, true); // Description
}
MMMALNosepiece::~MMMALNosepiece()
{
Shutdown();
}
int MMMALNosepiece::Shutdown()
{
initialized_ = false;
return DEVICE_OK;
}
void MMMALNosepiece::GetName(char *pszName) const
{
GetProperty(MM::g_Keyword_Name, pszName);
}
bool MMMALNosepiece::Busy()
{
return hub_->IsNosepieceBusy();
}
unsigned long MMMALNosepiece::GetNumberOfPositions() const
{
return hub_->GetNosepieceNPositions();
};
int MMMALNosepiece::Initialize()
{
int ret = DEVICE_OK;
if (initialized_)
{
return DEVICE_OK;
}
hub_ = static_cast<MMMALHub*>(GetParentHub());
if (hub_ == NULL)
{
return DEVICE_ERR;
}
hub_->SetNosepieceDevice(this);
int pos = hub_->GetNosepiecePosition();
CPropertyAction* pAct = new CPropertyAction (this, &MMMALNosepiece::OnState);
ret = CreateProperty(MM::g_Keyword_State, CDeviceUtils::ConvertToString((long)pos), MM::Integer, false, pAct);
if (ret != DEVICE_OK)
{
return ret;
}
SetPropertyLimits(MM::g_Keyword_State, 1, GetNumberOfPositions());
pAct = new CPropertyAction (this, &MMMALNosepiece::OnLabel);
ret = CreateProperty(MM::g_Keyword_Label, "", MM::String, false, pAct);
for (unsigned i = 1; i <= GetNumberOfPositions(); i++)
{
long bufSize = MM::MaxStrLength;
char buf[MM::MaxStrLength];
if (malGetObjectiveLensName(hub_->GetMALObject(), (MAL_MS_REVOLVERPOSITION)(MAL_MS_REVOLVERPOS0 + i), &bufSize, buf) == MAL_OK && bufSize > 0)
{
if (strcmp(buf, "---") != 0 )
{
SetPositionLabel(i, buf);
}
else
{
SetPositionLabel(i, CDeviceUtils::ConvertToString((int)i));
}
}
}
initialized_ = true;
return ret;
}
int MMMALNosepiece::OnState(MM::PropertyBase* pProp, MM::ActionType eAct)
{
int ret = DEVICE_OK;
if (eAct == MM::BeforeGet)
{
pProp->Set((long)(hub_->GetNosepiecePosition()));
}
else if (eAct == MM::AfterSet) {
long pos;
pProp->Get(pos);
assert((unsigned long) pos <= GetNumberOfPositions() && pos > 0);
ret = hub_->SetNosepiecePosition((int)pos, true);
}
return ret;
}
int MMMALNosepiece::StateChanged()
{
int ret = DEVICE_OK;
if (IsCallbackRegistered())
{
int pos = hub_->GetNosepiecePosition();
ret = GetCoreCallback()->OnPropertyChanged(this, MM::g_Keyword_State, CDeviceUtils::ConvertToString(pos));
char buf[MM::MaxStrLength];
GetPositionLabel(pos, buf);
ret = GetCoreCallback()->OnPropertyChanged(this, MM::g_Keyword_Label, buf);
//std::clog << "Lightpath state changed " << state << std::endl;
}
return ret;
}
}