MMDevice
Loading...
Searching...
No Matches
DeviceBase.h
Go to the documentation of this file.
1
2// FILE: DeviceBase.h
3// PROJECT: Micro-Manager
4// SUBSYSTEM: MMDevice - Device adapter kit
5//-----------------------------------------------------------------------------
6// DESCRIPTION: Generic functionality for implementing device adapters
7//
8// AUTHOR: Nenad Amodaj, nenad@amodaj.com, 08/18/2005
9//
10// COPYRIGHT: University of California, San Francisco, 2006
11//
12// LICENSE: This file is distributed under the BSD license.
13// License text is included with the source distribution.
14//
15// This file is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty
17// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18//
19// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
22//
23
24#pragma once
25
26#include "MMDevice.h"
27
28#include "CameraImageMetadata.h"
29#include "DeviceThreads.h"
30#include "DeviceUtils.h"
31#include "MMDeviceConstants.h"
32#include "ModuleInterface.h"
33#include "Property.h"
34
35#include <math.h>
36#include <assert.h>
37
38#include <string>
39#include <vector>
40#include <iomanip>
41#include <map>
42#include <sstream>
43#include <utility>
44
45// common error messages
46const char* const g_Msg_ERR = "Unknown error in the device";
47const char* const g_Msg_INVALID_PROPERTY = "Invalid property name encountered";
48const char* const g_Msg_INVALID_PROPERTY_VALUE = "Invalid property value";
49const char* const g_Msg_DUPLICATE_PROPERTY = "Duplicate property names are not allowed";
50const char* const g_Msg_INVALID_PROPERTY_TYPE = "Invalid property type";
51const char* const g_Msg_NATIVE_MODULE_FAILED = "Native module failed to load";
52const char* const g_Msg_UNSUPPORTED_DATA_FORMAT = "Unsupported data format encountered";
53const char* const g_Msg_INTERNAL_INCONSISTENCY = "Device adapter inconsistent with the actual device";
54const char* const g_Msg_NOT_SUPPORTED = "Device not supported by the adapter";
55const char* const g_Msg_UNKNOWN_LABEL = "Label not defined";
56const char* const g_Msg_UNSUPPORTED_COMMAND = "Unsupported device command";
57const char* const g_Msg_UNKNOWN_POSITION = "Invalid state (position) requested";
58const char* const g_Msg_NO_CALLBACK_REGISTERED = "No callback registered";
59const char* const g_Msg_SERIAL_BUFFER_OVERRUN = "Serial buffer overrun.";
60const char* const g_Msg_SERIAL_INVALID_RESPONSE = "Unexpected response from serial port. Is the device connected to the correct serial port?";
61const char* const g_Msg_SERIAL_TIMEOUT = "Serial timeout occurred.";
62const char* const g_Msg_SELF_REFERENCE = "Self reference error.";
63const char* const g_Msg_NO_PROPERTY_DATA = "No property data error.";
64const char* const g_Msg_DEVICE_DUPLICATE_LABEL = "Position label already in use";
65const char* const g_Msg_INVALID_INPUT_PARAM = "Invalid input parameter.";
66const char* const g_Msg_BUFFER_OVERFLOW = "Buffer Overflow.";
67const char* const g_Msg_SERIAL_COMMAND_FAILED = "Serial command failed. Is the device connected to the serial port?";
68const char* const g_Msg_DEVICE_NONEXISTENT_CHANNEL = "Requested channel is not defined.";
69const char* const g_Msg_DEVICE_INVALID_PROPERTY_LIMTS = "Specified property limits are not valid."
70" Either the property already has a set of discrete values, or the range is invalid";
71const char* const g_Msg_EXCEPTION_IN_THREAD = "Exception in the thread function.";
72const char* const g_Msg_EXCEPTION_IN_ON_THREAD_EXITING = "Exception in the OnThreadExiting function.";
73const char* const g_Msg_SEQUENCE_ACQUISITION_THREAD_EXITING="Sequence thread exiting";
74const char* const g_Msg_DEVICE_CAMERA_BUSY_ACQUIRING="Camera is busy acquiring images. Stop camera activity before changing this property";
75const char* const g_Msg_DEVICE_CAN_NOT_SET_PROPERTY="The device can not set this property at this moment";
76const char* const g_Msg_DEVICE_NOT_CONNECTED="Unable to communicate with the device.";
77const char* const g_Msg_DEVICE_COMM_HUB_MISSING= "Parent module (Hub) is not available or defined for this device!";
78const char* const g_Msg_DEVICE_DUPLICATE_LIBRARY="Duplicate Device Library Name";
79const char* const g_Msg_DEVICE_PROPERTY_NOT_SEQUENCEABLE="This property is not sequenceable";
80const char* const g_Msg_DEVICE_SEQUENCE_TOO_LARGE="Sequence is too large for this device";
81const char* const g_Msg_DEVICE_NOT_YET_IMPLEMENTED="This command has not yet been implemented for this device.";
82
83inline long nint( double value )
84{
85 return (long)floor( 0.5 + value);
86};
87
95template <class T, class U>
96class CDeviceBase : public T
97{
98public:
99
102
106 virtual void SetModuleName(const char* name)
107 {
108 moduleName_ = name;
109 }
110
114 virtual void GetModuleName(char* name) const
115 {
116 CDeviceUtils::CopyLimitedString(name, moduleName_.c_str());
117 }
118
122 virtual void SetDescription(const char* descr)
123 {
124 description_ = descr;
125 }
126
130 virtual void GetDescription(char* name) const
131 {
132 CDeviceUtils::CopyLimitedString(name, description_.c_str());
133 }
134
141 virtual void SetLabel(const char* label)
142 {
143 label_ = label;
144 }
145
152 virtual void GetLabel(char* name) const
153 {
154 CDeviceUtils::CopyLimitedString(name, label_.c_str());
155 }
156
163 virtual double GetDelayMs() const {return delayMs_;}
164
171 virtual void SetDelayMs(double delay) {delayMs_ = delay;}
172
176 virtual void SetCallback(MM::Core* cbk) {callback_ = cbk;}
177
183 virtual bool UsesDelay() {return usesDelay_;}
184
188 virtual unsigned GetNumberOfProperties() const {return (unsigned)properties_.GetSize();}
189
196 virtual int GetProperty(const char* name, char* value) const
197 {
198 std::string strVal;
199 // additional information for reporting invalid properties.
201 int nRet = properties_.Get(name, strVal);
202 if (nRet == DEVICE_OK)
203 CDeviceUtils::CopyLimitedString(value, strVal.c_str());
204 return nRet;
205 }
206
213 int GetProperty(const char* name, double& val)
214 {
215 std::string strVal;
216 int nRet = properties_.Get(name, strVal);
217 if (nRet == DEVICE_OK)
218 val = atof(strVal.c_str());
219 return nRet;
220 }
221
228 int GetProperty(const char* name, long& val)
229 {
230 std::string strVal;
231 int nRet = properties_.Get(name, strVal);
232 if (nRet == DEVICE_OK)
233 val = atol(strVal.c_str());
234 return nRet;
235 }
236
245 bool IsPropertyEqualTo(const char* name, const char* val) const
246 {
247 std::string strVal;
248 int nRet = properties_.Get(name, strVal);
249 if (nRet == DEVICE_OK)
250 return strcmp(val, strVal.c_str()) == 0;
251 else
252 return false;
253 }
254
261 virtual int GetPropertyReadOnly(const char* name, bool& readOnly) const
262 {
263 MM::Property* pProp = properties_.Find(name);
264 if (!pProp)
265 {
266 // additional information for reporting invalid properties.
269 }
270 readOnly = pProp->GetReadOnly();
271
272 return DEVICE_OK;
273 }
274
281 virtual int GetPropertyInitStatus(const char* name, bool& preInit) const
282 {
283 MM::Property* pProp = properties_.Find(name);
284 if (!pProp)
285 {
286 // additional information for reporting invalid properties.
289 }
290 preInit = pProp->GetInitStatus();
291
292 return DEVICE_OK;
293 }
294
295 virtual int HasPropertyLimits(const char* name, bool& hasLimits) const
296 {
297 MM::Property* pProp = properties_.Find(name);
298 if (!pProp)
299 {
300 // additional information for reporting invalid properties.
303 }
304 hasLimits = pProp->HasLimits();
305 return DEVICE_OK;
306 }
307
314 virtual int GetPropertyLowerLimit(const char* name, double& lowLimit) const
315 {
316 MM::Property* pProp = properties_.Find(name);
317 if (!pProp)
318 {
319 // additional information for reporting invalid properties.
322 }
323 lowLimit = pProp->GetLowerLimit();
324 return DEVICE_OK;
325 }
326
333 virtual int GetPropertyUpperLimit(const char* name, double& hiLimit) const
334 {
335 MM::Property* pProp = properties_.Find(name);
336 if (!pProp)
337 {
338 // additional information for reporting invalid properties.
341 }
342 hiLimit = pProp->GetUpperLimit();
343 return DEVICE_OK;
344 }
345
352 virtual int IsPropertySequenceable(const char* name, bool& sequenceable) const
353 {
354 MM::Property* pProp = properties_.Find(name);
355 if (!pProp)
356 {
357 // additional information for reporting invalid properties.
360 }
361 sequenceable = pProp->IsSequenceable();
362
363 return DEVICE_OK;
364 }
365
372 virtual int GetPropertySequenceMaxLength(const char* name, long& nrEvents) const
373 {
374 MM::Property* pProp = properties_.Find(name);
375 if (!pProp)
376 {
377 // additional information for reporting invalid properties.
380 }
381 bool sequenceable;
382 int ret = IsPropertySequenceable(name, sequenceable);
383 if (ret != DEVICE_OK)
384 return ret;
385 if (!sequenceable) {
388 }
389
390 nrEvents = pProp->GetSequenceMaxSize();
391
392 return DEVICE_OK;
393 }
394
403 virtual int StartPropertySequence(const char* name)
404 {
405 MM::Property* pProp = properties_.Find(name);
406 if (!pProp)
407 {
408 // additional information for reporting invalid properties.
411 }
412 bool sequenceable;
413 int ret = IsPropertySequenceable(name, sequenceable);
414 if (ret != DEVICE_OK)
415 return ret;
416 if (!sequenceable) {
419 }
420
421 return pProp->StartSequence();
422 }
423
432 virtual int StopPropertySequence(const char* name)
433 {
434 MM::Property* pProp = properties_.Find(name);
435 if (!pProp)
436 {
439 }
440 bool sequenceable;
441 int ret = IsPropertySequenceable(name, sequenceable);
442 if (ret != DEVICE_OK)
443 return ret;
444 if (!sequenceable) {
447 }
448
449 return pProp->StopSequence();
450 }
451
460 virtual int ClearPropertySequence(const char* name)
461 {
462 MM::Property* pProp;
463 int ret = GetSequenceableProperty(&pProp, name);
464 if (ret != DEVICE_OK)
465 return ret;
466
467 return pProp->ClearSequence();
468 }
469
479 virtual int AddToPropertySequence(const char* name, const char* value)
480 {
481 MM::Property* pProp;
482 int ret = GetSequenceableProperty(&pProp, name);
483 if (ret != DEVICE_OK)
484 return ret;
485
486 return pProp->AddToSequence(value);
487 }
488
498 virtual int SendPropertySequence(const char* name)
499 {
500 MM::Property* pProp;
501 int ret = GetSequenceableProperty(&pProp, name);
502 if (ret != DEVICE_OK)
503 return ret;
504
505 return pProp->SendSequence();
506 }
507
516 virtual bool GetPropertyName(unsigned uIdx, char* name) const
517 {
518 std::string strName;
519 if (!properties_.GetName(uIdx, strName))
520 return false;
521
522 CDeviceUtils::CopyLimitedString(name, strName.c_str());
523 return true;
524 }
525
529 virtual int GetPropertyType(const char* name, MM::PropertyType& pt) const
530 {
531 MM::Property* pProp = properties_.Find(name);
532 if (!pProp)
534
535 pt = pProp->GetType();
536 return DEVICE_OK;
537 }
538
545 virtual int SetProperty(const char* name, const char* value)
546 {
547 int ret = properties_.Set(name, value);
548 if( DEVICE_OK != ret)
549 {
550 // additional information for reporting invalid properties.
552
553 }
554 return ret;
555 }
556
560 virtual bool HasProperty(const char* name) const
561 {
562 MM::Property* pProp = properties_.Find(name);
563 if (pProp)
564 return true;
565 else
566 return false;
567 }
568
575 virtual unsigned GetNumberOfPropertyValues(const char* propertyName) const
576 {
577 MM::Property* pProp = properties_.Find(propertyName);
578 if (!pProp)
579 return 0;
580
581 return (unsigned)pProp->GetAllowedValues().size();
582 }
583
593 virtual bool GetPropertyValueAt(const char* propertyName, unsigned index, char* value) const
594 {
595 MM::Property* pProp = properties_.Find(propertyName);
596 if (!pProp)
597 return false;
598
599 std::vector<std::string> values = pProp->GetAllowedValues();
600 if (values.size() < index)
601 return false;
602
603 CDeviceUtils::CopyLimitedString(value, values[index].c_str());
604 return true;
605 }
606
618 int CreateProperty(const char* name, const char* value, MM::PropertyType eType, bool readOnly, MM::ActionFunctor* pAct=0, bool isPreInitProperty=false)
619 {
620 return properties_.CreateProperty(name, value, eType, readOnly, pAct, isPreInitProperty);
621 }
622
635 int CreatePropertyWithHandler(const char* name, const char* value, MM::PropertyType eType, bool readOnly,
636 int(U::*memberFunction)(MM::PropertyBase* pProp, MM::ActionType eAct), bool isPreInitProperty=false) {
637 CPropertyAction* pAct = new CPropertyAction((U*) this, memberFunction);
638 return CreateProperty(name, value, eType, readOnly, pAct, isPreInitProperty);
639 }
640
644 int CreateIntegerProperty(const char* name, long value, bool readOnly, MM::ActionFunctor* pAct = 0, bool isPreInitProperty = false)
645 {
646 // Note: in theory, we can avoid converting to string and back. At this
647 // moment, it is not worth the trouble.
648 std::ostringstream oss;
649 oss << value;
650 return CreateProperty(name, oss.str().c_str(), MM::Integer, readOnly, pAct, isPreInitProperty);
651 }
652
656 int CreateFloatProperty(const char* name, double value, bool readOnly, MM::ActionFunctor* pAct = 0, bool isPreInitProperty = false)
657 {
658 // Note: in theory, we can avoid converting to string and back. At this
659 // moment, it is not worth the trouble.
660 //
661 // However, note the following assumption being made here: the default
662 // settings of std::ostream will return strings with a decimal precision
663 // of 6 digits. When this eventually gets passed to
664 // MM::FloatProperty::Set(double), it gets truncated to 4 digits before
665 // being stored. Thus, we do not loose any information.
666 std::ostringstream oss;
667 oss << value;
668 return CreateProperty(name, oss.str().c_str(), MM::Float, readOnly, pAct, isPreInitProperty);
669 }
670
674 int CreateStringProperty(const char* name, const char* value, bool readOnly, MM::ActionFunctor* pAct = 0, bool isPreInitProperty = false)
675 {
676 return CreateProperty(name, value, MM::String, readOnly, pAct, isPreInitProperty);
677 }
678
682 int SetPropertyLimits(const char* name, double low, double high)
683 {
684 MM::Property* pProp = properties_.Find(name);
685 if (!pProp)
686 {
689 }
690 if (pProp->SetLimits(low, high))
691 return DEVICE_OK;
692 else {
693 std::ostringstream os;
694 os << "Device adapter requests invalid values ( " << low << ", ";
695 os << high << ") for property: " << name;
696 LogMessage(os.str().c_str(), false);
698 }
699 }
700
709 int ClearPropertyLimits(const char* name)
710 {
711 MM::Property* pProp = properties_.Find(name);
712 if (!pProp)
713 {
716 }
717 pProp->ClearLimits();
718 return DEVICE_OK;
719 }
720
724 int SetAllowedValues(const char* name, std::vector<std::string>& values)
725 {
726 return properties_.SetAllowedValues(name, values);
727 }
728
732 int ClearAllowedValues(const char* name)
733 {
734 return properties_.ClearAllowedValues(name);
735 }
736
740 int AddAllowedValue(const char* name, const char* value)
741 {
742 return properties_.AddAllowedValue(name, value);
743 }
744
748 int AddAllowedValue(const char* name, const char* value, long data)
749 {
750 return properties_.AddAllowedValue(name, value, data);
751 }
752
756 int GetPropertyData(const char* name, const char* value, long& data)
757 {
758 int ret = properties_.GetPropertyData(name, value, data);
759 if( DEVICE_OK != ret)
760 // additional information for reporting invalid properties.
762
763 return ret;
764 }
765
769 int GetCurrentPropertyData(const char* name, long& data)
770 {
771 int ret = properties_.GetCurrentPropertyData(name, data);
772 if( DEVICE_OK != ret)
773 // additional information for reporting invalid properties.
775
776 return ret;
777 }
778
784 {
785 return properties_.UpdateAll();
786 }
787
791 int UpdateProperty(const char* name)
792 {
793 return properties_.Update(name);
794 }
795
796
800 int ApplyProperty(const char* name)
801 {
802 return properties_.Apply(name);
803 }
804
808 virtual bool GetErrorText(int errorCode, char* text) const
809 {
810 std::map<int, std::string>::const_iterator it;
811 it = messages_.find(errorCode);
812 if (it == messages_.end())
813 {
814 // generic message
815 std::ostringstream osTxt;
816 osTxt << "Error code " << errorCode << " (" << std::setbase(16) << errorCode << " hex)";
817 CDeviceUtils::CopyLimitedString(text, osTxt.str().c_str());
818 return false; // message text not found
819 }
820 else
821 {
822 std::ostringstream stringStreamMessage;
823 stringStreamMessage << it->second.c_str();
824 // add the additional 'property' error info.
825 if( 2<=errorCode && errorCode<=5 )
826 {
827 stringStreamMessage << ": " << GetMorePropertyErrorInfo();
828 }
830 // native message
831 CDeviceUtils::CopyLimitedString(text, stringStreamMessage.str().c_str());
832 return true; // message found
833 }
834 }
835
836 // device discovery (auto-configuration)
837 virtual bool SupportsDeviceDetection(void) {
838 return false;
839 }
843
844 // hub - peripheral relationship
845 virtual void SetParentID(const char* parentId)
846 {
847 parentID_ = parentId;
848
849 // truncate if necessary
850 if (parentID_.size() >= (unsigned) MM::MaxStrLength)
851 parentID_ = parentID_.substr(MM::MaxStrLength-1);
852
854 {
855 this->SetProperty(MM::g_Keyword_HubID, parentID_.c_str());
856 }
857 }
858
859 virtual void GetParentID(char* parentID) const
860 {
861 CDeviceUtils::CopyLimitedString(parentID, parentID_.c_str());
862 }
863
865 // Protected methods, for internal use by the device adapters
867
868protected:
869
870 CDeviceBase() : delayMs_(0), usesDelay_(false), callback_(0)
871 {
873 }
874 virtual ~CDeviceBase() {}
875
879 void SetErrorText(int errorCode, const char* text)
880 {
881 messages_[errorCode] = text;
882 }
883
884 const char* GetMorePropertyErrorInfo(void) const
885 {
886 return morePropertyErrorInfo_.c_str();
887 }
888
889 void SetMorePropertyErrorInfo( const char* ptext) const
890 {
891 morePropertyErrorInfo_ = ptext;
892 }
893
901 int LogMessage(const char* msg, bool debugOnly = false) const
902 {
903 if (callback_)
904 return callback_->LogMessage(this, msg, debugOnly);
906 }
907
915 int LogMessage(const std::string& msg, bool debugOnly = false) const
916 {
917 if (callback_)
918 return callback_->LogMessage(this, msg.c_str(), debugOnly);
920 }
921
929 int LogMessageCode(const int errorCode, bool debugOnly = false) const
930 {
931 if (callback_)
932 {
933 char text[MM::MaxStrLength];
934 GetErrorText(errorCode, text);
935 return callback_->LogMessage(this, text, debugOnly);
936 }
938 }
939
940
952 int LogTimeDiff(MM::MMTime start, MM::MMTime end, const std::string& message, bool debugOnly = false) const
953 {
954 std::ostringstream os;
955 MM::MMTime t = end-start;
956 os << message << t.toString() << " seconds";
957 if (callback_)
958 return callback_->LogMessage(this, os.str().c_str(), debugOnly);
960 }
961
972 int LogTimeDiff(MM::MMTime start, MM::MMTime end, bool debugOnly = false) const
973 {
974 return LogTimeDiff(start, end, "Process took: " , debugOnly);
975 }
976
981 {
982 // initialize error codes
1016 }
1017
1024 MM::Device* GetDevice(const char* deviceLabel) const
1025 {
1026 if (callback_)
1027 return callback_->GetDevice(this, deviceLabel);
1028 return 0;
1029 }
1030
1040 // Microsoft compiler has trouble generating code to transport stl objects across DLL boundary
1041 // so we use char*. Other compilers could conceivably have similar trouble, if for example,
1042 // a dynamic library is linked with a different CRT than its client.
1043 void GetLoadedDeviceOfType(MM::DeviceType devType, char* deviceName, const unsigned int deviceIterator )
1044 {
1045 deviceName[0] = 0;
1046 if (callback_)
1047 {
1048 callback_->GetLoadedDeviceOfType( this, devType, deviceName, deviceIterator);
1049 }
1050 }
1051
1052
1056 int WriteToComPort(const char* portLabel, const unsigned char* buf, unsigned bufLength)
1057 {
1058 if (callback_)
1059 return callback_->WriteToSerial(this, portLabel, buf, bufLength);
1060
1062 }
1063
1072 int SendSerialCommand(const char* portName, const char* command, const char* term)
1073 {
1074 if (callback_)
1075 return callback_->SetSerialCommand(this, portName, command, term);
1076
1078 }
1079
1088 int GetSerialAnswer (const char* portName, const char* term, std::string& ans)
1089 {
1090 const unsigned long MAX_BUFLEN = 2000;
1091 char buf[MAX_BUFLEN];
1092 if (callback_)
1093 {
1094 int ret = callback_->GetSerialAnswer(this, portName, MAX_BUFLEN, buf, term);
1095 if (ret != DEVICE_OK)
1096 return ret;
1097 ans = buf;
1098 return DEVICE_OK;
1099 }
1100
1102 }
1103
1107 int ReadFromComPort(const char* portLabel, unsigned char* buf, unsigned bufLength, unsigned long& read)
1108 {
1109 if (callback_)
1110 return callback_->ReadFromSerial(this, portLabel, buf, bufLength, read);
1112 }
1113
1117 int PurgeComPort(const char* portLabel)
1118 {
1119 if (callback_)
1120 return callback_->PurgeSerial(this, portLabel);
1122 }
1123
1129 MM::PortType GetSerialPortType(const char* portLabel)
1130 {
1131 if (callback_)
1132 return callback_->GetSerialPortType(portLabel);
1133 return MM::InvalidPort;
1134 }
1135
1145 {
1146 if (callback_)
1147 return callback_->OnPropertiesChanged(this);
1149 }
1150
1154 int OnPropertyChanged(const char* propName, const char* propValue)
1155 {
1156 if (callback_)
1157 return callback_->OnPropertyChanged(this, propName, propValue);
1159 }
1160
1173 {
1174 if (callback_)
1175 return callback_->OnStagePositionChanged(this, pos);
1177 }
1178
1190 int OnXYStagePositionChanged(double xPos, double yPos)
1191 {
1192 if (callback_)
1193 return callback_->OnXYStagePositionChanged(this, xPos, yPos);
1195 }
1196
1200 int OnExposureChanged(double exposure)
1201 {
1202 if (callback_)
1203 return callback_->OnExposureChanged(this, exposure);
1205 }
1206
1210 int OnSLMExposureChanged(double exposure)
1211 {
1212 if (callback_)
1213 return callback_->OnSLMExposureChanged(this, exposure);
1215 }
1216
1221 {
1222 if (callback_)
1223 return callback_->OnMagnifierChanged(this);
1225 }
1226
1232 unsigned long GetClockTicksUs()
1233 {
1234 if (callback_)
1235 return callback_->GetClockTicksUs(this);
1236
1237 return 0;
1238 }
1239
1244 {
1245 if (callback_)
1246 return callback_->GetCurrentMMTime();
1247
1248 return MM::MMTime(0.0);
1249 }
1250
1255 {
1256 return callback_ == 0 ? false : true;
1257 }
1258
1263 {
1264 return callback_;
1265 }
1266
1273 void EnableDelay(bool state = true)
1274 {
1275 usesDelay_ = state;
1276 }
1277
1287 {
1288 char pid[MM::MaxStrLength];
1289 this->GetParentID(pid);
1291 }
1292
1301 {
1303 return GetCoreCallback()->GetParentHub(this);
1304
1305 return 0;
1306 }
1307
1313 template<class T_HUB>
1314 T_HUB* AssignToHub() {
1315 T_HUB* hub = static_cast<T_HUB*>(GetParentHub());
1316 if (hub == NULL) {
1317 LogMessage("Parent hub not defined.");
1318 } else {
1319 char hubLabel[MM::MaxStrLength];
1320 hub->GetLabel(hubLabel);
1321 SetParentID(hubLabel); // for backward comp.
1322 }
1323 return hub;
1324 }
1325
1326private:
1327 bool PropertyDefined(const char* propName) const
1328 {
1329 return properties_.Find(propName) != 0;
1330 }
1331
1342 int GetSequenceableProperty(MM::Property** pProp, const char* name) const
1343 {
1344 *pProp = properties_.Find(name);
1345 if (!*pProp)
1346 {
1349 }
1350
1351 bool sequenceable = (*pProp)->IsSequenceable();
1352 if (!sequenceable) {
1355 }
1356 return DEVICE_OK;
1357 }
1358
1359
1360 MM::PropertyCollection properties_;
1361 std::string label_;
1362 std::string moduleName_;
1363 std::string description_;
1364 std::map<int, std::string> messages_;
1365 double delayMs_;
1366 bool usesDelay_;
1367 MM::Core* callback_;
1368 // specific information about the errant property, etc.
1369 mutable std::string morePropertyErrorInfo_;
1370 std::string parentID_;
1371};
1372
1373// Forbid instantiation of CDeviceBase<MM::Device, U>
1374// (It was abused in the past.)
1375template <class U>
1376class CDeviceBase<MM::Device, U>
1377{
1378 CDeviceBase(); // private; construction disallowed
1379};
1380
1384template <class U>
1385class CGenericBase : public CDeviceBase<MM::Generic, U>
1386{
1387};
1388
1389
1396template <class U>
1397class CCameraBase : public CDeviceBase<MM::Camera, U>
1398{
1399public:
1400 // These 2 'using' declarations were originally introduced in order to allow
1401 // C[Legacy]CameraBase member functions to call these functions (which would
1402 // have also been possible with 'this->'). The 2 functions are protected in
1403 // CDeviceBase. However, they are made public here, and some concrete
1404 // cameras ended up depending on that. So they need to be kept for now,
1405 // until and unless such cameras are fixed.
1408
1410 {
1411 // create and initialize common transpose properties
1412 std::vector<std::string> allowedValues;
1413 allowedValues.push_back("0");
1414 allowedValues.push_back("1");
1423
1424 }
1425
1426 virtual const unsigned char* GetImageBuffer() = 0;
1427 virtual unsigned GetImageWidth() const = 0;
1428 virtual unsigned GetImageHeight() const = 0;
1429 virtual unsigned GetImageBytesPerPixel() const = 0;
1430 virtual int SnapImage() = 0;
1431 virtual bool Busy() = 0;
1432
1438 virtual int StartSequenceAcquisition(double unused) = 0;
1439
1443 virtual int StopSequenceAcquisition() = 0;
1444
1445 virtual unsigned GetNumberOfComponents() const
1446 {
1447 return 1; // Default to monochrome (ie not RGB)
1448 }
1449
1456 virtual unsigned GetNumberOfChannels() const
1457 {
1458 return 1;
1459 }
1460
1468 virtual int GetChannelName(unsigned /* channel */, char* name)
1469 {
1471 return DEVICE_OK;
1472 }
1473
1480 virtual const unsigned char* GetImageBuffer(unsigned /* channelNr */)
1481 {
1482 if (GetNumberOfChannels() == 1)
1483 return GetImageBuffer();
1484 return 0;
1485 }
1486
1487 virtual const unsigned int* GetImageBufferAsRGB32()
1488 {
1489 return 0;
1490 }
1491
1495 virtual void GetTags(char* serializedMetadata)
1496 {
1498 for (const auto& p : addedTags_)
1499 {
1500 md.AddTag(p.first.c_str(), p.second.c_str());
1501 }
1502 CDeviceUtils::CopyLimitedString(serializedMetadata, md.Serialize());
1503 }
1504
1510 virtual int StartSequenceAcquisition(long numImages, double unused,
1511 bool stopOnOverflow) = 0;
1512
1513 virtual int GetExposureSequenceMaxLength(long& /*nrEvents*/) const
1514 {
1516 }
1517
1519 {
1521 }
1522
1524 {
1526 }
1527
1529 {
1531 }
1532
1533 virtual int AddToExposureSequence(double /*exposureTime_ms*/)
1534 {
1536 }
1537
1538 virtual int SendExposureSequence() const
1539 {
1541 }
1542
1543 virtual bool IsCapturing() = 0;
1544
1545 virtual void AddTag(const char* key, const char* deviceLabel, const char* value)
1546 {
1547 std::string k;
1548 if (deviceLabel != std::string("_"))
1549 {
1550 k += deviceLabel;
1551 k += '-';
1552 }
1553 k += key;
1554 addedTags_[k] = value;
1555 }
1556
1557 virtual void RemoveTag(const char* key)
1558 {
1559 addedTags_.erase(key);
1560 }
1561
1562 virtual bool SupportsMultiROI()
1563 {
1564 return false;
1565 }
1566
1567 virtual bool IsMultiROISet()
1568 {
1569 return false;
1570 }
1571
1572 virtual int GetMultiROICount(unsigned& /* count */)
1573 {
1575 }
1576
1577 virtual int SetMultiROI(const unsigned* /* xs */, const unsigned* /* ys */,
1578 const unsigned* /* widths */, const unsigned* /* heights */,
1579 unsigned /* numROIs */)
1580 {
1582 }
1583
1584 virtual int GetMultiROI(unsigned* /* xs */, unsigned* /* ys */,
1585 unsigned* /* widths */, unsigned* /* heights */, unsigned* /* length */)
1586 {
1588 }
1589
1590private:
1591 std::map<std::string, std::string> addedTags_;
1592};
1593
1594
1595
1596
1604template <class U>
1606{
1607public:
1608 CLegacyCameraBase() : busy_(false), stopWhenCBOverflows_(false), thd_(0)
1609 {
1610 thd_ = new BaseSequenceThread(this);
1611 }
1612
1614 {
1615 if (!thd_->IsStopped()) {
1616 thd_->Stop();
1617 thd_->wait();
1618 }
1619 delete thd_;
1620 }
1621
1622
1623 virtual bool Busy() {return busy_;}
1624
1630 virtual int StartSequenceAcquisition(double /*unused*/)
1631 {
1632 return StartSequenceAcquisition(LONG_MAX, 0.0, false);
1633 }
1634
1639 {
1640 if (!thd_->IsStopped()) {
1641 thd_->Stop();
1642 thd_->wait();
1643 }
1644
1645 return DEVICE_OK;
1646 }
1647
1648 // Implementation of a sequence acquisition as a series of snaps
1649 // This was a temporary method used for debugging, which is why its now
1650 // implemented in this legacy class. It's preferable that camera devices
1651 // inherit directly from CCameraBase and not use these default implementations.
1652 virtual int StartSequenceAcquisition(long numImages, double /*unused*/, bool stopOnOverflow)
1653 {
1654 if (IsCapturing())
1656
1657 int ret = this->GetCoreCallback()->PrepareForAcq(this);
1658 if (ret != DEVICE_OK)
1659 return ret;
1660 thd_->Start(numImages);
1661 stopWhenCBOverflows_ = stopOnOverflow;
1662 return DEVICE_OK;
1663 }
1664
1665 virtual bool IsCapturing(){return !thd_->IsStopped();}
1666
1667
1668protected:
1669 // Member functions that can be overridden by derived classes (these
1670 // customize the legacy snap-based sequence acquisition).
1671
1672 // Do actual capturing
1673 // Called from inside the thread
1674 virtual int ThreadRun (void)
1675 {
1676 int ret=DEVICE_ERR;
1677 ret = this->SnapImage();
1678 if (ret != DEVICE_OK)
1679 {
1680 return ret;
1681 }
1682 ret = InsertImage();
1683 if (ret != DEVICE_OK)
1684 {
1685 return ret;
1686 }
1687 return ret;
1688 };
1689
1690 virtual int InsertImage()
1691 {
1692 char label[MM::MaxStrLength];
1693 this->GetLabel(label);
1696 return this->GetCoreCallback()->InsertImage(this, this->GetImageBuffer(), this->GetImageWidth(),
1697 this->GetImageHeight(), this->GetImageBytesPerPixel(),
1698 md.Serialize());
1699 }
1700
1701 virtual double GetIntervalMs() {return 0.0;}
1702 virtual long GetImageCounter() {return thd_->GetImageCounter();}
1703 virtual long GetNumberOfImages() {return thd_->GetNumberOfImages();}
1704
1705 // called from the thread function before exit
1706 virtual void OnThreadExiting()
1707 {
1708 try
1709 {
1711 if (this->GetCoreCallback() != nullptr) {
1712 this->GetCoreCallback()->AcqFinished(this, 0);
1713 }
1714 }
1715 catch(...)
1716 {
1718 }
1719 }
1720
1721 virtual bool isStopOnOverflow() {return stopWhenCBOverflows_;}
1722 virtual void setStopOnOverflow(bool stop) {stopWhenCBOverflows_ = stop;}
1723
1725 // Helper Class
1727 {
1728 bool restart_;
1729 CLegacyCameraBase* pCam_;
1730
1731 public:
1733 :pCam_(pCam)
1734 {
1735 restart_=pCam_->IsCapturing();
1736 }
1737 operator bool()
1738 {
1739 return restart_;
1740 }
1741 };
1743
1744 // Nested class for live streaming
1747 {
1748 friend class CLegacyCameraBase;
1749 enum { default_numImages=1 };
1750 public:
1752 :numImages_(default_numImages)
1753 ,imageCounter_(0)
1754 ,stop_(true)
1755 ,suspend_(false)
1756 ,camera_(pCam)
1757 ,startTime_(0)
1758 ,actualDuration_(0)
1759 ,lastFrameTime_(0)
1760 {};
1761
1763
1764 void Stop() {
1765 MMThreadGuard g(this->stopLock_);
1766 stop_=true;
1767 }
1768
1769 void Start(long numImages)
1770 {
1771 MMThreadGuard g1(this->stopLock_);
1772 MMThreadGuard g2(this->suspendLock_);
1773 numImages_=numImages;
1774 imageCounter_=0;
1775 stop_ = false;
1776 suspend_=false;
1777 activate();
1778 actualDuration_ = MM::MMTime{};
1779 startTime_= camera_->GetCurrentMMTime();
1780 lastFrameTime_ = MM::MMTime{};
1781 }
1783 MMThreadGuard g(this->stopLock_);
1784 return stop_;
1785 }
1786 void Suspend() {
1787 MMThreadGuard g(this->suspendLock_);
1788 suspend_ = true;
1789 }
1791 MMThreadGuard g(this->suspendLock_);
1792 return suspend_;
1793 }
1794 void Resume() {
1795 MMThreadGuard g(this->suspendLock_);
1796 suspend_ = false;
1797 }
1798 void SetLength(long images) {numImages_ = images;}
1799
1800 long GetImageCounter(){return imageCounter_;}
1801 MM::MMTime GetStartTime(){return startTime_;}
1802 MM::MMTime GetActualDuration(){return actualDuration_;}
1803
1804 CLegacyCameraBase* GetCamera() {return camera_;}
1805 long GetNumberOfImages() {return numImages_;}
1806
1807 void UpdateActualDuration() {actualDuration_ = camera_->GetCurrentMMTime() - startTime_;}
1808
1809 private:
1810 virtual int svc()
1811 {
1812 int ret=DEVICE_ERR;
1813 try
1814 {
1815 do
1816 {
1817 ret=camera_->ThreadRun();
1818 } while (DEVICE_OK == ret && !IsStopped() && imageCounter_++ < numImages_-1);
1819 if (IsStopped())
1820 camera_->LogMessage("SeqAcquisition interrupted by the user\n");
1821
1822 }catch(...){
1823 camera_->LogMessage(g_Msg_EXCEPTION_IN_THREAD, false);
1824 }
1825 stop_=true;
1827 camera_->OnThreadExiting();
1828 return ret;
1829 }
1830 private:
1831 long numImages_;
1832 long imageCounter_;
1833 bool stop_;
1834 bool suspend_;
1835 CLegacyCameraBase* camera_;
1836 MM::MMTime startTime_;
1837 MM::MMTime actualDuration_;
1838 MM::MMTime lastFrameTime_;
1839 MMThreadLock stopLock_;
1840 MMThreadLock suspendLock_;
1841 };
1843
1844
1845private:
1846
1847 bool busy_;
1848 bool stopWhenCBOverflows_;
1849
1850 BaseSequenceThread * thd_;
1852};
1853
1854
1858template <class U>
1859class CStageBase : public CDeviceBase<MM::Stage, U>
1860{
1861 virtual int GetPositionUm(double& pos) = 0;
1862 virtual int SetPositionUm(double pos) = 0;
1863
1869 virtual int SetRelativePositionUm(double d)
1870 {
1871 double pos;
1872 int ret = GetPositionUm(pos);
1873 if (ret != DEVICE_OK)
1874 return ret;
1875 return SetPositionUm(pos + d);
1876 }
1877
1878 virtual int SetAdapterOriginUm(double /*d*/)
1879 {
1881 }
1882
1883 virtual int Move(double /*velocity*/)
1884 {
1886 }
1887
1888 virtual int Stop()
1889 {
1890 // Historically, Move() has been in this interface longer than Stop(), so
1891 // there is a chance that a stage implements Move() but not Stop(). In
1892 // which case zero velocity is the best thing to do.
1893 return Move(0.0);
1894 }
1895
1896 virtual int Home()
1897 {
1899 }
1900
1901 virtual int GetFocusDirection(MM::FocusDirection& direction)
1902 {
1903 // FocusDirectionUnknown is a safe default for all stages. Override this
1904 // only if direction is known for sure (i.e. does not depend on how the
1905 // hardware is installed).
1906 direction = MM::FocusDirectionUnknown;
1907 return DEVICE_OK;
1908 }
1909
1913 virtual int UsesOnStagePositionChanged(bool& result) const
1914 {
1915 result = false;
1916 return DEVICE_OK;
1917 }
1918
1919 virtual int IsStageLinearSequenceable(bool& isSequenceable) const
1920 {
1921 isSequenceable = false;
1922 return DEVICE_OK;
1923 }
1924
1925 virtual int GetStageSequenceMaxLength(long& /*nrEvents*/) const
1926 {
1928 }
1929
1930 virtual int StartStageSequence()
1931 {
1933 }
1934
1935 virtual int StopStageSequence()
1936 {
1938 }
1939
1940 virtual int ClearStageSequence()
1941 {
1943 }
1944
1945 virtual int AddToStageSequence(double /*position*/)
1946 {
1948 }
1949
1950 virtual int SendStageSequence()
1951 {
1953 }
1954
1955 virtual int SetStageLinearSequence(double, long)
1956 {
1958 }
1959};
1960
1967template <class U>
1968class CXYStageBase : public CDeviceBase<MM::XYStage, U>
1969{
1970public:
1971 CXYStageBase() : originXSteps_(0), originYSteps_(0), xPos_(0), yPos_(0)
1972 {
1973 // set-up directionality properties
1977
1981 }
1982
1983 // This converts an absolute position (x_um, y_um), under the current
1984 // adapter origin and x/y mirroring, to an absolute step position. Do not
1985 // use for relative offsets.
1986 std::pair<long, long> ConvertPositionUmToSteps(double x_um, double y_um)
1987 {
1988 bool mirrorX, mirrorY;
1989 GetOrientation(mirrorX, mirrorY);
1990
1991 long xSteps{}, ySteps{};
1992 if (mirrorX)
1993 xSteps = originXSteps_ - nint (x_um / this->GetStepSizeXUm());
1994 else
1995 xSteps = originXSteps_ + nint (x_um / this->GetStepSizeXUm());
1996 if (mirrorY)
1997 ySteps = originYSteps_ - nint (y_um / this->GetStepSizeYUm());
1998 else
1999 ySteps = originYSteps_ + nint (y_um / this->GetStepSizeYUm());
2000
2001 return {xSteps, ySteps};
2002 }
2003
2004 // This converts an absolute position (xSteps, ySteps), under the current
2005 // adapter origin and x/y mirroring, to an absolute um position. Do not use
2006 // for relative offsets.
2007 std::pair<double, double> ConvertPositionStepsToUm(long xSteps, long ySteps)
2008 {
2009 bool mirrorX, mirrorY;
2010 GetOrientation(mirrorX, mirrorY);
2011
2012 double x_um{}, y_um{};
2013 if (mirrorX)
2014 x_um = (originXSteps_ - xSteps) * this->GetStepSizeXUm();
2015 else
2016 x_um = - ((originXSteps_ - xSteps) * this->GetStepSizeXUm());
2017
2018 if (mirrorY)
2019 y_um = (originYSteps_ - ySteps) * this->GetStepSizeYUm();
2020 else
2021 y_um = - ((originYSteps_ - ySteps) * this->GetStepSizeYUm());
2022
2023 return {x_um, y_um};
2024 }
2025
2026 virtual int SetPositionUm(double x_um, double y_um)
2027 {
2028 auto posSteps = ConvertPositionUmToSteps(x_um, y_um);
2029 long xSteps = posSteps.first;
2030 long ySteps = posSteps.second;
2031
2032 int ret = this->SetPositionSteps(xSteps, ySteps);
2033 if (ret == DEVICE_OK) {
2034 xPos_ = x_um;
2035 yPos_ = y_um;
2036 }
2037 return ret;
2038 }
2039
2045 virtual int SetRelativePositionUm(double dx, double dy)
2046 {
2047 bool mirrorX, mirrorY;
2048 GetOrientation(mirrorX, mirrorY);
2049 double xPos = xPos_ + dx;
2050 double yPos = yPos_ + dy;
2051
2052 if (mirrorX)
2053 dx = -dx;
2054 if (mirrorY)
2055 dy = -dy;
2056
2057 int ret = SetRelativePositionSteps(nint(dx / this->GetStepSizeXUm()), nint(dy / this->GetStepSizeYUm()));
2058 if (ret == DEVICE_OK) {
2059 xPos_ = xPos;
2060 yPos_ = yPos;
2061 }
2062 return ret;
2063 }
2064
2072 virtual int SetAdapterOriginUm(double newXUm, double newYUm)
2073 {
2074 bool mirrorX, mirrorY;
2075 GetOrientation(mirrorX, mirrorY);
2076
2077 long xStep, yStep;
2078 int ret = this->GetPositionSteps(xStep, yStep);
2079 if (ret != DEVICE_OK)
2080 return ret;
2081
2082 if (mirrorX)
2083 originXSteps_ = xStep + nint(newXUm / this->GetStepSizeXUm());
2084 else
2085 originXSteps_ = xStep - nint(newXUm / this->GetStepSizeXUm());
2086 if (mirrorY)
2087 originYSteps_ = yStep + nint(newYUm / this->GetStepSizeYUm());
2088 else
2089 originYSteps_ = yStep - nint(newYUm / this->GetStepSizeYUm());
2090
2091 return DEVICE_OK;
2092 }
2093
2094 virtual int GetPositionUm(double& x_um, double& y_um)
2095 {
2096 long xSteps, ySteps;
2097 int ret = this->GetPositionSteps(xSteps, ySteps);
2098 if (ret != DEVICE_OK)
2099 return ret;
2100
2101 auto pos_um = ConvertPositionStepsToUm(xSteps, ySteps);
2102 x_um = pos_um.first;
2103 y_um = pos_um.second;
2104
2105 xPos_ = x_um;
2106 yPos_ = y_um;
2107
2108 return DEVICE_OK;
2109 }
2110
2117 virtual int SetRelativePositionSteps(long x, long y)
2118 {
2119 long xSteps, ySteps;
2120 int ret = this->GetPositionSteps(xSteps, ySteps);
2121 if (ret != DEVICE_OK)
2122 return ret;
2123
2124 return this->SetPositionSteps(xSteps+x, ySteps+y);
2125 }
2126
2130 virtual int UsesOnXYStagePositionChanged(bool& result) const
2131 {
2132 result = false;
2133 return DEVICE_OK;
2134 }
2135
2136 virtual int Move(double /*vx*/, double /*vy*/)
2137 {
2139 }
2140
2141 virtual int SetXOrigin()
2142 {
2144 }
2145
2146 virtual int SetYOrigin()
2147 {
2149 }
2150
2151 virtual int GetXYStageSequenceMaxLength(long& /*nrEvents*/) const
2152 {
2154 }
2155
2157 {
2159 }
2160
2162 {
2164 }
2165
2167 {
2169 }
2170
2171 virtual int AddToXYStageSequence(double /*positionX*/, double /*positionY*/)
2172 {
2174 }
2175
2177 {
2179 }
2180
2181protected:
2182
2194 double GetCachedXUm() {return xPos_;}
2195 double GetCachedYUm() {return yPos_;}
2196
2197private:
2198
2199 void GetOrientation(bool& mirrorX, bool& mirrorY)
2200 {
2201 char val[MM::MaxStrLength];
2202 int ret = this->GetProperty(MM::g_Keyword_Transpose_MirrorX, val);
2203 assert(ret == DEVICE_OK);
2204 mirrorX = strcmp(val, "1") == 0 ? true : false;
2205
2207 assert(ret == DEVICE_OK);
2208 mirrorY = strcmp(val, "1") == 0 ? true : false;
2209 }
2210
2211
2212 // absolute coordinate translation data
2213 long originXSteps_;
2214 long originYSteps_;
2215 double xPos_;
2216 double yPos_;
2217};
2218
2222template <class U>
2223class CShutterBase : public CDeviceBase<MM::Shutter, U>
2224{
2225};
2226
2230template <class U>
2231class CSerialBase : public CDeviceBase<MM::Serial, U>
2232{
2233};
2234
2238template <class U>
2239class CAutoFocusBase : public CDeviceBase<MM::AutoFocus, U>
2240{
2241 virtual int AutoSetParameters() {return DEVICE_UNSUPPORTED_COMMAND;}
2242};
2243
2247template <class U>
2248class CImageProcessorBase : public CDeviceBase<MM::ImageProcessor, U>
2249{
2250};
2251
2255template <class U>
2256class CSignalIOBase : public CDeviceBase<MM::SignalIO, U>
2257{
2258 virtual int GetDASequenceMaxLength(long& /*nrEvents*/) const
2259 {
2261 }
2262
2263 virtual int StartDASequence()
2264 {
2266 }
2267
2268 virtual int StopDASequence() {
2270 }
2271
2272 virtual int ClearDASequence() {
2274 }
2275
2276 virtual int AddToDASequence(double /*voltage*/)
2277 {
2279 }
2280
2281 virtual int SendDASequence() {
2283 }
2284};
2285
2289template <class U>
2290class CMagnifierBase : public CDeviceBase<MM::Magnifier, U>
2291{
2292};
2293
2297template <class U>
2298class CSLMBase : public CDeviceBase<MM::SLM, U>
2299{
2300 virtual int GetSLMSequenceMaxLength(long& /*nrEvents*/) const
2301 {
2303 }
2304
2305 virtual int StartSLMSequence()
2306 {
2308 }
2309
2310 virtual int StopSLMSequence() {
2312 }
2313
2314 virtual int ClearSLMSequence() {
2316 }
2317
2318 virtual int AddToSLMSequence(const unsigned char * const /*image*/)
2319 {
2321 }
2322
2323 virtual int AddToSLMSequence(const unsigned int * const /*image*/)
2324 {
2326 }
2327
2328 virtual int SendSLMSequence() {
2330 }
2331};
2332
2336template <class U>
2337class CGalvoBase : public CDeviceBase<MM::Galvo, U>
2338{
2339 double GetXMinimum() { return 0.0;};
2340 double GetYMinimum() { return 0.0;};
2341};
2342
2347template <class U>
2348class HubBase : public CDeviceBase<MM::Hub, U>
2349{
2350public:
2352 virtual ~HubBase() {}
2353
2362 virtual int DetectInstalledDevices() {return DEVICE_OK;}
2363
2370 virtual unsigned GetNumberOfInstalledDevices() {return (unsigned)installedDevices.size();}
2371
2378 virtual MM::Device* GetInstalledDevice(int devIdx) {return installedDevices[devIdx];}
2379
2387 {
2388 for (unsigned i=0; i<installedDevices.size(); i++)
2389 delete installedDevices[i];
2390 installedDevices.clear();
2391 }
2392
2393protected:
2394 void AddInstalledDevice(MM::Device* pdev) {installedDevices.push_back(pdev);}
2395
2396private:
2397 std::vector<MM::Device*> installedDevices;
2398
2399};
2400
2405template <class U>
2406class CStateDeviceBase : public CDeviceBase<MM::State, U>
2407{
2408public:
2409
2411
2412 CStateDeviceBase(): gateOpen_(true)
2413 {
2414 // set-up Position to move to when the state device's gate is closed
2415 // Allowed values should be set in the state device adapter
2416 // this->CreateProperty(MM::g_Keyword_Closed_Position, "0", MM::String, false);
2417 }
2418
2424 virtual int SetPosition(long pos)
2425 {
2427 }
2428
2434 virtual int SetPosition(const char* label)
2435 {
2436 std::map<std::string, long>::const_iterator it;
2437 it = labels_.find(label);
2438 if (it == labels_.end())
2439 return DEVICE_UNKNOWN_LABEL;
2440
2441 return SetPosition(it->second);
2442 }
2443
2444
2452 virtual int SetGateOpen(bool open)
2453 {
2454 if (gateOpen_ != open) {
2455 gateOpen_ = open;
2456 long position;
2457 int ret = GetPosition(position);
2458 if (ret != DEVICE_OK)
2459 return ret;
2460 return SetPosition(position);
2461 }
2462 return DEVICE_OK;
2463 }
2464
2465 virtual int GetGateOpen(bool& open)
2466 {
2467 open = gateOpen_;
2468 return DEVICE_OK;
2469 }
2470
2476 virtual int GetPosition(long& pos) const
2477 {
2478 char buf[MM::MaxStrLength];
2479 assert(this->HasProperty(MM::g_Keyword_State));
2480 int ret = this->GetProperty(MM::g_Keyword_State, buf);
2481 if (ret == DEVICE_OK)
2482 {
2483 pos = atol(buf);
2484 return DEVICE_OK;
2485 }
2486 else
2487 return ret;
2488 }
2489
2495 virtual int GetPosition(char* label) const
2496 {
2497 long pos;
2498 int ret = GetPosition(pos);
2499 if (ret == DEVICE_OK)
2500 return GetPositionLabel(pos, label);
2501 else
2502 return ret;
2503 }
2504
2508 virtual int GetPositionLabel(long pos, char* label) const
2509 {
2510 std::map<std::string, long>::const_iterator it;
2511 for (it=labels_.begin(); it!=labels_.end(); it++)
2512 {
2513 //string devLabel = it->first;
2514 //long devPosition = it->second;
2515 if (it->second == pos)
2516 {
2517 CDeviceUtils::CopyLimitedString(label, it->first.c_str());
2518 return DEVICE_OK;
2519 }
2520 }
2521
2522 // label not found
2524 }
2525
2530 virtual int SetPositionLabel(long pos, const char* label)
2531 {
2532 // first test if the label already exists with different position defined
2533 std::map<std::string, long>::iterator it;
2534 it = labels_.find(label);
2535 if (it != labels_.end() && it->second != pos)
2536 {
2537 // remove the existing one
2538 labels_.erase(it);
2539 }
2540
2541 // then test if the given position already has a label
2542 for (it=labels_.begin(); it!=labels_.end(); it++)
2543 {
2544 if (it->second == pos)
2545 {
2546 labels_.erase(it);
2547 break;
2548 }
2549 }
2550
2551 // finally we can add the new label-position mapping
2552 labels_[label] = pos;
2553
2554 // attempt to define allowed values for label property (if it exists),
2555 // and don't make any fuss if the operation fails
2556 std::string strLabel(label);
2557 std::vector<std::string> values;
2558 for (it=labels_.begin(); it!=labels_.end(); it++)
2559 values.push_back(it->first);
2561
2562 return DEVICE_OK;
2563 }
2564
2568 virtual int GetLabelPosition(const char* label, long& pos) const
2569 {
2570 std::map<std::string, long>::const_iterator it;
2571 it = labels_.find(label);
2572 if (it == labels_.end())
2573 return DEVICE_UNKNOWN_LABEL;
2574
2575 pos = it->second;
2576 return DEVICE_OK;
2577 }
2578
2583 {
2584 if (eAct == MM::BeforeGet)
2585 {
2586 char buf[MM::MaxStrLength];
2587 int ret = GetPosition(buf);
2588 if (ret != DEVICE_OK)
2589 return ret;
2590 pProp->Set(buf);
2591 }
2592 else if (eAct == MM::AfterSet)
2593 {
2594 std::string label;
2595 pProp->Get(label);
2596 int ret = SetPosition(label.c_str());
2597 if (ret != DEVICE_OK)
2598 return ret;
2599 }
2600 else if (eAct == MM::IsSequenceable)
2601 {
2602 assert(this->HasProperty(MM::g_Keyword_State));
2603 bool sequenceable;
2604 int ret = this->IsPropertySequenceable(MM::g_Keyword_State, sequenceable);
2605 if (ret != DEVICE_OK)
2606 return ret;
2607
2608 long nrEvents = 0;
2609 if (sequenceable) {
2611 if (ret != DEVICE_OK)
2612 return ret;
2613 }
2614 pProp->SetSequenceable(nrEvents);
2615 }
2616 else if (eAct == MM::AfterLoadSequence) {
2617 assert(this->HasProperty(MM::g_Keyword_State));
2618 std::vector<std::string> sequence = pProp->GetSequence();
2619 for (std::vector<std::string>::iterator it = sequence.begin(); it != sequence.end(); ++it) {
2620 long pos;
2621 int ret = GetLabelPosition((*it).c_str(), pos);
2622 if (ret != DEVICE_OK)
2623 return ret;
2624 std::stringstream s;
2625 s << pos;
2626 s >> *it;
2627 }
2628
2630 if (ret != DEVICE_OK)
2631 return ret;
2632
2633 std::vector<std::string>::iterator it;
2634 for ( it=sequence.begin() ; it < sequence.end(); it++ )
2635 {
2636 ret = this->AddToPropertySequence(MM::g_Keyword_State, (*it).c_str());
2637 if (ret != DEVICE_OK)
2638 return ret;
2639 }
2640
2642 if (ret != DEVICE_OK)
2643 return ret;
2644
2645 //this->LoadPropertySequence(MM::g_Keyword_State, sequence);
2646 }
2647 else if (eAct == MM::StartSequence) {
2648 assert(this->HasProperty(MM::g_Keyword_State));
2650 }
2651 else if (eAct == MM::StopSequence) {
2652 assert(this->HasProperty(MM::g_Keyword_State));
2654 }
2655
2656 return DEVICE_OK;
2657 }
2658
2663 int OnStateChanged(long position) {
2664 int ret;
2666 if (ret != DEVICE_OK) {
2667 return ret;
2668 }
2669
2670 char label[MM::MaxStrLength];
2671 GetPositionLabel(position, label);
2672 ret = this->OnPropertyChanged(MM::g_Keyword_Label, label);
2673 return ret;
2674 }
2675
2676private:
2677 bool gateOpen_;
2678
2679private:
2680 std::map<std::string, long> labels_;
2681};
2682
2686template <class U>
2687class CVolumetricPumpBase : public CDeviceBase<MM::VolumetricPump, U>
2688{
2689 int Home()
2690 {
2692 }
2693
2694 int InvertDirection(bool /*state*/)
2695 {
2697 }
2698};
2699
2703template <class U>
2704class CPressurePumpBase : public CDeviceBase<MM::PressurePump, U>
2705{
2706 int Calibrate()
2707 {
2709 }
2710};
const char *const g_Msg_DUPLICATE_PROPERTY
Definition DeviceBase.h:49
const char *const g_Msg_INTERNAL_INCONSISTENCY
Definition DeviceBase.h:53
const char *const g_Msg_DEVICE_NOT_YET_IMPLEMENTED
Definition DeviceBase.h:81
const char *const g_Msg_DEVICE_CAN_NOT_SET_PROPERTY
Definition DeviceBase.h:75
const char *const g_Msg_DEVICE_CAMERA_BUSY_ACQUIRING
Definition DeviceBase.h:74
const char *const g_Msg_EXCEPTION_IN_THREAD
Definition DeviceBase.h:71
const char *const g_Msg_DEVICE_COMM_HUB_MISSING
Definition DeviceBase.h:77
const char *const g_Msg_NO_PROPERTY_DATA
Definition DeviceBase.h:63
const char *const g_Msg_SERIAL_TIMEOUT
Definition DeviceBase.h:61
const char *const g_Msg_EXCEPTION_IN_ON_THREAD_EXITING
Definition DeviceBase.h:72
const char *const g_Msg_UNKNOWN_LABEL
Definition DeviceBase.h:55
const char *const g_Msg_INVALID_PROPERTY
Definition DeviceBase.h:47
const char *const g_Msg_BUFFER_OVERFLOW
Definition DeviceBase.h:66
const char *const g_Msg_SERIAL_INVALID_RESPONSE
Definition DeviceBase.h:60
const char *const g_Msg_DEVICE_PROPERTY_NOT_SEQUENCEABLE
Definition DeviceBase.h:79
const char *const g_Msg_DEVICE_NONEXISTENT_CHANNEL
Definition DeviceBase.h:68
const char *const g_Msg_SERIAL_BUFFER_OVERRUN
Definition DeviceBase.h:59
long nint(double value)
Definition DeviceBase.h:83
const char *const g_Msg_DEVICE_NOT_CONNECTED
Definition DeviceBase.h:76
const char *const g_Msg_DEVICE_SEQUENCE_TOO_LARGE
Definition DeviceBase.h:80
const char *const g_Msg_INVALID_INPUT_PARAM
Definition DeviceBase.h:65
const char *const g_Msg_UNSUPPORTED_COMMAND
Definition DeviceBase.h:56
const char *const g_Msg_SELF_REFERENCE
Definition DeviceBase.h:62
const char *const g_Msg_SEQUENCE_ACQUISITION_THREAD_EXITING
Definition DeviceBase.h:73
const char *const g_Msg_DEVICE_DUPLICATE_LIBRARY
Definition DeviceBase.h:78
const char *const g_Msg_UNSUPPORTED_DATA_FORMAT
Definition DeviceBase.h:52
const char *const g_Msg_SERIAL_COMMAND_FAILED
Definition DeviceBase.h:67
const char *const g_Msg_NOT_SUPPORTED
Definition DeviceBase.h:54
const char *const g_Msg_UNKNOWN_POSITION
Definition DeviceBase.h:57
const char *const g_Msg_DEVICE_INVALID_PROPERTY_LIMTS
Definition DeviceBase.h:69
const char *const g_Msg_INVALID_PROPERTY_VALUE
Definition DeviceBase.h:48
const char *const g_Msg_INVALID_PROPERTY_TYPE
Definition DeviceBase.h:50
const char *const g_Msg_NO_CALLBACK_REGISTERED
Definition DeviceBase.h:58
const char *const g_Msg_DEVICE_DUPLICATE_LABEL
Definition DeviceBase.h:64
const char *const g_Msg_ERR
Definition DeviceBase.h:46
const char *const g_Msg_NATIVE_MODULE_FAILED
Definition DeviceBase.h:51
#define DEVICE_NO_CALLBACK_REGISTERED
Definition MMDeviceConstants.h:60
#define DEVICE_SEQUENCE_TOO_LARGE
Definition MMDeviceConstants.h:86
#define DEVICE_NOT_SUPPORTED
Definition MMDeviceConstants.h:56
#define DEVICE_DUPLICATE_PROPERTY
Definition MMDeviceConstants.h:51
#define DEVICE_SERIAL_INVALID_RESPONSE
Definition MMDeviceConstants.h:63
#define DEVICE_UNKNOWN_LABEL
Definition MMDeviceConstants.h:57
#define DEVICE_PROPERTY_NOT_SEQUENCEABLE
Definition MMDeviceConstants.h:85
#define DEVICE_NO_PROPERTY_DATA
Definition MMDeviceConstants.h:66
#define DEVICE_BUFFER_OVERFLOW
Definition MMDeviceConstants.h:69
#define DEVICE_UNSUPPORTED_DATA_FORMAT
Definition MMDeviceConstants.h:54
#define DEVICE_NONEXISTENT_CHANNEL
Definition MMDeviceConstants.h:70
#define DEVICE_CAMERA_BUSY_ACQUIRING
Definition MMDeviceConstants.h:77
#define DEVICE_UNSUPPORTED_COMMAND
Definition MMDeviceConstants.h:58
#define DEVICE_ERR
Definition MMDeviceConstants.h:48
#define DEVICE_SERIAL_TIMEOUT
Definition MMDeviceConstants.h:64
#define DEVICE_NATIVE_MODULE_FAILED
Definition MMDeviceConstants.h:53
#define DEVICE_OK
Definition MMDeviceConstants.h:47
#define DEVICE_INVALID_PROPERTY_TYPE
Definition MMDeviceConstants.h:52
#define DEVICE_SELF_REFERENCE
Definition MMDeviceConstants.h:65
#define DEVICE_DUPLICATE_LABEL
Definition MMDeviceConstants.h:67
#define DEVICE_SERIAL_BUFFER_OVERRUN
Definition MMDeviceConstants.h:62
#define DEVICE_INTERNAL_INCONSISTENCY
Definition MMDeviceConstants.h:55
#define DEVICE_UNKNOWN_POSITION
Definition MMDeviceConstants.h:59
#define DEVICE_SERIAL_COMMAND_FAILED
Definition MMDeviceConstants.h:61
#define DEVICE_DUPLICATE_LIBRARY
Definition MMDeviceConstants.h:84
#define DEVICE_CAN_NOT_SET_PROPERTY
Definition MMDeviceConstants.h:79
#define DEVICE_INVALID_PROPERTY_VALUE
Definition MMDeviceConstants.h:50
#define DEVICE_INVALID_PROPERTY
Definition MMDeviceConstants.h:49
#define DEVICE_COMM_HUB_MISSING
Definition MMDeviceConstants.h:83
#define DEVICE_INVALID_PROPERTY_LIMTS
Definition MMDeviceConstants.h:71
#define DEVICE_NOT_CONNECTED
Definition MMDeviceConstants.h:82
#define DEVICE_LOCALLY_DEFINED_ERROR
Definition MMDeviceConstants.h:81
#define DEVICE_NOT_YET_IMPLEMENTED
Definition MMDeviceConstants.h:88
#define DEVICE_INVALID_INPUT_PARAM
Definition MMDeviceConstants.h:68
Base class for creating auto-focusing modules.
Definition DeviceBase.h:2240
Base class for creating camera device adapters.
Definition DeviceBase.h:1398
virtual int StartSequenceAcquisition(double unused)=0
Start continuous sequence acquisition.
virtual int GetMultiROI(unsigned *, unsigned *, unsigned *, unsigned *, unsigned *)
Definition DeviceBase.h:1584
virtual int StopExposureSequence()
Definition DeviceBase.h:1523
virtual int StartSequenceAcquisition(long numImages, double unused, bool stopOnOverflow)=0
Start sequence acquisition.
virtual int SetMultiROI(const unsigned *, const unsigned *, const unsigned *, const unsigned *, unsigned)
Definition DeviceBase.h:1577
virtual bool SupportsMultiROI()
Definition DeviceBase.h:1562
virtual unsigned GetImageBytesPerPixel() const =0
Return image buffer pixel depth in bytes.
virtual int GetExposureSequenceMaxLength(long &) const
Definition DeviceBase.h:1513
virtual int StartExposureSequence()
Definition DeviceBase.h:1518
virtual int GetMultiROICount(unsigned &)
Definition DeviceBase.h:1572
CCameraBase()
Definition DeviceBase.h:1409
virtual unsigned GetImageHeight() const =0
Return image buffer Y-size in pixels.
virtual int StopSequenceAcquisition()=0
Stop and wait for the thread to finish.
virtual void RemoveTag(const char *key)
Remove an existing tag from the metadata associated with this device.
Definition DeviceBase.h:1557
virtual int AddToExposureSequence(double)
Definition DeviceBase.h:1533
virtual int ClearExposureSequence()
Definition DeviceBase.h:1528
virtual unsigned GetNumberOfChannels() const
Return the number of channels.
Definition DeviceBase.h:1456
virtual bool Busy()=0
virtual int SendExposureSequence() const
Definition DeviceBase.h:1538
virtual const unsigned char * GetImageBuffer()=0
Return pixel data.
virtual bool IsMultiROISet()
Definition DeviceBase.h:1567
virtual unsigned GetNumberOfComponents() const
Return the number of components in this image.
Definition DeviceBase.h:1445
virtual int SnapImage()=0
Perform exposure and grab a single image.
virtual unsigned GetImageWidth() const =0
Return image buffer X-size in pixels.
virtual void AddTag(const char *key, const char *deviceLabel, const char *value)
Add new tag or modify the value of an existing one.
Definition DeviceBase.h:1545
virtual const unsigned char * GetImageBuffer(unsigned)
Return the image buffer for a specific channel.
Definition DeviceBase.h:1480
virtual bool IsCapturing()=0
Indicate whether sequence acquisition is currently running.
virtual const unsigned int * GetImageBufferAsRGB32()
Return pixel data with interleaved RGB pixels in 32 bpp format.
Definition DeviceBase.h:1487
virtual void GetTags(char *serializedMetadata)
Fill serializedMetadata with the device's metadata tags.
Definition DeviceBase.h:1495
virtual int GetChannelName(unsigned, char *name)
Return the channel name.
Definition DeviceBase.h:1468
Implement functionality common to all devices.
Definition DeviceBase.h:97
MM::Action< U > CPropertyAction
Definition DeviceBase.h:100
virtual bool GetErrorText(int errorCode, char *text) const
Obtain the error text associated with the error code.
Definition DeviceBase.h:808
virtual bool GetPropertyName(unsigned uIdx, char *name) const
Obtain the property name given the index.
Definition DeviceBase.h:516
const char * GetMorePropertyErrorInfo(void) const
Definition DeviceBase.h:884
int CreateStringProperty(const char *name, const char *value, bool readOnly, MM::ActionFunctor *pAct=0, bool isPreInitProperty=false)
Create a string-valued property for the device.
Definition DeviceBase.h:674
void InitializeDefaultErrorMessages()
Set up the standard set of error codes and error messages.
Definition DeviceBase.h:980
int LogMessageCode(const int errorCode, bool debugOnly=false) const
Output the text message of specified code to the log stream.
Definition DeviceBase.h:929
bool IsPropertyEqualTo(const char *name, const char *val) const
Check if the property value is equal to a specific string.
Definition DeviceBase.h:245
int CreateFloatProperty(const char *name, double value, bool readOnly, MM::ActionFunctor *pAct=0, bool isPreInitProperty=false)
Create a float-valued property for the device.
Definition DeviceBase.h:656
void SetErrorText(int errorCode, const char *text)
Define the error text associated with the code.
Definition DeviceBase.h:879
virtual void SetDelayMs(double delay)
Set the device delay used for synchronization by the calling code.
Definition DeviceBase.h:171
unsigned long GetClockTicksUs()
Get the system ticks in microseconds.
Definition DeviceBase.h:1232
CDeviceBase()
Definition DeviceBase.h:870
int UpdateStatus()
Refresh the entire state of the device and synchronize property values with the actual state of the h...
Definition DeviceBase.h:783
int OnPropertiesChanged()
Signal that something changed in the property structure.
Definition DeviceBase.h:1144
int SetPropertyLimits(const char *name, double low, double high)
Define limits for properties with a continuous range of values.
Definition DeviceBase.h:682
int CreateIntegerProperty(const char *name, long value, bool readOnly, MM::ActionFunctor *pAct=0, bool isPreInitProperty=false)
Create an integer-valued property for the device.
Definition DeviceBase.h:644
MM::Hub * GetParentHub() const
Return the parent Hub device pointer, or null if there isn't any.
Definition DeviceBase.h:1300
virtual void GetParentID(char *parentID) const
Definition DeviceBase.h:859
bool IsCallbackRegistered() const
Check if we have callback mechanism set up.
Definition DeviceBase.h:1254
MM::ActionEx< U > CPropertyActionEx
Definition DeviceBase.h:101
int CreateProperty(const char *name, const char *value, MM::PropertyType eType, bool readOnly, MM::ActionFunctor *pAct=0, bool isPreInitProperty=false)
Create a new property for the device.
Definition DeviceBase.h:618
int OnXYStagePositionChanged(double xPos, double yPos)
Report position change (for XY stage).
Definition DeviceBase.h:1190
int GetProperty(const char *name, long &val)
Obtain the value of the property.
Definition DeviceBase.h:228
int OnSLMExposureChanged(double exposure)
Signal that the SLM exposure has changed.
Definition DeviceBase.h:1210
int PurgeComPort(const char *portLabel)
Clear the serial port buffers.
Definition DeviceBase.h:1117
void EnableDelay(bool state=true)
Enable response to delay settings.
Definition DeviceBase.h:1273
virtual int StartPropertySequence(const char *name)
Start a (TTL-triggered) sequence for the given property.
Definition DeviceBase.h:403
int LogTimeDiff(MM::MMTime start, MM::MMTime end, bool debugOnly=false) const
Output time difference between two time stamps.
Definition DeviceBase.h:972
void CreateHubIDProperty()
Create read-only property displaying parentID (hub label).
Definition DeviceBase.h:1286
void GetLoadedDeviceOfType(MM::DeviceType devType, char *deviceName, const unsigned int deviceIterator)
Provide access to the names of devices of a given type.
Definition DeviceBase.h:1043
int ClearAllowedValues(const char *name)
Clear allowed values, and make any value valid.
Definition DeviceBase.h:732
int LogMessage(const char *msg, bool debugOnly=false) const
Output the specified text message to the log stream.
Definition DeviceBase.h:901
int OnPropertyChanged(const char *propName, const char *propValue)
Signal to the core that a property value has changed.
Definition DeviceBase.h:1154
virtual double GetDelayMs() const
Return device delay used for synchronization by the calling code.
Definition DeviceBase.h:163
virtual bool SupportsDeviceDetection(void)
Definition DeviceBase.h:837
virtual int ClearPropertySequence(const char *name)
Clear a property sequence.
Definition DeviceBase.h:460
virtual bool HasProperty(const char *name) const
Check if device supports a given property.
Definition DeviceBase.h:560
int GetSerialAnswer(const char *portName, const char *term, std::string &ans)
Get the received string from the serial port, waiting for the terminating character sequence.
Definition DeviceBase.h:1088
MM::Core * GetCoreCallback() const
Get the callback object.
Definition DeviceBase.h:1262
virtual bool UsesDelay()
Signal if the device responds to different delay settings.
Definition DeviceBase.h:183
int UpdateProperty(const char *name)
Update property value from the hardware.
Definition DeviceBase.h:791
T_HUB * AssignToHub()
Return the parent Hub device pointer, or null if there isn't any.
Definition DeviceBase.h:1314
virtual int AddToPropertySequence(const char *name, const char *value)
Add to a property sequence.
Definition DeviceBase.h:479
MM::PortType GetSerialPortType(const char *portLabel)
TODO-BRIEF.
Definition DeviceBase.h:1129
virtual int GetPropertySequenceMaxLength(const char *name, long &nrEvents) const
Provide the maximum number of events that can be executed by this sequenceable property.
Definition DeviceBase.h:372
virtual int HasPropertyLimits(const char *name, bool &hasLimits) const
Definition DeviceBase.h:295
MM::MMTime GetCurrentMMTime()
Get current time.
Definition DeviceBase.h:1243
virtual int StopPropertySequence(const char *name)
Stop a (TTL-triggered) sequence for the given property.
Definition DeviceBase.h:432
virtual void SetModuleName(const char *name)
Assign a name for the module (for use only by the calling code).
Definition DeviceBase.h:106
virtual unsigned GetNumberOfPropertyValues(const char *propertyName) const
Return the number of allowed property values.
Definition DeviceBase.h:575
virtual int SetProperty(const char *name, const char *value)
Set the property value.
Definition DeviceBase.h:545
virtual int SendPropertySequence(const char *name)
Send the property sequence to the device.
Definition DeviceBase.h:498
virtual void GetLabel(char *name) const
Return the device label (for use only by the calling code).
Definition DeviceBase.h:152
int LogMessage(const std::string &msg, bool debugOnly=false) const
Output the specified text message to the log stream.
Definition DeviceBase.h:915
virtual void GetDescription(char *name) const
Return device description (for use only by the calling code).
Definition DeviceBase.h:130
int WriteToComPort(const char *portLabel, const unsigned char *buf, unsigned bufLength)
Send an array of bytes to the COM port.
Definition DeviceBase.h:1056
virtual void SetLabel(const char *label)
Set the device label (for use only by the calling code).
Definition DeviceBase.h:141
virtual bool GetPropertyValueAt(const char *propertyName, unsigned index, char *value) const
Return the allowed value of the property, given its index.
Definition DeviceBase.h:593
virtual void GetModuleName(char *name) const
Return the module name (for use only by the calling code).
Definition DeviceBase.h:114
int SendSerialCommand(const char *portName, const char *command, const char *term)
Send an ASCII string with the specified terminating characters to the serial port.
Definition DeviceBase.h:1072
virtual void SetParentID(const char *parentId)
Definition DeviceBase.h:845
int GetPropertyData(const char *name, const char *value, long &data)
Obtain data field associated with the allowed property value.
Definition DeviceBase.h:756
int GetCurrentPropertyData(const char *name, long &data)
Obtain data field associated with the currently applied property value.
Definition DeviceBase.h:769
int OnMagnifierChanged()
Signal that the magnifier has changed.
Definition DeviceBase.h:1220
int OnStagePositionChanged(double pos)
Report position change (for single-axis stage).
Definition DeviceBase.h:1172
virtual unsigned GetNumberOfProperties() const
Return the number of properties.
Definition DeviceBase.h:188
virtual int GetProperty(const char *name, char *value) const
Obtain the value of the property.
Definition DeviceBase.h:196
int ApplyProperty(const char *name)
Apply the current property value to the hardware.
Definition DeviceBase.h:800
virtual MM::DeviceDetectionStatus DetectDevice(void)
Definition DeviceBase.h:840
virtual int GetPropertyType(const char *name, MM::PropertyType &pt) const
Obtain property type (string, float, or integer).
Definition DeviceBase.h:529
int ReadFromComPort(const char *portLabel, unsigned char *buf, unsigned bufLength, unsigned long &read)
Read the current contents of Rx serial buffer.
Definition DeviceBase.h:1107
int OnExposureChanged(double exposure)
Signal that the exposure has changed.
Definition DeviceBase.h:1200
virtual int GetPropertyInitStatus(const char *name, bool &preInit) const
Check whether the property is pre-init.
Definition DeviceBase.h:281
int LogTimeDiff(MM::MMTime start, MM::MMTime end, const std::string &message, bool debugOnly=false) const
Output time difference between two time stamps.
Definition DeviceBase.h:952
void SetMorePropertyErrorInfo(const char *ptext) const
Definition DeviceBase.h:889
virtual void SetDescription(const char *descr)
Assign description string for a device (for use only by the calling code).
Definition DeviceBase.h:122
virtual int GetPropertyLowerLimit(const char *name, double &lowLimit) const
Provide lower limit for a property that has property limits.
Definition DeviceBase.h:314
int ClearPropertyLimits(const char *name)
Remove the limits of a property, so that any value is allowed again.
Definition DeviceBase.h:709
virtual int GetPropertyUpperLimit(const char *name, double &hiLimit) const
Provide upper limit for a property that has property limits.
Definition DeviceBase.h:333
virtual int GetPropertyReadOnly(const char *name, bool &readOnly) const
Check whether the property is read-only.
Definition DeviceBase.h:261
int GetProperty(const char *name, double &val)
Obtain the value of the property.
Definition DeviceBase.h:213
MM::Device * GetDevice(const char *deviceLabel) const
Get the handle (pointer) to the specified device label.
Definition DeviceBase.h:1024
int AddAllowedValue(const char *name, const char *value)
Add a single allowed value.
Definition DeviceBase.h:740
int SetAllowedValues(const char *name, std::vector< std::string > &values)
Set an entire array of allowed values.
Definition DeviceBase.h:724
int AddAllowedValue(const char *name, const char *value, long data)
Add a single allowed value, plus additional data.
Definition DeviceBase.h:748
int CreatePropertyWithHandler(const char *name, const char *value, MM::PropertyType eType, bool readOnly, int(U::*memberFunction)(MM::PropertyBase *pProp, MM::ActionType eAct), bool isPreInitProperty=false)
Create a new property for the device.
Definition DeviceBase.h:635
virtual ~CDeviceBase()
Definition DeviceBase.h:874
virtual int IsPropertySequenceable(const char *name, bool &sequenceable) const
Check whether the property can be run in a sequence.
Definition DeviceBase.h:352
virtual void SetCallback(MM::Core *cbk)
Set the callback for accessing parent functionality (used only by the calling code).
Definition DeviceBase.h:176
static const char * ConvertToString(long lnVal)
Definition DeviceUtils.cpp:65
static bool CopyLimitedString(char *pszTarget, const char *pszSource)
Definition DeviceUtils.cpp:45
Base class for creating Galvo devices.
Definition DeviceBase.h:2338
Base class for creating generic devices.
Definition DeviceBase.h:1386
Base class for creating image processing modules.
Definition DeviceBase.h:2249
Definition DeviceBase.h:1747
MM::MMTime GetStartTime()
Definition DeviceBase.h:1801
void Suspend()
Definition DeviceBase.h:1786
void Resume()
Definition DeviceBase.h:1794
long GetNumberOfImages()
Definition DeviceBase.h:1805
void Stop()
Definition DeviceBase.h:1764
void SetLength(long images)
Definition DeviceBase.h:1798
bool IsSuspended()
Definition DeviceBase.h:1790
~BaseSequenceThread()
Definition DeviceBase.h:1762
void UpdateActualDuration()
Definition DeviceBase.h:1807
CLegacyCameraBase * GetCamera()
Definition DeviceBase.h:1804
BaseSequenceThread(CLegacyCameraBase *pCam)
Definition DeviceBase.h:1751
bool IsStopped()
Definition DeviceBase.h:1782
long GetImageCounter()
Definition DeviceBase.h:1800
void Start(long numImages)
Definition DeviceBase.h:1769
MM::MMTime GetActualDuration()
Definition DeviceBase.h:1802
Definition DeviceBase.h:1727
CaptureRestartHelper(CLegacyCameraBase *pCam)
Definition DeviceBase.h:1732
Legacy base class for creating camera device adapters.
Definition DeviceBase.h:1606
virtual void setStopOnOverflow(bool stop)
Definition DeviceBase.h:1722
virtual bool isStopOnOverflow()
Definition DeviceBase.h:1721
virtual ~CLegacyCameraBase()
Definition DeviceBase.h:1613
virtual int ThreadRun(void)
Definition DeviceBase.h:1674
virtual double GetIntervalMs()
Definition DeviceBase.h:1701
CLegacyCameraBase()
Definition DeviceBase.h:1608
virtual bool Busy()
Definition DeviceBase.h:1623
virtual void OnThreadExiting()
Definition DeviceBase.h:1706
virtual int InsertImage()
Definition DeviceBase.h:1690
virtual int StartSequenceAcquisition(double)
Start continuous sequence acquisition.
Definition DeviceBase.h:1630
friend class BaseSequenceThread
Definition DeviceBase.h:1851
virtual long GetNumberOfImages()
Definition DeviceBase.h:1703
virtual bool IsCapturing()
Indicate whether sequence acquisition is currently running.
Definition DeviceBase.h:1665
virtual long GetImageCounter()
Definition DeviceBase.h:1702
virtual int StartSequenceAcquisition(long numImages, double, bool stopOnOverflow)
Start sequence acquisition.
Definition DeviceBase.h:1652
virtual int StopSequenceAcquisition()
Stop and wait for the thread to finish.
Definition DeviceBase.h:1638
Base class for creating devices that can change magnification (NS).
Definition DeviceBase.h:2291
Base class for creating pressure pump device adapters.
Definition DeviceBase.h:2705
Base class for creating SLM devices that can project images.
Definition DeviceBase.h:2299
Base class for creating serial port device adapters.
Definition DeviceBase.h:2232
Base class for creating shutter device adapters.
Definition DeviceBase.h:2224
Base class for creating ADC/DAC modules.
Definition DeviceBase.h:2257
Base class for creating single axis stage adapters.
Definition DeviceBase.h:1860
Base class for creating state device adapters such as filter wheels, objectives, turrets,...
Definition DeviceBase.h:2407
virtual int GetPosition(char *label) const
Obtain the state (position) label of the device.
Definition DeviceBase.h:2495
virtual int GetPositionLabel(long pos, char *label) const
Obtain the label associated with the position (state).
Definition DeviceBase.h:2508
virtual int SetPositionLabel(long pos, const char *label)
Create new label for the given position, or override the existing one.
Definition DeviceBase.h:2530
virtual int GetGateOpen(bool &open)
Definition DeviceBase.h:2465
virtual int GetPosition(long &pos) const
Obtain the state (position) index of the device.
Definition DeviceBase.h:2476
int OnLabel(MM::PropertyBase *pProp, MM::ActionType eAct)
Implement the default Label property action.
Definition DeviceBase.h:2582
CStateDeviceBase< U > CStateBase
Definition DeviceBase.h:2410
virtual int SetPosition(const char *label)
Set the state (position) of the device based on the state label.
Definition DeviceBase.h:2434
int OnStateChanged(long position)
Signal to the core that the state has changed, so that both "State" and "Label" properties should be ...
Definition DeviceBase.h:2663
virtual int GetLabelPosition(const char *label, long &pos) const
Obtain the position associated with a label.
Definition DeviceBase.h:2568
virtual int SetPosition(long pos)
Set the state (position) of the device based on the state index.
Definition DeviceBase.h:2424
CStateDeviceBase()
Definition DeviceBase.h:2412
virtual int SetGateOpen(bool open)
Implement a gate, i.e., a position where the state device is closed.
Definition DeviceBase.h:2452
Base class for creating volumetric pump device adapters.
Definition DeviceBase.h:2688
Base class for creating dual axis stage adapters.
Definition DeviceBase.h:1969
virtual int SetAdapterOriginUm(double newXUm, double newYUm)
Alter the software coordinate translation between micrometers and steps, such that the current positi...
Definition DeviceBase.h:2072
virtual int StartXYStageSequence()
Definition DeviceBase.h:2156
virtual int AddToXYStageSequence(double, double)
Add one value to the sequence.
Definition DeviceBase.h:2171
virtual int GetXYStageSequenceMaxLength(long &) const
Definition DeviceBase.h:2151
CXYStageBase()
Definition DeviceBase.h:1971
virtual int SetYOrigin()
Define the current position as Y = 0 (in hardware if possible).
Definition DeviceBase.h:2146
virtual int Move(double, double)
Definition DeviceBase.h:2136
std::pair< double, double > ConvertPositionStepsToUm(long xSteps, long ySteps)
Definition DeviceBase.h:2007
double GetCachedXUm()
Return the cached X position.
Definition DeviceBase.h:2194
virtual int SetPositionUm(double x_um, double y_um)
Definition DeviceBase.h:2026
double GetCachedYUm()
Definition DeviceBase.h:2195
virtual int GetPositionUm(double &x_um, double &y_um)
Definition DeviceBase.h:2094
virtual int SendXYStageSequence()
Signal that we are done sending sequence values so that the adapter can send the whole sequence to th...
Definition DeviceBase.h:2176
virtual int StopXYStageSequence()
Definition DeviceBase.h:2161
virtual int SetRelativePositionSteps(long x, long y)
Set relative position in steps.
Definition DeviceBase.h:2117
std::pair< long, long > ConvertPositionUmToSteps(double x_um, double y_um)
Definition DeviceBase.h:1986
virtual int SetRelativePositionUm(double dx, double dy)
Set relative position.
Definition DeviceBase.h:2045
virtual int ClearXYStageSequence()
Remove all values in the sequence.
Definition DeviceBase.h:2166
virtual int SetXOrigin()
Define the current position as X = 0 (in hardware if possible).
Definition DeviceBase.h:2141
virtual int UsesOnXYStagePositionChanged(bool &result) const
Return true when your device adapter uses OnXYStagePositionChanged callbacks.
Definition DeviceBase.h:2130
Base class for creating special HUB devices for managing device libraries.
Definition DeviceBase.h:2349
void AddInstalledDevice(MM::Device *pdev)
Definition DeviceBase.h:2394
virtual unsigned GetNumberOfInstalledDevices()
Return the number of child devices after DetectInstalledDevices was called.
Definition DeviceBase.h:2370
virtual int DetectInstalledDevices()
Detect installed child devices.
Definition DeviceBase.h:2362
virtual ~HubBase()
Definition DeviceBase.h:2352
HubBase()
Definition DeviceBase.h:2351
virtual void ClearInstalledDevices()
Remove all installed devices that were created by DetectInstalledDevices().
Definition DeviceBase.h:2386
virtual MM::Device * GetInstalledDevice(int devIdx)
Return a pointer to the device with index devIdx.
Definition DeviceBase.h:2378
Extended device action implementation.
Definition Property.h:109
Abstract interface to invoke specific action in the device.
Definition Property.h:76
Device action implementation.
Definition Property.h:87
Camera API.
Definition MMDevice.h:300
Definition CameraImageMetadata.h:29
void AddTag(const char *key, V value)
Add a tag.
Definition CameraImageMetadata.h:57
const char * Serialize() const
Return this metadata map serialized to string form.
Definition CameraImageMetadata.h:102
Callback API to the core control module.
Definition MMDevice.h:1596
virtual int OnPropertiesChanged(const Device *caller)=0
virtual MM::MMTime GetCurrentMMTime()=0
virtual unsigned long GetClockTicksUs(const Device *caller)=0
virtual int GetSerialAnswer(const Device *caller, const char *portName, unsigned long ansLength, char *answer, const char *term)=0
virtual int OnMagnifierChanged(const Device *caller)=0
Signal changes in magnification.
virtual int AcqFinished(const Device *caller, int statusCode)=0
virtual MM::PortType GetSerialPortType(const char *portName) const =0
virtual int SetSerialCommand(const Device *caller, const char *portName, const char *command, const char *term)=0
virtual int PurgeSerial(const Device *caller, const char *portName)=0
virtual int OnStagePositionChanged(const Device *caller, double pos)=0
Inform the UI when a stage has changed its position.
virtual void GetLoadedDeviceOfType(const Device *caller, MM::DeviceType devType, char *pDeviceName, const unsigned int deviceIterator)=0
Get the names of currently loaded devices of a given type.
virtual int OnExposureChanged(const Device *caller, double newExposure)=0
Inform the UI when the exposure time has changed.
virtual int WriteToSerial(const Device *caller, const char *port, const unsigned char *buf, unsigned long length)=0
virtual MM::Hub * GetParentHub(const MM::Device *caller) const =0
virtual int LogMessage(const Device *caller, const char *msg, bool debugOnly) const =0
Log a message (msg) in the Corelog output, labeled with the device name (derived from caller).
virtual int OnXYStagePositionChanged(const Device *caller, double xPos, double yPos)=0
Inform the UI when an XY stage has changed its position.
virtual int ReadFromSerial(const Device *caller, const char *port, unsigned char *buf, unsigned long length, unsigned long &read)=0
virtual Device * GetDevice(const Device *caller, const char *label)=0
Get a pointer to another device.
virtual int OnPropertyChanged(const Device *caller, const char *propName, const char *propValue)=0
Inform the UI that a property changed.
virtual int OnSLMExposureChanged(const Device *caller, double newExposure)=0
Inform the UI when the SLM exposure time has changed.
virtual int InsertImage(const Device *caller, const unsigned char *buf, unsigned width, unsigned height, unsigned bytePerPixel, unsigned nComponents, const char *serializedMetadata=nullptr)=0
Send a frame to the Core during sequence acquisition.
virtual int PrepareForAcq(const Device *caller)=0
Generic device interface.
Definition MMDevice.h:192
HUB device.
Definition MMDevice.h:1327
Utility class used both MMCore and devices to maintain time intervals in the uniform,...
Definition MMDevice.h:58
std::string toString() const
Definition MMDevice.h:144
Base API for all device properties.
Definition Property.h:39
virtual void SetSequenceable(long sequenceSize)=0
virtual std::vector< std::string > GetSequence() const =0
virtual bool Get(double &dVal) const =0
virtual bool Set(double dVal)=0
virtual PropertyType GetType()=0
An array of properties supported by a device.
Definition Property.h:451
bool GetName(unsigned uIdx, std::string &strName) const
Definition Property.cpp:436
int ClearAllowedValues(const char *name)
Definition Property.cpp:379
int UpdateAll()
Definition Property.cpp:459
int GetCurrentPropertyData(const char *name, long &data)
Definition Property.cpp:422
int GetPropertyData(const char *name, const char *value, long &data)
Definition Property.cpp:410
int AddAllowedValue(const char *name, const char *value, long data)
Definition Property.cpp:389
int Set(const char *propName, const char *Value)
Definition Property.cpp:266
int Get(const char *propName, std::string &val) const
Definition Property.cpp:289
int CreateProperty(const char *name, const char *value, PropertyType eType, bool bReadOnly, ActionFunctor *pAct=0, bool isPreInitProperty=false)
Definition Property.cpp:329
int Update(const char *Name)
Definition Property.cpp:485
Property * Find(const char *name) const
Definition Property.cpp:305
int Apply(const char *Name)
Definition Property.cpp:494
int SetAllowedValues(const char *name, std::vector< std::string > &values)
Definition Property.cpp:366
unsigned GetSize() const
Definition Property.cpp:324
Property API with most of the Property mechanism implemented.
Definition Property.h:145
double GetUpperLimit() const
Definition Property.h:215
bool GetReadOnly() const
Definition Property.h:170
bool IsSequenceable()
Definition Property.h:249
long GetSequenceMaxSize() const
Definition Property.h:258
int ClearSequence()
Definition Property.h:263
int StopSequence()
Definition Property.h:318
void ClearLimits()
Definition Property.h:226
bool SetLimits(double lowerLimit, double upperLimit)
Definition Property.h:233
double GetLowerLimit() const
Definition Property.h:210
bool HasLimits() const
Definition Property.h:205
int AddToSequence(const char *value)
Definition Property.h:278
bool GetInitStatus() const
Definition Property.h:173
std::vector< std::string > GetAllowedValues() const
Definition Property.cpp:32
int StartSequence()
Definition Property.h:311
int SendSequence()
Definition Property.h:293
virtual double GetStepSizeXUm()=0
virtual int GetPositionSteps(long &x, long &y)=0
virtual double GetStepSizeYUm()=0
virtual int SetPositionSteps(long x, long y)=0
Base class for threads in MM devices.
Definition DeviceThreads.h:32
void activate()
Definition DeviceThreads.h:60
void wait()
Definition DeviceThreads.h:72
RAII object to acquire and auto-release MMThreadLock.
Definition DeviceThreads.h:124
Critical section lock.
Definition DeviceThreads.h:92
Definition CameraImageMetadata.h:27
FocusDirection
Definition MMDeviceConstants.h:291
@ FocusDirectionUnknown
Definition MMDeviceConstants.h:292
PortType
Definition MMDeviceConstants.h:284
@ InvalidPort
Definition MMDeviceConstants.h:285
const char *const g_Keyword_Metadata_CameraLabel
Definition MMDeviceConstants.h:184
PropertyType
Definition MMDeviceConstants.h:267
@ Float
Definition MMDeviceConstants.h:270
@ String
Definition MMDeviceConstants.h:269
@ Integer
Definition MMDeviceConstants.h:271
const char *const g_Keyword_Transpose_Correction
Definition MMDeviceConstants.h:154
const int MaxStrLength
Definition MMDeviceConstants.h:96
DeviceType
Definition MMDeviceConstants.h:245
const char *const g_Keyword_State
Definition MMDeviceConstants.h:119
const char *const g_Keyword_Label
Definition MMDeviceConstants.h:120
const char *const g_Keyword_HubID
Definition MMDeviceConstants.h:156
ActionType
Definition MMDeviceConstants.h:274
@ IsSequenceable
Definition MMDeviceConstants.h:278
@ AfterSet
Definition MMDeviceConstants.h:277
@ StopSequence
Definition MMDeviceConstants.h:281
@ AfterLoadSequence
Definition MMDeviceConstants.h:279
@ StartSequence
Definition MMDeviceConstants.h:280
@ BeforeGet
Definition MMDeviceConstants.h:276
const char *const g_Keyword_Transpose_MirrorY
Definition MMDeviceConstants.h:153
const char *const g_Keyword_Transpose_SwapXY
Definition MMDeviceConstants.h:151
const char *const g_Keyword_Transpose_MirrorX
Definition MMDeviceConstants.h:152
DeviceDetectionStatus
Definition MMDeviceConstants.h:305
@ Unimplemented
Definition MMDeviceConstants.h:306