diff --git a/DeviceAdapters/Revealer/LICENSE b/DeviceAdapters/Revealer/LICENSE new file mode 100644 index 000000000..52b96bc66 --- /dev/null +++ b/DeviceAdapters/Revealer/LICENSE @@ -0,0 +1,142 @@ +GNU Lesser General Public License + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. + +We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. + + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) + + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. + + In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. + + e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. + + b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS diff --git a/DeviceAdapters/Revealer/MMSCCam.cpp b/DeviceAdapters/Revealer/MMSCCam.cpp new file mode 100644 index 000000000..ac7c70e0c --- /dev/null +++ b/DeviceAdapters/Revealer/MMSCCam.cpp @@ -0,0 +1,1489 @@ +/////////////////////////////////////////////////////////////////////////////// +// FILE: MMSCCam.cpp +// PROJECT: Micro-Manager +// SUBSYSTEM: DeviceAdapters +//----------------------------------------------------------------------------- +// COPYRIGHT: HF Agile Device Co., Ltd., 2024 +// +// LICENSE: This file is distributed under the LGPL license. +// License text is included with the source distribution. + +#include "MMSCCam.h" +#include "ModuleInterface.h" +#include "SCDefines.h" + + +const double SCCamera::nominalPixelSizeUm_ = 1.0; + +const char* gCameraDeviceName = "Revealer"; +const char* g_PixelType_8bit = "8bit"; +const char* g_PixelType_16bit = "16bit"; +const char* g_feature_xoffset = "OffsetX"; +const char* g_feature_yoffset = "OffsetY"; +const char* g_feature_width = "Width"; +const char* g_feature_height = "Height"; +const char* g_feature_pixelFormat = "PixelFormat"; +const char* g_feature_sensorWidth = "SensorWidth"; +const char* g_feature_sensorHeight = "SensorHeight"; +const char* g_feature_binning = "BinningMode"; +const char* g_feature_readoutMode = "ReadoutMode"; +const char* g_feature_triggerInType = "TriggerInType"; +const char* g_feature_triggerActivation = "TriggerActivation"; +const char* g_feature_triggerDelay = "TriggerDelay"; + +const char* g_feature_triggerOutSelector = "TriggerOutSelector"; +const char* g_feature_triggerOutType = "TriggerOutType"; +const char* g_feature_triggerOutActivation = "TriggerOutActivation"; +const char* g_feature_triggerOutDelay = "TriggerOutDelay"; +const char* g_feature_triggerOutPulseWidth = "TriggerOutPulseWidth"; +const char* NoHubError = "Parent Hub not defined."; + +const char* g_trigger_off = "off"; +const char* g_trigger_external_edge = "External_Edge_Trigger"; +const char* g_trigger_external_level = "External_Level_Trigger"; +const char* g_trigger_rising_edge = "RisingEdge"; +const char* g_trigger_falling_edge = "FallEdge"; +const char* g_trigger_level_high = "LevelHigh"; +const char* g_trigger_level_low = "LevelLow"; +const char* g_trigger_global_reset_external_edge = "Global_Reset_External_Edge_Trigger"; +const char* g_trigger_global_reset_external_level = "Global_Reset_External_Level_Trigger"; + +const char* g_triggerout1 = "TriggerOut1"; +const char* g_triggerout2 = "TriggerOut2"; +const char* g_triggerout3 = "TriggerOut3"; + +//const char* g_property_triggerOutIFType1 = "TriggerOutIFType1"; +//const char* g_property_triggerOutType1 = "TriggerOutType1"; +//const char* g_property_triggerOutAct1 = "TriggerOutAct1"; +//const char* g_property_triggerOutDelay1 = "TriggerOutAct1"; +//const char* g_property_triggerOutPulseWidth1 = "TriggerOutPulseWidth1"; +//const char* g_trigger_if_name1 = "triggerOut1"; +// +//const char* g_property_triggerOutIFType2 = "TriggerOutIFType2"; +//const char* g_property_triggerOutType2 = "TriggerOutType2"; +//const char* g_property_triggerOutAct2 = "TriggerOutAct2"; +//const char* g_property_triggerOutDelay2 = "TriggerOutAct2"; +//const char* g_property_triggerOutPulseWidth2 = "TriggerOutPulseWidth2"; +//const char* g_trigger_if_name2 = "triggerOut2"; +// +//const char* g_property_triggerOutIFType3 = "TriggerOutIFType3"; +//const char* g_property_triggerOutType3 = "TriggerOutType3"; +//const char* g_property_triggerOutAct3 = "TriggerOutAct3"; +//const char* g_property_triggerOutDelay3 = "TriggerOutAct3"; +//const char* g_property_triggerOutPulseWidth3 = "TriggerOutPulseWidth3"; +//const char* g_trigger_if_name3 = "triggerOut3"; + +const char* g_trigger_exposure_start = "Exposure_Start"; +const char* g_trigger_vsync = "VSYNC"; +const char* g_trigger_readout_end = "Readout_End"; +const char* g_trigger_ready = "Trigger_Ready"; +const char* g_trigger_global_exposure = "Global_Exposure"; +const char* g_trigger_high = "High"; +const char* g_trigger_low = "Low"; + +/////////////////////////////////////////////////////////////////////////////// +// Exported MMDevice API +/////////////////////////////////////////////////////////////////////////////// + +MODULE_API void InitializeModuleData() +{ + RegisterDevice(gCameraDeviceName, MM::CameraDevice, "Scientific Camera Adapter"); +} + +MODULE_API MM::Device* CreateDevice(const char* deviceName) +{ + if (deviceName == 0) + return 0; + + // decide which device class to create based on the deviceName parameter + if (strcmp(deviceName, gCameraDeviceName) == 0) + { + // create camera + return new SCCamera(); + } + + // ...supplied name not recognized + return 0; +} + +MODULE_API void DeleteDevice(MM::Device* pDevice) +{ + delete pDevice; +} + + +/////////////////////////////////////////////////////////////////////////////// +// SCCamera implementation +// ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +/** +* SCCamera constructor. +* Setup default all variables and create device properties required to exist +* before intialization. In this case, no such properties were required. All +* properties will be created in the Initialize() method. +* +* As a general guideline Micro-Manager devices do not access hardware in the +* the constructor. We should do as little as possible in the constructor and +* perform most of the initialization in the Initialize() method. +*/ +SCCamera::SCCamera() : + CCameraBase (), + insertCount_(0), + initialized_(false), + devHandle_(nullptr), + isAcqusition_(false), + xoffset_(0), + yoffset_(0), + depth_(0), + rawBuffer_(nullptr), + recvImage_(nullptr), + thd_(nullptr), + stopOnOverflow_(false), + isSequenceable_(false), + sequenceMaxLength_(100), + sequenceRunning_(false), + sequenceIndex_(0) +{ + CreateHubIDProperty(); +} + +SCCamera::~SCCamera() +{ + StopSequenceAcquisition(); + if (thd_) { + delete thd_; + thd_ = nullptr; + } + + if (recvImage_) { + delete recvImage_; + recvImage_ = nullptr; + } + +} + +/** +* Obtains device name. +* Required by the MM::Device API. +*/ +void SCCamera::GetName(char* name) const +{ + CDeviceUtils::CopyLimitedString(name, gCameraDeviceName); +} + +/** +* Intializes the hardware. +* Required by the MM::Device API. +* Typically we access and initialize hardware at this point. +* Device properties are typically created here as well, except +* the ones we need to use for defining initialization parameters. +* Such pre-initialization properties are created in the constructor. +* (This device does not have any pre-initialization properties) +*/ +int SCCamera::Initialize() +{ + if (initialized_) return DEVICE_OK; + + LogMessage("init start"); + // init + SC_Init(SCLogLevel::eInfo); + + // enum device + SC_DeviceList deviceInfoList; + auto ret = SC_EnumDevices(&deviceInfoList, eInterfaceTypeAll, nullptr); + if (ret != SC_OK) { + LogMessage("enumDevice failed"); + return DEVICE_ERR; + } + + if (deviceInfoList.nDevNum < 1) { + LogMessage("on device online"); + return DEVICE_NOT_CONNECTED; + } + + for (uint32_t i = 0; i < deviceInfoList.nDevNum; i++) { + if (deviceInfoList.pDevInfo[i].nCameraType == eTypeVirtual) { + continue; + } + ret = SC_CreateHandle(&devHandle_, eModeByCameraKey, deviceInfoList.pDevInfo[i].cameraKey); + if (ret != SC_OK) { + LogMessage("create device handle failed"); + return DEVICE_NOT_CONNECTED; + } + break; + } + + ret = SC_OpenEx(devHandle_, SC_ECameraAccessPermission::eAccessPermissionMonitor); + if (ret != SC_OK) { + LogMessage("create device handle failed"); + return DEVICE_NOT_CONNECTED; + } + + int nRet = CreateProperty(MM::g_Keyword_Name, gCameraDeviceName, MM::String, true); + if (DEVICE_OK != nRet) + return nRet; + + // Description + nRet = CreateProperty(MM::g_Keyword_Description, "ZKJS Camera Device ", MM::String, true); + if (DEVICE_OK != nRet) + return nRet; + + // CameraName + nRet = CreateProperty(MM::g_Keyword_CameraName, "ZKJS Camera", MM::String, true); + assert(nRet == DEVICE_OK); + + // CameraID + nRet = CreateProperty(MM::g_Keyword_CameraID, "V1.0", MM::String, true); + assert(nRet == DEVICE_OK); + + // exposure + double exp = 0; + nRet = SC_GetFloatFeatureValue(devHandle_, "ExposureTime", &exp); + nRet = CreateProperty(MM::g_Keyword_Exposure, std::to_string(exp/1000.0f).c_str(), MM::Float, false); + assert(nRet == DEVICE_OK); + + // binning + CPropertyAction *pAct = new CPropertyAction (this, &SCCamera::OnBinning); + nRet = CreateProperty(MM::g_Keyword_Binning, "1", MM::Integer, false, pAct); + assert(nRet == DEVICE_OK); + + std::vector binValues; + binValues.push_back("1"); // off + + nRet = SetAllowedValues(MM::g_Keyword_Binning, binValues); + if (nRet != DEVICE_OK) + return nRet; + + // pixelType + pAct = new CPropertyAction (this, &SCCamera::OnPixelType); + nRet = CreateProperty(MM::g_Keyword_PixelType, g_PixelType_16bit, MM::String, false, pAct); + assert(nRet == DEVICE_OK); + + std::vector pixelValues; + pixelValues.push_back(g_PixelType_16bit); + + nRet = SetAllowedValues(MM::g_Keyword_PixelType, pixelValues); + if (nRet != DEVICE_OK) + return nRet; + + // trigger in type + nRet = createTriggerProperty(); + if (nRet != DEVICE_OK) + return nRet; + + nRet = createTriggerOutProperty(); + if (nRet != DEVICE_OK) + return nRet; + + // readoutMode + uint64_t readOutMode = 0; + readOutModes_.clear(); + readOutModes_.push_back("bit11_HS_Low"); + readOutModes_.push_back("bit11_HS_High"); + readOutModes_.push_back("bit11_HDR_Low"); + readOutModes_.push_back("bit11_HDR_High"); + readOutModes_.push_back("bit12_HDR_Low"); + readOutModes_.push_back("bit12_HDR_High"); + readOutModes_.push_back("bit12_CMS"); + readOutModes_.push_back("bit16_From11"); + readOutModes_.push_back("bit16_From12"); + //readOutModes_.push_back("bit11_HDR_2F"); + //readOutModes_.push_back("bit12_HDR_2F"); + //readOutModes_.push_back("CMS_2F"); + + std::string value = "bit11_HS_Low"; + nRet = SC_GetEnumFeatureValue(devHandle_, g_feature_readoutMode, &readOutMode); + if (nRet == SC_OK && readOutMode < readOutModes_.size()) { + value = readOutModes_[readOutMode]; + } + pAct = new CPropertyAction (this, &SCCamera::OnReadOutMode); + nRet = CreateProperty(g_feature_readoutMode, value.c_str(), MM::String, false, pAct); + assert(nRet == DEVICE_OK); + + nRet = SetAllowedValues(g_feature_readoutMode, readOutModes_); + if (nRet != DEVICE_OK) + return nRet; + + + // Whether or not to use exposure time sequencing + pAct = new CPropertyAction (this, &SCCamera::OnIsSequenceable); + std::string propName = "UseExposureSequences"; + CreateStringProperty(propName.c_str(), "No", false, pAct); + AddAllowedValue(propName.c_str(), "Yes"); + AddAllowedValue(propName.c_str(), "No"); + + // resizeBuffer + int64_t width = 0, height = 0; + uint64_t pixelFormat = 0, binningMode = 0; + SC_GetIntFeatureValue(devHandle_, g_feature_width, &width); + SC_GetIntFeatureValue(devHandle_, g_feature_height, &height); + SC_GetEnumFeatureValue(devHandle_, g_feature_pixelFormat, &pixelFormat); + SC_GetEnumFeatureValue(devHandle_, g_feature_binning, &binningMode); + auto binningValue = convertBinningModeToBinningValue((int)binningMode); + auto depth = convertPixelFormatToDepth((SC_EPixelType)pixelFormat); + ResizeImageBuffer((int)width, (int)height, depth/8, binningValue); + + nRet = UpdateStatus(); + if (nRet != DEVICE_OK) + return nRet; + + thd_ = new CameraRecvThread(this); + recvImage_ = new SC_Frame(); + + initialized_ = true; + LogMessage("init end"); + return DEVICE_OK; +} + +/** +* Shuts down (unloads) the device. +* Required by the MM::Device API. +* Ideally this method will completely unload the device and release all resources. +* Shutdown() may be called multiple times in a row. +* After Shutdown() we should be allowed to call Initialize() again to load the device +* without causing problems. +*/ +int SCCamera::Shutdown() +{ + LogMessage("Shutdown"); + StopSequenceAcquisition(); + SC_Close(devHandle_); + SC_DestroyHandle(devHandle_); + SC_Release(); + return DEVICE_OK; +} + + +int SCCamera::SnapImage() +{ + if (!isAcqusition_) { + SC_StartGrabbingEx(devHandle_, 0, SC_EGrabStrategy::grabStrartegySequential); + } + isAcqusition_ = true; + + if (sequenceRunning_ && IsCapturing()){ + double exp = GetSequenceExposure(); + SetExposure(exp); + } + + auto rslt = getNextFrame(); + if (rslt != DEVICE_OK) { + LogMessage("getFrame failed"); + return rslt; + } + + auto ret = SC_StopGrabbing(devHandle_); + if (ret != SC_OK) { + LogMessage("stop grabbing failed"); + return DEVICE_ERR; + } + isAcqusition_ = false; + return DEVICE_OK; +}; + +const unsigned char* SCCamera::GetImageBuffer() +{ + MMThreadGuard g(imgPixelsLock_); + unsigned char *pB = (unsigned char*)(image_.GetPixels()); + return pB; +} + +unsigned SCCamera::GetImageWidth() const +{ + return image_.Width(); +} + +unsigned SCCamera::GetImageHeight() const { + return image_.Height(); +} + +unsigned SCCamera::GetImageBytesPerPixel() const { + return image_.Depth(); +} + +unsigned SCCamera::GetBitDepth() const { + return 8 * GetImageBytesPerPixel(); +} + +long SCCamera::GetImageBufferSize() const { + auto size = image_.Width() * image_.Height() * image_.Depth(); + return size; +} + +double SCCamera::GetExposure() const { + char buf[MM::MaxStrLength]; + int ret = GetProperty(MM::g_Keyword_Exposure, buf); + if (ret != DEVICE_OK) + return 0.0; + + std::ostringstream msg; + msg << "GetExposure:" << atof(buf); + LogMessage(msg.str().c_str()); + return atof(buf); +} + +void SCCamera::SetExposure(double exp) { + double realExp = 0; + SC_SetFloatFeatureValue(devHandle_, "ExposureTime", exp * 1000); + SC_GetFloatFeatureValue(devHandle_, "ExposureTime", &realExp); + SetProperty(MM::g_Keyword_Exposure, CDeviceUtils::ConvertToString(realExp/1000)); + GetCoreCallback()->OnExposureChanged(this, realExp/1000); + + std::ostringstream msg; + msg << "SetExposure:" << exp << "," << realExp/1000; + LogMessage(msg.str().c_str()); + return; +} + +int SCCamera::SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) { + + int32_t rslt = SC_ERROR; + std::ostringstream errMsg; + unsigned actualX = x, actualY = y, actualXSize = xSize, actualYSize = ySize; + + // close binning + auto origBinningValue = GetBinning(); + auto origBinningMode = convertBinningValueToBinningMode(origBinningValue); + + auto binningValue = 1; + auto binningMode = convertBinningValueToBinningMode(binningValue); + SC_SetEnumFeatureValue(devHandle_, g_feature_binning, binningMode); + + // TODO: + getActualRoi(actualX, actualY, actualXSize, actualYSize); + + rslt = SC_SetIntFeatureValue(devHandle_, g_feature_xoffset, (uint64_t)actualX); + if (rslt != SC_OK) { + errMsg << "set xoffset failed:" << x << std::endl; + LogMessage(errMsg.str().c_str()); + return DEVICE_INVALID_PROPERTY_VALUE; + } + + rslt = SC_SetIntFeatureValue(devHandle_, g_feature_yoffset, (uint64_t)actualY); + if (rslt != SC_OK) { + errMsg << "set yoffset failed:" << y << std::endl; + LogMessage(errMsg.str().c_str()); + return DEVICE_INVALID_PROPERTY_VALUE; + } + + rslt = SC_SetIntFeatureValue(devHandle_, g_feature_width, (uint64_t)actualXSize); + if (rslt != SC_OK) { + errMsg << "set width failed:" << xSize << std::endl; + LogMessage(errMsg.str().c_str()); + return DEVICE_INVALID_PROPERTY_VALUE; + } + + rslt = SC_SetIntFeatureValue(devHandle_, g_feature_height, (uint64_t)actualYSize); + if (rslt != SC_OK) { + errMsg << "set height failed:" << ySize << std::endl; + LogMessage(errMsg.str().c_str()); + return DEVICE_INVALID_PROPERTY_VALUE; + } + + SC_SetEnumFeatureValue(devHandle_, g_feature_binning, origBinningMode); + GetROI(actualX, actualY, actualXSize, actualYSize); + xoffset_ = actualX; + yoffset_ = actualY; + + char buf[MM::MaxStrLength]; + auto ret = GetProperty(MM::g_Keyword_PixelType, buf); + if (ret != DEVICE_OK) + return ret; + + int depth = 1; + ret = getDepth(buf, depth); + if (ret != DEVICE_OK) return ret; + + return ResizeImageBuffer(actualXSize, actualYSize, depth, 1); +} + +int SCCamera::GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize) +{ + int64_t xoffset = x; + int64_t yoffset = y; + int64_t width = xSize; + int64_t height = ySize; + auto rslt = SC_GetIntFeatureValue(devHandle_, g_feature_xoffset, &xoffset); + SC_GetIntFeatureValue(devHandle_, g_feature_yoffset, &yoffset); + SC_GetIntFeatureValue(devHandle_, g_feature_width, &width); + SC_GetIntFeatureValue(devHandle_, g_feature_height, &height); + return DEVICE_OK; +} + +int SCCamera::ClearROI() { + int64_t width = 0; + int64_t height = 0; + SC_GetIntFeatureValue(devHandle_, g_feature_sensorWidth, &width); + SC_GetIntFeatureValue(devHandle_, g_feature_sensorHeight, &height); + SetROI(0, 0, width, height); + return DEVICE_OK; +} + +double SCCamera::GetSequenceExposure() +{ + if (exposureSequence_.size() == 0) { + return this->GetExposure(); + } + + double exposure = exposureSequence_[sequenceIndex_]; + sequenceIndex_++; + if (sequenceIndex_ >= exposureSequence_.size()) { + sequenceIndex_ = 0; + } + return exposure; +} + +int SCCamera::StartSequenceAcquisition(double interval) { + return StartSequenceAcquisition(LONG_MAX, interval, false); +} + +int SCCamera::StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow) { + if (IsCapturing()) { + //return DEVICE_CAMERA_BUSY_ACQUIRING; + StopSequenceAcquisition(); + } + + if (!isAcqusition_) { + auto rslt = SC_StartGrabbingEx(devHandle_, numImages, SC_EGrabStrategy::grabStrartegySequential); + if (rslt != SC_OK) { + return rslt; + } + } + + stopOnOverflow_ = stopOnOverflow; + int ret = GetCoreCallback()->PrepareForAcq(this); + if (ret != DEVICE_OK) + return ret; + + //auto bret = GetCoreCallback()->InitializeImageBuffer(10, 1, GetImageWidth(), GetImageHeight(), GetImageBytesPerPixel()); + //if (!bret) { + // LogMessage("InitializeImageBuffer failed"); + //} + thd_->Start(numImages, interval_ms); + isAcqusition_ = true; + LogMessage("StartSequenceAcquisition"); + return DEVICE_OK; +} + +int SCCamera::StopSequenceAcquisition() { + if (thd_ && !thd_->IsStopped()) { + thd_->Stop(); + thd_->wait(); + } + + auto rslt = SC_StopGrabbing(devHandle_); + if (rslt != SC_OK) { + LogMessage("stop aquisition failed"); + return DEVICE_ERR; + } + isAcqusition_ = false; + LogMessage("stop aquisition"); + return DEVICE_OK; +} + + + + +int SCCamera::ResizeImageBuffer( + int imageSizeW, + int imageSizeH, + int byteDepth, + int binSize) +{ + std::ostringstream msg; + msg << "ResizeImageBuffer: (" << imageSizeW << "," << imageSizeH << "," << binSize << "," << byteDepth << ")" << std::endl; + LogMessage(msg.str().c_str()); + + image_.Resize(imageSizeW / binSize, imageSizeH / binSize, byteDepth); + return DEVICE_OK; +} + +void SCCamera::getActualRoi( + unsigned& actualX, + unsigned& actualY, + unsigned& actualXSize, + unsigned& actualYSize) +{ + actualX = (actualX >> 6) << 6; + actualY = (actualY >> 1) << 1; + actualXSize = (actualXSize >> 6) << 6; + actualYSize = (actualYSize >> 1) << 1; + if (actualXSize == 0) actualXSize = (1 >> 6); + if (actualYSize == 0) actualYSize = (1 >> 2); +} + + +int SCCamera::getDepth(const char* pixelType, int &byteDepth) +{ + std::ostringstream errMsg; + if (strcmp(pixelType, g_PixelType_8bit) == 0) { + byteDepth = 1; + } + else if (strcmp(pixelType, g_PixelType_16bit) == 0) { + byteDepth = 2; + } + else { + errMsg << "invalid pixeltype : " << pixelType << std::endl; + LogMessage(errMsg.str().c_str()); + return DEVICE_UNSUPPORTED_DATA_FORMAT; + } + return DEVICE_OK; +} + +int SCCamera::RunSequenceOnThread(MM::MMTime startTime) +{ + auto rslt = getNextFrame(); + if (rslt != DEVICE_OK) { + LogMessage("getNextFrame failed"); + return rslt; + } + LogMessage("GetOneFrame end"); + rslt = InsertImage(); + if (rslt != DEVICE_OK) { + LogMessage("insertFrame failed"); + } + + ++insertCount_; + std::ostringstream msg; + msg << "InsertOneFrame end (" << GetImageWidth() << ',' << GetImageHeight() << ',' << GetImageBytesPerPixel() << "," << insertCount_ << ')'; + LogMessage(msg.str().c_str()); + return rslt; +} + +int SCCamera::InsertImage() +{ + auto width = GetImageWidth(); + auto height = GetImageHeight(); + unsigned int bytePerPixel = GetImageBytesPerPixel(); + + MM::MMTime timeStamp = this->GetCurrentMMTime(); + char label[MM::MaxStrLength]; + this->GetLabel(label); + + Metadata md; + md.put(MM::g_Keyword_Metadata_CameraLabel, label); + //md.put(MM::g_Keyword_Metadata_ROI_X, CDeviceUtils::ConvertToString( (long) xoffset_)); + //md.put(MM::g_Keyword_Metadata_ROI_Y, CDeviceUtils::ConvertToString( (long) yoffset_)); + MMThreadGuard g(imgPixelsLock_); + const unsigned char* data = GetImageBuffer(); + + auto coreCallback = GetCoreCallback(); + auto rslt = GetCoreCallback()->InsertImage(this, data, width, height, bytePerPixel,1, md.Serialize().c_str()); + if (!stopOnOverflow_ && rslt == DEVICE_BUFFER_OVERFLOW) + { + // do not stop on overflow - just reset the buffer + GetCoreCallback()->ClearImageBuffer(this); + // don't process this same image again... + rslt = GetCoreCallback()->InsertImage(this, data, width, height, bytePerPixel, 1, md.Serialize().c_str(), false); + } + return rslt; +} + +int SCCamera::getNextFrame() { + auto rslt = SC_GetFrame(devHandle_, recvImage_, 1000); + if (rslt == SC_TIMEOUT) { + LogMessage("recv frame timeout"); + return DEVICE_OK; + } + else if (rslt != SC_OK) { + LogMessage("recv frame failed"); + return DEVICE_ERR; + } + + auto height = recvImage_->frameInfo.height; + auto width = recvImage_->frameInfo.width; + auto pixelFormat = recvImage_->frameInfo.pixelFormat; + auto depth = convertPixelFormatToDepth(pixelFormat); + + if (height == 0 || width == 0 || depth == 0) + return DEVICE_OUT_OF_MEMORY; + + if (height != GetImageHeight() || width != GetImageWidth() || depth/8 != GetImageBytesPerPixel()) { + ResizeImageBuffer(width, height, depth/8, 1); + } + + std::ostringstream msg; + msg << "getFrame:(" << height << "," << width << "," << recvImage_->frameInfo.size << "," << GetImageBufferSize() <<"," << depth << ")" << std::endl; + LogMessage(msg.str().c_str()); + + auto dst = image_.GetPixelsRW(); + memcpy(dst, recvImage_->pData, recvImage_->frameInfo.size); + SC_ReleaseFrame(devHandle_, recvImage_); + + return DEVICE_OK; +} + +void SCCamera::OnThreadExiting() throw() +{ + try + { + LogMessage(g_Msg_SEQUENCE_ACQUISITION_THREAD_EXITING); + if (GetCoreCallback()) GetCoreCallback()->AcqFinished(this,0); + } + catch(...) + { + LogMessage(g_Msg_EXCEPTION_IN_ON_THREAD_EXITING, false); + } +} + +bool SCCamera::IsCapturing(){ + if (!thd_) return false; + std::ostringstream msg; + msg << "IsCapturing" << ":" << !thd_->IsStopped(); + LogMessage(msg.str().c_str()); + return !thd_->IsStopped(); +} + +double SCCamera::GetNominalPixelSizeUm() const{ + return nominalPixelSizeUm_; +} + +double SCCamera::GetPixelSizeUm() const { + return nominalPixelSizeUm_ * GetBinning(); +} + +int SCCamera::GetBinning() const { + uint64_t binning = 0; + SC_GetEnumFeatureValue(devHandle_, "BinningMode", &binning); + auto value = convertBinningModeToBinningValue((int)binning); + return value; +} + +int SCCamera::SetBinning(int bS) { + std::ostringstream msg; + auto mode = convertBinningValueToBinningMode(bS); + auto rslt = SC_SetEnumFeatureValue(devHandle_, g_feature_binning, mode); + if (rslt != SC_OK) { + msg << "SetBinning value:" << bS << ", mode:" << mode << "failed"; + LogMessage(msg.str().c_str()); + } + LogMessage(std::string("setBinning ").append(std::to_string(mode)).data()); + return SC_OK; + //return SetProperty(MM::g_Keyword_Binning, CDeviceUtils::ConvertToString(bS)); +} + +int SCCamera::IsExposureSequenceable(bool& isSequenceable) const { + isSequenceable = isSequenceable_; + LogMessage("IsExposureSequenceable"); + return DEVICE_OK; +} + +int SCCamera::GetExposureSequenceMaxLength(long& length) const { + if (!isSequenceable_) { + return DEVICE_UNSUPPORTED_COMMAND; + } + + length = sequenceMaxLength_; + LogMessage("GetExposureSequenceMaxLength"); + return DEVICE_OK; +} + +int SCCamera::StartExposureSequence() { + if (!isSequenceable_) { + return DEVICE_UNSUPPORTED_COMMAND; + } + + sequenceRunning_ = true; + LogMessage("StartExposureSequence"); + return DEVICE_OK; +} + +int SCCamera::StopExposureSequence() { + if (!isSequenceable_) + { + return DEVICE_UNSUPPORTED_COMMAND; + } + + sequenceRunning_ = false; + sequenceIndex_ = 0; + LogMessage("StopExposureSequence"); + return DEVICE_OK; +} + +int SCCamera::ClearExposureSequence() { + if (!isSequenceable_) { + return DEVICE_UNSUPPORTED_COMMAND; + } + + exposureSequence_.clear(); + std::ostringstream msg; + LogMessage("ClearExposureSequence"); + return DEVICE_OK; +} + +int SCCamera::AddToExposureSequence(double exposureTime_ms) { + if (!isSequenceable_) { + return DEVICE_UNSUPPORTED_COMMAND; + } + + exposureSequence_.push_back(exposureTime_ms); + LogMessage("AddToExposureSequence"); + return DEVICE_OK; +} + +int SCCamera::SendExposureSequence() const { + if (!isSequenceable_) { + return DEVICE_UNSUPPORTED_COMMAND; + } + LogMessage("SendExposureSequence"); + return DEVICE_OK; +} + +unsigned SCCamera::GetNumberOfComponents() const { + LogMessage("GetNumberOfComponents"); + return 1; +} + +int SCCamera::OnIsSequenceable(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + std::string val = "Yes"; + if (eAct == MM::BeforeGet) + { + if (!isSequenceable_) + { + val = "No"; + } + pProp->Set(val.c_str()); + } + else if (eAct == MM::AfterSet) + { + isSequenceable_ = false; + pProp->Get(val); + if (val == "Yes") + { + isSequenceable_ = true; + } + } + return DEVICE_OK; +} + +int SCCamera::OnBinning(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + int ret = DEVICE_ERR; + switch (eAct) + { + case MM::AfterSet: + { + if (IsCapturing()) { + return DEVICE_CAMERA_BUSY_ACQUIRING; + } + long binFactor; + pProp->Get(binFactor); + if (binFactor == 1 || binFactor == 2 || binFactor == 4) + { + // calculate ROI using the previous bin settings + ResizeImageBuffer(GetImageWidth(), GetImageHeight(), GetImageBytesPerPixel(), binFactor); + + std::ostringstream os; + os << binFactor; + OnPropertyChanged("Binning", os.str().c_str()); + ret = DEVICE_OK; + } + else { + LogMessage("invalid binning value"); + } + break; + } + + case MM::BeforeGet: { + ret = DEVICE_OK; + break; + } + } + return ret; +} + +int SCCamera::OnReadOutMode(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + auto ret = DEVICE_ERR; + switch (eAct) { + case MM::AfterSet: + { + if (IsCapturing()) { + return DEVICE_CAN_NOT_SET_PROPERTY; + } + + std::string readOutMode; + pProp->Get(readOutMode); + auto mode = getReadOutModeEnum(readOutMode.c_str()); + if (mode == bit12_HDR_Low || mode == bit12_HDR_High || mode == bit12_CMS) { + AddAllowedValue(g_feature_triggerInType, g_trigger_global_reset_external_edge); + AddAllowedValue(g_feature_triggerInType, g_trigger_global_reset_external_level); + } + ret = DEVICE_OK; + }break; + + case MM::BeforeGet: { + ret = DEVICE_OK;; + }break; + + } + return ret; +} + +int SCCamera::OnTriggerSelector(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + auto ret = DEVICE_ERR; + switch (eAct) + { + case MM::AfterSet: { + std::string selector; + pProp->Get(selector); + auto rslt = SC_SetEnumFeatureValue(devHandle_, g_feature_triggerOutSelector, convertTriggerOutSeletorToEnum(selector.c_str())); + if (rslt != SC_OK) { + LogMessage("set selector failed"); + return ret; + } + + uint64_t triggerOutType = 0, triggerOutAct = 0; + double delay = 0, pulseWidth = 0; + SC_GetEnumFeatureValue(devHandle_, g_feature_triggerOutType, &triggerOutType); + SetProperty(g_feature_triggerOutType, triggerOutTypes_[triggerOutType].c_str()); + + SC_GetEnumFeatureValue(devHandle_, g_feature_triggerOutActivation, &triggerOutAct); + SetProperty(g_feature_triggerOutActivation, triggerActivations_[triggerOutAct].c_str()); + + SC_GetFloatFeatureValue(devHandle_, g_feature_triggerOutDelay, &delay); + SetProperty(g_feature_triggerOutDelay, std::to_string(delay).c_str()); + + SC_GetFloatFeatureValue(devHandle_, g_feature_triggerOutPulseWidth, &pulseWidth); + SetProperty(g_feature_triggerOutPulseWidth, std::to_string(pulseWidth).c_str()); + ret = DEVICE_OK; + }break; + + case MM::BeforeGet: + { + ret = DEVICE_OK; + }break; + } + return ret; +} + +int SCCamera::OnTriggerOut(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + auto ret = DEVICE_ERR; + switch (eAct) + { + case MM::AfterSet: + { + if (IsCapturing()) + return DEVICE_CAN_NOT_SET_PROPERTY; + std::string type; + pProp->Get(type); + + std::vector values; + if (type == g_trigger_exposure_start || type == g_trigger_vsync || type == g_trigger_readout_end) { + values.push_back(g_trigger_falling_edge); + values.push_back(g_trigger_rising_edge); + SetAllowedValues(g_feature_triggerOutActivation, values); + SetPropertyLimits(g_feature_triggerOutDelay, 0, 1e6); // us + SetProperty(g_feature_triggerOutActivation, g_trigger_rising_edge); + } + else if (type == g_trigger_ready || type == g_trigger_global_exposure) { + values.push_back(g_trigger_level_high); + values.push_back(g_trigger_level_low); + SetAllowedValues(g_feature_triggerOutActivation, values); + SetPropertyLimits(g_feature_triggerOutDelay, 0, 1e6); // us + SetProperty(g_feature_triggerOutActivation, g_trigger_level_high); + } + else { + ClearAllowedValues(g_feature_triggerActivation); + } + ret = DEVICE_OK; + } break; + + case MM::BeforeGet: + { + ret = DEVICE_OK; + }break; + } + return ret; +} + +int SCCamera::OnTriggerIn(MM::PropertyBase* pProp, MM::ActionType eAct) { + auto ret = DEVICE_ERR; + switch (eAct) + { + case MM::AfterSet: + { + if (IsCapturing()) + return DEVICE_CAN_NOT_SET_PROPERTY; + std::string type; + pProp->Get(type); + + std::vector values; + if (type == g_trigger_external_edge) { + values.push_back(g_trigger_falling_edge); + values.push_back(g_trigger_rising_edge); + SetAllowedValues(g_feature_triggerActivation, values); + SetPropertyLimits(g_feature_triggerDelay, 0, 1e6); // us + SetProperty(g_feature_triggerActivation, g_trigger_rising_edge); + } + else if (type == g_trigger_external_level) { + values.push_back(g_trigger_level_high); + values.push_back(g_trigger_level_low); + SetAllowedValues(g_feature_triggerActivation, values); + SetPropertyLimits(g_feature_triggerDelay, 0, 1e6); // us + SetProperty(g_feature_triggerActivation, g_trigger_level_high); + } + else { + ClearAllowedValues(g_feature_triggerActivation); + SetPropertyLimits(g_feature_triggerDelay, 0, 0); // disable + } + ret = DEVICE_OK; + } break; + + case MM::BeforeGet: + { + ret = DEVICE_OK; + }break; + } + return ret; +} + +int SCCamera::OnPixelType(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + int ret = DEVICE_ERR; + switch(eAct) + { + case MM::AfterSet: + { + if(IsCapturing()) + return DEVICE_CAN_NOT_SET_PROPERTY; + + std::string pixelType; + pProp->Get(pixelType); + + int depth; + ret = getDepth(pixelType.c_str(), depth); + if (ret == DEVICE_OK) { + ret = ResizeImageBuffer(image_.Width(), image_.Height(), depth, 1); + } + else + { + // on error switch to default pixel type + pProp->Set(g_PixelType_8bit); + ResizeImageBuffer(image_.Width(), image_.Height(), 1); + ret = DEVICE_UNSUPPORTED_DATA_FORMAT; + } + + }break; + case MM::BeforeGet: + { + ret=DEVICE_OK; + }break; + } + return ret; +} + +int SCCamera::convertPixelFormatToDepth(SC_EPixelType pixel) { + switch (pixel) { + case SC_EPixelType::gvspPixelMono12: + case SC_EPixelType::gvspPixelMono16: + return 16; + + default: + LogMessage("invalid pixel"); + return 0; + } + return 0; +} + +int32_t SCCamera::convertTriggerOutSeletorToEnum(const char* selector) +{ + if (strcmp(selector, g_triggerout1) == 0) return 1; + if (strcmp(selector, g_triggerout2) == 0) return 2; + if (strcmp(selector, g_triggerout3) == 0) return 3; + return 0; +} + +std::string SCCamera::convertTriggerOutSelectorToVal(int32_t selector) +{ + if (selector == 1) return g_triggerout1; + if (selector == 2) return g_triggerout2; + if (selector == 3) return g_triggerout3; + return ""; +} + +int32_t SCCamera::convertTriggerOutTypeToEnum(const char* type) +{ + for (int32_t i = 0; i < triggerOutTypes_.size(); ++i) { + if (strcmp(triggerOutTypes_[i].c_str(), type) == 0) return i; + } + return -1; +} + +int SCCamera::convertBinningModeToBinningValue(int binningMode) const +{ + if (binningMode == 0) return 1; // off + if (binningMode == 1) return 2; // 2*2 + if (binningMode == 2) return 4; // 4*4 + return 1; +} + +int SCCamera::convertBinningValueToBinningMode(int binningValue) const +{ + if (binningValue == 1) return 0; // off + if (binningValue == 2) return 1; // 2*2 + if (binningValue == 4) return 2; // 4*4 + return 0; +} + +uint32_t SCCamera::getReadOutModeEnum(const char* vvStr) const +{ + for (uint32_t i = 0; i < readOutModes_.size(); ++i) { + if (strcmp(vvStr, readOutModes_[i].c_str()) == 0) { + return i; + } + } + return (uint32_t)readOutModes_.size(); +} + +uint32_t SCCamera::convertReadOutModeEnum(const char* name, const char* vvStr) const +{ + if (strcmp(vvStr, "bit11_HS_Low") == 0) return bit11_HS_Low; + if (strcmp(vvStr, "bit11_HS_High") == 0) return bit11_HS_High; + if (strcmp(vvStr, "bit11_HDR_Low") == 0) return bit11_HDR_Low; + if (strcmp(vvStr, "bit11_HDR_High") == 0) return bit11_HDR_High; + if (strcmp(vvStr, "bit12_HDR_Low") == 0) return bit12_HDR_Low; + if (strcmp(vvStr, "bit12_HDR_High") == 0) return bit12_HDR_High; + if (strcmp(vvStr, "bit12_CMS") == 0) return bit12_CMS; + if (strcmp(vvStr, "bit16_From11") == 0) return bit16_From11; + if (strcmp(vvStr, "bit16_From12") == 0) return bit16_From12; + //if (strcmp(vvStr, "bit11_HDR_2F") == 0) return 9; + //if (strcmp(vvStr, "bit12_HDR_2F") == 0) return 10; + //if (strcmp(vvStr, "CMS_2F") == 0) return 11; + return 0; +} + +std::string SCCamera::convertReadOutModeStr(const char* name, uint64_t vv) const +{ + switch (vv) { + case bit11_HS_Low: + return "bit11_HS_Low"; + case bit11_HS_High: + return "bit11_HS_High"; + case bit11_HDR_Low: + return "bit11_HDR_Low"; + case bit11_HDR_High: + return "bit11_HDR_High"; + case bit12_HDR_Low: + return "bit12_HDR_Low"; + case bit12_HDR_High: + return "bit12_HDR_High"; + case bit12_CMS: + return "bit12_CMS"; + case bit16_From11: + return "bit16_From11"; + case bit16_From12: + return "bit16_From12"; + default: + return "bit11_HS_Low"; + } +} + +std::string SCCamera::convertTriggerTypeToValue(int32_t type) +{ + if (type == 0) return g_trigger_off; + if (type == 1) return g_trigger_external_edge; + if (type == 3) return g_trigger_external_level; + return g_trigger_off; +} + +int32_t SCCamera::convertTriggerValueToType(const char* value) { + if (strcmp(value, g_trigger_off) == 0) return 0; + if (strcmp(value, g_trigger_external_edge) == 0) return 1; + if (strcmp(value, g_trigger_external_level) == 0) return 3; + return 0; +} + +int SCCamera::GetProperty(const char* name, char* value) const +{ + if (strcmp(g_feature_readoutMode, name) == 0) { + uint64_t vv; + auto rslt = SC_GetEnumFeatureValue(devHandle_, name, &vv); + if (rslt != SC_OK) { + LogMessage("getProperty failed"); + return DEVICE_OK; + } + auto valueStr = convertReadOutModeStr(name, vv); + memcpy(value, valueStr.data(), valueStr.length()); + return DEVICE_OK; + } + return CDeviceBase::GetProperty(name, value); +} + + +int SCCamera::SetProperty(const char* name, const char* value) +{ + int32_t rslt = SC_ERROR; + if (strcmp(g_feature_readoutMode, name) == 0) { + auto mode = convertReadOutModeEnum(name, value); + rslt = SC_SetEnumFeatureValue(devHandle_, name, mode); + } + + else if (strcmp(g_feature_triggerOutSelector, name) == 0) { + auto selector = convertTriggerOutSeletorToEnum(value); + rslt = SC_SetEnumFeatureValue(devHandle_, name, selector); + } + + else if (strcmp(g_feature_triggerInType, name) == 0) { + auto type = convertTriggerValueToType(value); + rslt = SC_SetEnumFeatureValue(devHandle_, name, type); + } + + else if (strcmp(g_feature_triggerActivation, name) == 0 || strcmp(g_feature_triggerOutActivation, name) == 0) { + for (uint32_t i = 0; i < triggerActivations_.size(); ++i) { + if (strcmp(triggerActivations_[i].data(), value) == 0) { + rslt = SC_SetEnumFeatureValue(devHandle_, name, i); + } + } + } + else if (strcmp(g_feature_triggerDelay, name) == 0 || strcmp(g_feature_triggerOutDelay, name) == 0) { + double vv = atof(value); + rslt = SC_SetFloatFeatureValue(devHandle_, name, vv); + } + + else if (strcmp(g_feature_triggerOutPulseWidth, name) == 0) { + double vv = atof(value); + rslt = SC_SetFloatFeatureValue(devHandle_, name, vv); + } + else if (strcmp(g_feature_triggerOutType, name) == 0) { + auto type = convertTriggerOutTypeToEnum(value); + rslt = SC_SetEnumFeatureValue(devHandle_, name, type); + } + else if (strcmp("Binning", name) == 0) { + int32_t vv = atoi(value); + rslt = SetBinning(vv); + } + else { + rslt = SC_OK; + } + + if (rslt != SC_OK) { + LogMessage("setProperty failed"); + return DEVICE_OK; + } + return CDeviceBase::SetProperty(name, value); +} + +int32_t SCCamera::createTriggerOutProperty() +{ + uint64_t selector = 1; + auto rslt = SC_SetEnumFeatureValue(devHandle_, g_feature_triggerOutSelector, selector); + assert(rslt == SC_OK); + + // trigger out selector + std::vector selectors; + std::string value = convertTriggerOutSelectorToVal((uint32_t)selector); + auto pAct = new CPropertyAction(this, &SCCamera::OnTriggerSelector); + auto nRet = CreateProperty(g_feature_triggerOutSelector, value.c_str(), MM::String, false, pAct); + assert(nRet == DEVICE_OK); + selectors.push_back(g_triggerout1); + selectors.push_back(g_triggerout2); + selectors.push_back(g_triggerout3); + SetAllowedValues(g_feature_triggerOutSelector, selectors); + + // trigger out type + uint64_t triggerOutType = 0; + rslt = SC_GetEnumFeatureValue(devHandle_, g_feature_triggerOutType, &triggerOutType); + assert(rslt == SC_OK); + + triggerOutTypes_.push_back(g_trigger_exposure_start); + triggerOutTypes_.push_back(g_trigger_vsync); + triggerOutTypes_.push_back(g_trigger_readout_end); + triggerOutTypes_.push_back(g_trigger_ready); + triggerOutTypes_.push_back(g_trigger_global_exposure); + triggerOutTypes_.push_back(g_trigger_high); + triggerOutTypes_.push_back(g_trigger_low); + + value = g_trigger_exposure_start; + if (triggerOutType < triggerOutTypes_.size()) value = triggerOutTypes_[triggerOutType]; + pAct = new CPropertyAction(this, &SCCamera::OnTriggerOut); + nRet = CreateProperty(g_feature_triggerOutType, value.c_str(), MM::String, false, pAct); + assert(nRet == DEVICE_OK); + + nRet = SetAllowedValues(g_feature_triggerOutType, triggerOutTypes_); + if (nRet != DEVICE_OK) + return nRet; + + // trigger out activation + uint64_t triggerActivation = 0; + value = g_trigger_rising_edge; + rslt = SC_GetEnumFeatureValue(devHandle_, g_feature_triggerOutActivation, &triggerActivation); + if (rslt == SC_OK && triggerActivation < triggerActivations_.size()) { + value = triggerActivations_[triggerActivation]; + } + + nRet = CreateProperty(g_feature_triggerOutActivation, value.c_str(), MM::String, false); + assert(nRet == DEVICE_OK); + + // trigger out delay + double delay = 0; + rslt = SC_GetFloatFeatureValue(devHandle_, g_feature_triggerOutDelay, &delay); + + nRet = CreateProperty(g_feature_triggerOutDelay, std::to_string(delay).c_str(), MM::Float, false); + assert(nRet == DEVICE_OK); + + // trigger out pulse width + double pulseWidth = 0; + rslt = SC_GetFloatFeatureValue(devHandle_, g_feature_triggerOutPulseWidth, &delay); + + nRet = CreateProperty(g_feature_triggerOutPulseWidth, std::to_string(pulseWidth).c_str(), MM::Float, false); + assert(nRet == DEVICE_OK); + + return DEVICE_OK; + +} + +int SCCamera::createTriggerProperty() +{ + uint64_t triggerInType = 0; + auto rslt = SC_GetEnumFeatureValue(devHandle_, g_feature_triggerInType, &triggerInType); + if (rslt != SC_OK) { + LogMessage("set trigger off failed"); + } + std::string value = convertTriggerTypeToValue((uint32_t)triggerInType); + auto pAct = new CPropertyAction (this, &SCCamera::OnTriggerIn); + auto nRet = CreateProperty(g_feature_triggerInType, value.c_str(), MM::String, false, pAct); + assert(nRet == DEVICE_OK); + + std::vector triggerInValues; + triggerInValues.push_back(g_trigger_off); + triggerInValues.push_back(g_trigger_external_edge); + triggerInValues.push_back(g_trigger_external_level); + + nRet = SetAllowedValues(g_feature_triggerInType, triggerInValues); + if (nRet != DEVICE_OK) + return nRet; + + // trigger activation + uint64_t triggerActivation = 0; + value = g_trigger_rising_edge; + triggerActivations_.push_back(g_trigger_rising_edge); + triggerActivations_.push_back(g_trigger_falling_edge); + triggerActivations_.push_back(g_trigger_level_high); + triggerActivations_.push_back(g_trigger_level_low); + rslt = SC_GetEnumFeatureValue(devHandle_, g_feature_triggerActivation, &triggerActivation); + if (rslt == SC_OK && triggerActivation < triggerActivations_.size()) { + value = triggerActivations_[triggerActivation]; + } + + nRet = CreateProperty(g_feature_triggerActivation, value.c_str(), MM::String, false); + assert(nRet == DEVICE_OK); + + // trigger delay + double delay = 0; + rslt = SC_GetFloatFeatureValue(devHandle_, g_feature_triggerDelay, &delay); + + nRet = CreateProperty(g_feature_triggerDelay, std::to_string(delay).c_str(), MM::Float, false); + assert(nRet == DEVICE_OK); + + return DEVICE_OK; +} + +int SCCamera::ThreadRun() { + LogMessage("ThreadRun"); + return 0; +} + +CameraRecvThread::CameraRecvThread(SCCamera* pCam) + :camera_(pCam) + ,stop_(true) + ,suspend_(false) + ,numImages_(default_numImages) + ,imageCounter_(0) + ,intervalMs_(default_intervalMS) + ,startTime_(0) + ,actualDuration_(0) + ,lastFrameTime_(0) +{ +} + +CameraRecvThread::~CameraRecvThread() { +} + +void CameraRecvThread::Stop() { + MMThreadGuard(this->stopLock_); + stop_ = true; +} + +void CameraRecvThread::Start(long numImages, double intervalMs) +{ + MMThreadGuard(this->stopLock_); + MMThreadGuard(this->suspendLock_); + numImages_ = numImages; + intervalMs_ = intervalMs; + imageCounter_ = 0; + stop_ = false; + suspend_ = false; + activate(); + actualDuration_ = MM::MMTime{}; + startTime_ = camera_->GetCurrentMMTime(); + lastFrameTime_ = MM::MMTime{}; +} + +bool CameraRecvThread::IsStopped() { + MMThreadGuard(this->stopLock_); + return stop_; +} +void CameraRecvThread::Suspend() { + MMThreadGuard(this->suspendLock_); + suspend_ = true; +} +bool CameraRecvThread::IsSuspended() { + MMThreadGuard(this->suspendLock_); + return suspend_; +} +void CameraRecvThread::Resume() { + MMThreadGuard(this->suspendLock_); + suspend_ = false; +} + +double CameraRecvThread::GetIntervalMs() { + return intervalMs_; +} + +void CameraRecvThread::SetLength(long images) { + numImages_ = images; +} + +long CameraRecvThread::GetLength() const { + return numImages_; +} + +long CameraRecvThread::GetImageCounter() { + return imageCounter_; +} + +MM::MMTime CameraRecvThread::GetStartTime() { + return startTime_; +} + +MM::MMTime CameraRecvThread::GetActualDuration() { + return actualDuration_; +} + +int CameraRecvThread::svc(void) throw() +{ + int ret = DEVICE_ERR; + try + { + MM::MMTime startTime = camera_->GetCurrentMMTime(); + do + { + ret = camera_->RunSequenceOnThread(startTime); + } while (DEVICE_OK == ret && !IsStopped() && imageCounter_++ < numImages_ - 1); + + if (IsStopped()) { + camera_->LogMessage("SeqAcquisition interrupted by the user\n"); + } + } + catch (...) { + camera_->LogMessage(g_Msg_EXCEPTION_IN_THREAD, false); + } + stop_ = true; + actualDuration_ = camera_->GetCurrentMMTime() - startTime_; + camera_->OnThreadExiting(); + return ret; +} diff --git a/DeviceAdapters/Revealer/MMSCCam.h b/DeviceAdapters/Revealer/MMSCCam.h new file mode 100644 index 000000000..8661408ad --- /dev/null +++ b/DeviceAdapters/Revealer/MMSCCam.h @@ -0,0 +1,228 @@ +/////////////////////////////////////////////////////////////////////////////// +// FILE: MMSCCam.h +// PROJECT: Micro-Manager +// SUBSYSTEM: DeviceAdapters +//----------------------------------------------------------------------------- +// COPYRIGHT: HF Agile Device Co., Ltd., 2024 +// +// LICENSE: This file is distributed under the LGPL license. +// License text is included with the source distribution. + +#pragma once + +#include "DeviceBase.h" +#include "ImgBuffer.h" +#include "DeviceThreads.h" +#include "SCApi.h" +#include +#include +#include + +enum ReadoutMode { + bit11_HS_Low = 0, + bit11_HS_High, + bit11_HDR_Low, + bit11_HDR_High, + bit12_HDR_Low, + bit12_HDR_High, + bit12_CMS, + bit16_From11, + bit16_From12 +}; + +class SCCamera : public CCameraBase +{ +public: + SCCamera(); + ~SCCamera(); + + // MMDevice API + // ------------ + int Initialize(); + int Shutdown(); + + void GetName(char* name) const; + + // MMCamera API + // ------------ + int SnapImage(); + const unsigned char* GetImageBuffer(); + unsigned GetImageWidth() const; + unsigned GetImageHeight() const ; + unsigned GetImageBytesPerPixel() const; + unsigned GetBitDepth() const; + long GetImageBufferSize() const; + double GetExposure() const; + void SetExposure(double exp); + int SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) ; + int GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize); + int ClearROI(); + virtual int GetProperty(const char* name, char* value) const; + virtual int SetProperty(const char* name, const char* value); + + int PrepareSequenceAcqusition() { return DEVICE_OK; } + int StartSequenceAcquisition(double interval); + int StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow); + int StopSequenceAcquisition(); + int InsertImage(); + int RunSequenceOnThread(MM::MMTime startTime); + bool IsCapturing(); + void OnThreadExiting() throw(); + double GetNominalPixelSizeUm() const; + double GetPixelSizeUm() const; + int GetBinning() const; + int SetBinning(int bS); + + int IsExposureSequenceable(bool& isSequenceable) const; + int GetExposureSequenceMaxLength(long& length) const; + int StartExposureSequence(); + int StopExposureSequence(); + int ClearExposureSequence(); + int AddToExposureSequence(double exposureTime_ms); + int SendExposureSequence() const; + + //double LineIntervalTime(int nLineDelayTm); + //int LineIntervalCal(int nVal, bool bExpChange = true); + + unsigned GetNumberOfComponents() const; + //bool Busy() { return true; } + virtual int ThreadRun(void); + + + // action interface + // ---------------- + // floating point read-only properties for testing + int OnTestProperty(MM::PropertyBase* pProp, MM::ActionType eAct, long){ return 0; }; + + int OnBinning(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnBinningSum(MM::PropertyBase* pProp, MM::ActionType eAct){ return 0; }; + int OnExposure(MM::PropertyBase* pProp, MM::ActionType eAct){ return 0; }; + int OnFrameRate(MM::PropertyBase* pProp, MM::ActionType eAct){ return 0; }; + int OnImageMode(MM::PropertyBase* pProp, MM::ActionType eAct){ return 0; }; + int OnPixelType(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnIsSequenceable(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnReadOutMode(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnTriggerIn(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnTriggerSelector(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnTriggerOut(MM::PropertyBase* pProp, MM::ActionType eAct); + + MM::MMTime GetCurrentMMTime() + { + return CCameraBase::GetCurrentMMTime(); + }; + +private: + static const double nominalPixelSizeUm_; + int32_t insertCount_ = 0; + + bool initialized_ = false; + SC_DEV_HANDLE devHandle_ = nullptr; + bool isAcqusition_ = false; + + unsigned xoffset_ = 0; + unsigned yoffset_ = 0; + unsigned depth_ = 0; + ImgBuffer image_; + uint8_t* rawBuffer_ = nullptr; + SC_Frame *recvImage_ = nullptr; + + friend class CameraRecvThread; + CameraRecvThread* thd_ = nullptr; + MMThreadLock imgPixelsLock_; + bool stopOnOverflow_; + + bool isSequenceable_ = false; + int32_t sequenceMaxLength_ = 100; + bool sequenceRunning_ = false; + int32_t sequenceIndex_ = 0; + std::vector exposureSequence_; + + std::vector triggerOutTypes_; + std::vector triggerActivations_; + std::vector readOutModes_; + +private: + int ResizeImageBuffer( + int imageSizeW, + int imageSizeH, + int byteDepth, + int binSize = 1); + + void getActualRoi( + unsigned& actualX, + unsigned& actualY, + unsigned& actualXSize, + unsigned& actualYSize); + + int getDepth(const char* pixelType, int &dyteDepth); + + // acquisition + int getNextFrame(); + double GetSequenceExposure(); + int convertPixelFormatToDepth(SC_EPixelType pixel); + int convertBinningModeToBinningValue(int binngingMode) const; + int convertBinningValueToBinningMode(int binngingValue) const; + + std::string convertReadOutModeStr(const char* name, uint64_t vv) const; + uint32_t convertReadOutModeEnum(const char* name, const char* vvStr) const; + uint32_t getReadOutModeEnum(const char*vvStr) const; + + std::string convertTriggerTypeToValue(int32_t type); + int32_t convertTriggerValueToType(const char* value); + std::string convertTriggerOutSelectorToVal(int32_t selector); + int32_t convertTriggerOutSeletorToEnum(const char* selector); + int32_t convertTriggerOutTypeToEnum(const char* type); + + + int32_t createTriggerProperty(); + int32_t createTriggerOutProperty(); + //const char* ifname, + //const char* triggerOutTypeName, + //const char* triggerOutActName, + //const char* triggerOutDelayName, + //const char* triggerOutPulseWidthName); + + int32_t updateTriggerInActivation(const char *name, const std::vector &AllowPropertiesValue); +}; + + +class CameraRecvThread : public MMDeviceThreadBase +{ + friend class SCCamera; + enum { default_numImages=1, default_intervalMS = 100 }; +public: + CameraRecvThread(SCCamera* pCam); + + ~CameraRecvThread(); + + void Stop(); + + void Start(long numImages, double intervalMs); + bool IsStopped(); + void Suspend(); + bool IsSuspended(); + void Resume(); + double GetIntervalMs(); + void SetLength(long images); + long GetLength() const; + + long GetImageCounter(); + MM::MMTime GetStartTime(); + MM::MMTime GetActualDuration(); + +private: + int svc(void) throw(); + +protected: + SCCamera* camera_; + bool stop_; + bool suspend_; + long numImages_; + long imageCounter_; + double intervalMs_; + MM::MMTime startTime_; + MM::MMTime actualDuration_; + MM::MMTime lastFrameTime_; + MMThreadLock stopLock_; + MMThreadLock suspendLock_; +}; diff --git a/DeviceAdapters/Revealer/Revealer.vcxproj b/DeviceAdapters/Revealer/Revealer.vcxproj new file mode 100644 index 000000000..348a9ce2d --- /dev/null +++ b/DeviceAdapters/Revealer/Revealer.vcxproj @@ -0,0 +1,105 @@ + + + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + {b8c95f39-54bf-40a9-807b-598df2821d55} + + + + 16.0 + Win32Proj + {F32DD52C-3406-4B8E-BFFC-5E2FB18D652B} + Revealer + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + Level3 + true + _DEBUG;REVEALER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + + + $(MM_3RDPARTYPRIVATE)\Revealer\scsdk-2019;%(AdditionalIncludeDirectories) + + + Windows + true + false + $(MM_3RDPARTYPRIVATE)\Revealer\scsdk-2019 + scsdk.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;REVEALER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + NotUsing + pch.h + $(MM_3RDPARTYPRIVATE)\Revealer\scsdk-2019;%(AdditionalIncludeDirectories) + + + Windows + true + true + true + false + $(MM_3RDPARTYPRIVATE)\Revealer\scsdk-2019 + scsdk.lib;%(AdditionalDependencies) + + + + + + \ No newline at end of file diff --git a/DeviceAdapters/Revealer/Revealer.vcxproj.filters b/DeviceAdapters/Revealer/Revealer.vcxproj.filters new file mode 100644 index 000000000..fd9f3c9b5 --- /dev/null +++ b/DeviceAdapters/Revealer/Revealer.vcxproj.filters @@ -0,0 +1,23 @@ + + + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/micromanager.sln b/micromanager.sln index a8a6e7269..30b31af84 100644 --- a/micromanager.sln +++ b/micromanager.sln @@ -512,6 +512,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AMF", "DeviceAdapters\AMF\A EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mightex_SB_Cam", "DeviceAdapters\Mightex_SB_Cam\Mightex_SB_Cam.vcxproj", "{D0E08CDB-A197-4451-938F-4AD30D7097CC}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Revealer", "DeviceAdapters\Revealer\Revealer.vcxproj", "{F32DD52C-3406-4B8E-BFFC-5E2FB18D652B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -1538,6 +1540,10 @@ Global {D0E08CDB-A197-4451-938F-4AD30D7097CC}.Debug|x64.Build.0 = Debug|x64 {D0E08CDB-A197-4451-938F-4AD30D7097CC}.Release|x64.ActiveCfg = Release|x64 {D0E08CDB-A197-4451-938F-4AD30D7097CC}.Release|x64.Build.0 = Release|x64 + {F32DD52C-3406-4B8E-BFFC-5E2FB18D652B}.Debug|x64.ActiveCfg = Debug|x64 + {F32DD52C-3406-4B8E-BFFC-5E2FB18D652B}.Debug|x64.Build.0 = Debug|x64 + {F32DD52C-3406-4B8E-BFFC-5E2FB18D652B}.Release|x64.ActiveCfg = Release|x64 + {F32DD52C-3406-4B8E-BFFC-5E2FB18D652B}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE