From 4fb3deb2118cd0a34796814bef0675c05d86dbd8 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Mon, 25 Sep 2023 15:28:27 -0500 Subject: [PATCH 1/4] OxxiusCombiner: Update by Tristan Martinez, Oxxius Replace all .h and .cpp with new files from Tristan. Update .vcxproj and Makefile.am accordingly. Add previously missing .vcxproj.filters. --- DeviceAdapters/OxxiusCombiner/Cobolt08_01.cpp | 169 ++ DeviceAdapters/OxxiusCombiner/Cobolt08_01.h | 41 + .../OxxiusCombiner/CoherentObis.cpp | 345 +++ DeviceAdapters/OxxiusCombiner/CoherentObis.h | 39 + .../OxxiusCombiner/GenericLaser.cpp | 104 + DeviceAdapters/OxxiusCombiner/GenericLaser.h | 43 + DeviceAdapters/OxxiusCombiner/Makefile.am | 12 +- DeviceAdapters/OxxiusCombiner/OnBoardHW.cpp | 125 -- DeviceAdapters/OxxiusCombiner/OnBoardHW.h | 67 - .../OxxiusCombiner/OxxiusCombiner.vcxproj | 32 +- .../OxxiusCombiner.vcxproj.filters | 69 + .../OxxiusCombiner/OxxiusCombinerHub.cpp | 778 +++++++ .../OxxiusCombiner/OxxiusCombinerHub.h | 143 ++ .../OxxiusCombiner/OxxiusFlipMirror.cpp | 128 ++ .../OxxiusCombiner/OxxiusFlipMirror.h | 41 + DeviceAdapters/OxxiusCombiner/OxxiusLBX.cpp | 545 +++++ DeviceAdapters/OxxiusCombiner/OxxiusLBX.h | 46 + DeviceAdapters/OxxiusCombiner/OxxiusLCX.cpp | 575 +++++ DeviceAdapters/OxxiusCombiner/OxxiusLCX.h | 47 + DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp | 170 ++ DeviceAdapters/OxxiusCombiner/OxxiusMDual.h | 37 + .../OxxiusCombiner/OxxiusShutter.cpp | 148 ++ DeviceAdapters/OxxiusCombiner/OxxiusShutter.h | 50 + .../OxxiusCombiner/Oxxius_combiner.cpp | 1920 ----------------- .../OxxiusCombiner/Oxxius_combiner.h | 349 --- 25 files changed, 3550 insertions(+), 2473 deletions(-) create mode 100644 DeviceAdapters/OxxiusCombiner/Cobolt08_01.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/Cobolt08_01.h create mode 100644 DeviceAdapters/OxxiusCombiner/CoherentObis.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/CoherentObis.h create mode 100644 DeviceAdapters/OxxiusCombiner/GenericLaser.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/GenericLaser.h delete mode 100644 DeviceAdapters/OxxiusCombiner/OnBoardHW.cpp delete mode 100644 DeviceAdapters/OxxiusCombiner/OnBoardHW.h create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj.filters create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusLBX.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusLBX.h create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusLCX.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusLCX.h create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusMDual.h create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp create mode 100644 DeviceAdapters/OxxiusCombiner/OxxiusShutter.h delete mode 100644 DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp delete mode 100644 DeviceAdapters/OxxiusCombiner/Oxxius_combiner.h diff --git a/DeviceAdapters/OxxiusCombiner/Cobolt08_01.cpp b/DeviceAdapters/OxxiusCombiner/Cobolt08_01.cpp new file mode 100644 index 000000000..a49336791 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/Cobolt08_01.cpp @@ -0,0 +1,169 @@ +#include "Cobolt08_01.h" +using namespace std; + +Cobolt08_01::Cobolt08_01(const char* nameAndSlot) : initialized_(false) +{ + string tSlot = string(nameAndSlot); + + name_.assign(tSlot);// set laser name + tSlot = tSlot.substr(tSlot.length() - 1, 1); + slot_ = (unsigned int)atoi(tSlot.c_str());// set laser slot + + parentHub_; + busy_ = false; + laserOn_ = false; + + alarm_ = ""; + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); + + // parent ID display + CreateHubIDProperty(); +} + + +Cobolt08_01::~Cobolt08_01() +{ + Shutdown(); +} + + + +int Cobolt08_01::Initialize() +{ + + if (!initialized_) { + + parentHub_ = static_cast(GetParentHub()); + if (!parentHub_) { + return DEVICE_COMM_HUB_MISSING; + } + + + + RETURN_ON_MM_ERROR(UpdateStatus()); + + initialized_ = true; + + } + + return DEVICE_OK; + +} + + +int Cobolt08_01::Shutdown() +{ + initialized_ = false; + return DEVICE_OK; +} + + + + +int Cobolt08_01::Fire(double deltaT) +{ + string activate_query = "dl 1"; //SOUR1:AM:STAT ON + string deactivate_query = "dl 0"; + + if (laserOn_ == false) { + laserOn_ = true; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, activate_query.c_str(), false)); + } + CDeviceUtils::SleepMs((long)(deltaT)); + laserOn_ = false; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, deactivate_query.c_str(), false)); + //At the end, the laser is set to off + + return DEVICE_OK; +} + +//Handlers + +int Cobolt08_01::OnAlarm(MM::PropertyBase* pProp, MM::ActionType) +{ + unsigned int alarmInt = 99; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?F", false)); + + parentHub_->ParseforInteger(alarmInt); + + switch (alarmInt) { + case 0: + alarm_ = "No Alarm"; + break; + case 1: + alarm_ = "Out-of-bounds diode current"; + break; + case 2: + alarm_ = "Unexpected laser power value"; + break; + case 3: + alarm_ = "Out-of-bounds supply voltage"; + break; + case 4: + alarm_ = "Out-of-bounds internal temperature"; + break; + case 5: + alarm_ = "Out-of-bounds baseplate temperature"; + break; + case 7: + alarm_ = "Interlock circuit open"; + break; + case 8: + alarm_ = "Soft reset"; + break; + default: + alarm_ = "Other alarm"; + } + + pProp->Set(alarm_.c_str()); + + return DEVICE_OK; +} + + +int Cobolt08_01::OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + double status; + ostringstream query; + + query << "?l"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, query.str().c_str(), false)); + parentHub_->ParseforDouble(status); + + if (status == 1) { + laserOn_ = true; + } + else { + laserOn_ = false; + } + + if (laserOn_) { + pProp->Set("ON"); + } + else { + pProp->Set("OFF"); + } + } + else if (eAct == MM::AfterSet) { + string newEmissionStatus, newCommand = ""; + + pProp->Get(newEmissionStatus); + + if (newEmissionStatus.compare("ON") == 0) { + newCommand = "dl 1"; //original: SOUR1:AM:STAT ON + laserOn_ = true; + } + else if (newEmissionStatus.compare("OFF") == 0) { + newCommand = "dl 0"; + laserOn_ = false; + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false)); + } + + return DEVICE_OK; +} diff --git a/DeviceAdapters/OxxiusCombiner/Cobolt08_01.h b/DeviceAdapters/OxxiusCombiner/Cobolt08_01.h new file mode 100644 index 000000000..a2001d803 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/Cobolt08_01.h @@ -0,0 +1,41 @@ +#pragma once +#include "GenericLaser.h" +using namespace std; + +class Cobolt08_01 : public GenericLaser +{ +public: + Cobolt08_01(const char* nameAndSlot); //OK + ~Cobolt08_01(); //OK + + int Initialize(); //OK + int Shutdown(); //OK + + int Fire(double deltaT); //OK + + int OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnState(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnAlarm(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnFire(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + + int OnPowerReadback(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnCurrentReadback(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnOperatingMode(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + +private: + bool initialized_; + + //// SPECIFIC TO Cobolt08_01 + bool laserOn_; + //double maxPower_; + //double minPower_; + string alarm_; + //double wavelength_; + //string description_; + +}; \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/CoherentObis.cpp b/DeviceAdapters/OxxiusCombiner/CoherentObis.cpp new file mode 100644 index 000000000..c17e358fb --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/CoherentObis.cpp @@ -0,0 +1,345 @@ +#include "CoherentObis.h" +using namespace std; + +CoherentObis::CoherentObis(const char* nameAndSlot) +{ + initialized_ = false; + + string tSlot = string(nameAndSlot); + + name_.assign(tSlot);// set laser name + tSlot = tSlot.substr(tSlot.length() - 1, 1); + slot_ = (unsigned int)atoi(tSlot.c_str());// set laser slot + + parentHub_; + busy_ = false; + laserOn_ = false; + + alarm_ = ""; + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); + + // parent ID display + CreateHubIDProperty(); +} + + +CoherentObis::~CoherentObis() +{ + Shutdown(); +} + + +int CoherentObis::Initialize() +{ + + if (!initialized_) { + + parentHub_ = static_cast(GetParentHub()); + if (!parentHub_) { + return DEVICE_COMM_HUB_MISSING; + } + + string cmdmaxpwr = "SOUR1:POW:LIM:HIGH?"; + string cmdminpwr = "SOUR1:POW:LIM:LOW?"; + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, cmdmaxpwr.c_str(), true); + parentHub_->ParseforDouble(maxPower_); + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, cmdminpwr.c_str(), true); + parentHub_->ParseforDouble(minPower_); + + + + // Set property list + // ----------------- + // Name (read only) + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true)); + + // store the device serial number + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "SYST:INF:SNUM?", false); + parentHub_->ParseforString(serialNumber_); + + // Description (read only) + ostringstream descriPt1; + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "*IDN?", false); + parentHub_->ParseforString(description_); //example: "Coherent, Inc - OBIS 405nm 50mW C - V1.0.1 - Dec 14 2010" + + //we ignore "spa" + + //define the laser's wavelength + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "SYST1:INF:WAV?", false); + parentHub_->ParseforDouble(wavelength_); + + //let's skip the nominal power retrieve + + //let's assume there are no MPA or AOMs + + std::ostringstream InfoMessage1; // Debug purposes only + InfoMessage1 << "INFOS RECUPEREES: maxpower:"<LogMessage(this, InfoMessage1.str().c_str(), false); + + descriPt1 << "OBIS source on slot " << slot_; + descriPt1 << ", " << string(serialNumber_); + + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Description, descriPt1.str().c_str(), MM::String, true)); + + // Alarm (read only) + CPropertyAction* pAct = new CPropertyAction(this, &GenericLaser::OnAlarm); + RETURN_ON_MM_ERROR(CreateProperty("Alarm", "None", MM::String, true, pAct)); + //No status + //No Control mode + + + + //Emission selector + pAct = new CPropertyAction(this, &GenericLaser::OnEmissionOnOff); + RETURN_ON_MM_ERROR(CreateProperty("Emission", "", MM::String, false, pAct)); + AddAllowedValue("Emission", "ON"); + AddAllowedValue("Emission", "OFF"); + + //No Current set point ? + maxPower_ = 100.0; + + //Set Power + pAct = new CPropertyAction(this, &GenericLaser::OnPowerSetPoint); + RETURN_ON_MM_ERROR(CreateProperty("Power set point", "0.0", MM::Float, false, pAct)); + SetPropertyLimits("Power set point", 0.0, maxPower_); + + //Read Power + pAct = new CPropertyAction(this, &GenericLaser::OnPowerReadback); + RETURN_ON_MM_ERROR(CreateProperty("Read Power point", "0.0", MM::Float, false, pAct)); + + + //Read Current + pAct = new CPropertyAction(this, &GenericLaser::OnCurrentReadback); + RETURN_ON_MM_ERROR(CreateProperty("Read Current point", "0.0", MM::Float, false, pAct)); + + //Fire + pAct = new CPropertyAction(this, &GenericLaser::OnFire); + RETURN_ON_MM_ERROR(CreateProperty("Fire", "0", MM::Float, false, pAct)); + + //Modes + pAct = new CPropertyAction(this, &GenericLaser::OnOperatingMode); + RETURN_ON_MM_ERROR(CreateProperty("Mode", "", MM::String, false, pAct)); + + + RETURN_ON_MM_ERROR(UpdateStatus()); + + initialized_ = true; + + } + + return DEVICE_OK; + +} + + +int CoherentObis::Fire(double deltaT) +{ + string activate_query = "dl 1"; //SOUR1:AM:STAT ON + string deactivate_query = "dl 0"; + + if (laserOn_ == false) { + laserOn_ = true; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, activate_query.c_str(), false)); + } + CDeviceUtils::SleepMs((long)(deltaT)); + laserOn_ = false; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, deactivate_query.c_str(), false)); + //At the end, the laser is set to off + + return DEVICE_OK; +} + +//Handlers + +int CoherentObis::OnAlarm(MM::PropertyBase* pProp, MM::ActionType) +{ + unsigned int alarmInt = 99; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?F", false)); + + parentHub_->ParseforInteger(alarmInt); + + switch (alarmInt) { + case 0: + alarm_ = "No Alarm"; + break; + case 1: + alarm_ = "Out-of-bounds diode current"; + break; + case 2: + alarm_ = "Unexpected laser power value"; + break; + case 3: + alarm_ = "Out-of-bounds supply voltage"; + break; + case 4: + alarm_ = "Out-of-bounds internal temperature"; + break; + case 5: + alarm_ = "Out-of-bounds baseplate temperature"; + break; + case 7: + alarm_ = "Interlock circuit open"; + break; + case 8: + alarm_ = "Soft reset"; + break; + default: + alarm_ = "Other alarm"; + } + + pProp->Set(alarm_.c_str()); + + return DEVICE_OK; +} + + +int CoherentObis::OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + double status; + ostringstream query; + + query << "?l"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, query.str().c_str(), false)); + parentHub_->ParseforDouble(status); + + if (status == 1) { + laserOn_ = true; + } + else { + laserOn_ = false; + } + + if (laserOn_) { + pProp->Set("ON"); + } + else { + pProp->Set("OFF"); + } + } + else if (eAct == MM::AfterSet) { + string newEmissionStatus, newCommand = ""; + + pProp->Get(newEmissionStatus); + + if (newEmissionStatus.compare("ON") == 0) { + newCommand = "dl 1"; //original: SOUR1:AM:STAT ON + laserOn_ = true; + } + else if (newEmissionStatus.compare("OFF") == 0) { + newCommand = "dl 0"; + laserOn_ = false; + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false)); + } + + return DEVICE_OK; +} + +/* +int CoherentObis::OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + float absSetPoint_; + string command = "SOUR1:POW:LEV:IMM:AMPL?"; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + parentHub_->ParseforFloat(absSetPoint_); + + pProp->Set(absSetPoint_); + } + else if (eAct == MM::AfterSet) { + double GUISetPoint = 0.0; + pProp->Get(GUISetPoint); + + if ((GUISetPoint >= 0.0) && (GUISetPoint <= maxPower_)) { //&& instead of || + string command = "SOUR1:POW:LEV:IMM:AMPL "; + command += to_string(GUISetPoint); + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + + } + else { + // If the value entered through the GUI is not valid, read the machine value + OnPowerSetPoint(pProp, MM::BeforeGet); + } + } + return DEVICE_OK; +} +*/ + +int CoherentObis::OnPowerReadback(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) + { + string command = "SOUR1:POW:LEV:IMM:AMPL?"; + float power; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + parentHub_->ParseforFloat(power); + pProp->Set(power); + } + return DEVICE_OK; +} + +int CoherentObis::OnCurrentReadback(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) + { + string command = "SOUR1:POW:CURR?"; + float current; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + parentHub_->ParseforFloat(current); + pProp->Set(current); + } + return DEVICE_OK; +} + +int CoherentObis::OnOperatingMode(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if(eAct==MM::BeforeGet) + { + string command = "SOUR:AM:SOUR?"; + string operating_mode; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + parentHub_->ParseforString(operating_mode); + pProp->Set(operating_mode.c_str()); + } + else if (eAct == MM::AfterSet) { + string input = ""; + string command; + pProp->Get(input); + if (input == "CWP" || input == "CWC") { + command = "SOUR:AM:INT "; + } + else if (input == "DIG" || input == "ANAL" || input == "MIX" || input == "DIGITAL" || input == "ANALOG" || input == "MIXED" || input == "DIGSO" || input == "MIXSO") { + command = "SOUR:AM:EXT "; + } + command += input; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + string rep; + parentHub_->ParseforString(rep); + + + std::ostringstream Info; /////DEBUG + Info << "DEBUG OPERATING MODE: " << rep << "avec la commande encoyée suivante: " << command; + GetCoreCallback()->LogMessage(this, Info.str().c_str(), false); + + } + + return DEVICE_OK; + +} +/* +int CoherentObis::OnFire(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::AfterSet) { + double input; + pProp->Get(input); + return Fire(input); + } + return DEVICE_OK; +} +*/ \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/CoherentObis.h b/DeviceAdapters/OxxiusCombiner/CoherentObis.h new file mode 100644 index 000000000..ca9c1f5e4 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/CoherentObis.h @@ -0,0 +1,39 @@ +#pragma once +#include "GenericLaser.h" +using namespace std; + +class CoherentObis : public GenericLaser +{ +public: + CoherentObis(const char* nameAndSlot); //OK + ~CoherentObis(); //OK + + int Initialize(); //OK + + int Fire(double deltaT); + + // int OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnState(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; };//Aucun pour l'instant + int OnAlarm(MM::PropertyBase* pProp, MM::ActionType eAct); + // int OnFire(MM::PropertyBase* pProp, MM::ActionType eAct); + + int OnPowerReadback(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnCurrentReadback(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnOperatingMode(MM::PropertyBase* pProp, MM::ActionType eAct); + +private: + bool initialized_; + + //// SPECIFIC TO CoherentObis + double maxPower_; + double minPower_; + string alarm_; + double wavelength_; + string description_; + +}; diff --git a/DeviceAdapters/OxxiusCombiner/GenericLaser.cpp b/DeviceAdapters/OxxiusCombiner/GenericLaser.cpp new file mode 100644 index 000000000..281fabc10 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/GenericLaser.cpp @@ -0,0 +1,104 @@ +#include "GenericLaser.h" + +int GenericLaser::Shutdown() +{ + initialized_ = false; + return DEVICE_OK; +} + +void GenericLaser::GetName(char* Name) const +{ + CDeviceUtils::CopyLimitedString(Name, name_.c_str()); +} + +bool GenericLaser::Busy() +{ + return busy_; +} + +int GenericLaser::SetOpen(bool openCommand) +{ + string activate_query = "DL 1"; + string deactivate_query = "DL 0"; + + if (openCommand == false) { + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, deactivate_query.c_str(), false)); + laserOn_ = false; + } + else { + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, activate_query.c_str(), false)); + laserOn_ = true; + } + return DEVICE_OK; +} + + +int GenericLaser::GetOpen(bool& isOpen) +{ + unsigned int status = 0; + ostringstream query; + + query << "?CS " << slot_; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, query.str().c_str(), false)); + parentHub_->ParseforInteger(status); + + switch (status) { + case 0: // Emission is OFF + laserOn_ = false; + break; + case 1: // Emission is ON + laserOn_ = true; + break; + default: // Other cases: emission is potentially ON + laserOn_ = true; + } + isOpen = laserOn_; + return DEVICE_OK; +} + + + +int GenericLaser::OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + double relSetPoint_ = 0.0; + string powSetPointQuery = "?PPL"; // Generic query to read the power set point (percentage) + ostringstream powSetPointPhrase; + powSetPointPhrase << powSetPointQuery << slot_; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, powSetPointPhrase.str().c_str(), false)); + parentHub_->ParseforPercent(relSetPoint_); + + pProp->Set(relSetPoint_); + } + else if (eAct == MM::AfterSet) { + + double GUISetPoint = 0.0; + pProp->Get(GUISetPoint); + + if ((GUISetPoint >= 0.0) || (GUISetPoint <= POW_UPPER_LIMIT)) { + string powSetPointCommand = "PPL"; // Generic query to set the laser power (percentage) + + ostringstream powSetPointPhrase; + char* powerSPString = new char[20]; + strcpy( powerSPString, CDeviceUtils::ConvertToString(GUISetPoint) ); + + powSetPointPhrase << powSetPointCommand << slot_ << " " << powerSPString; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, powSetPointPhrase.str().c_str(), false)); + } + else {} // Do nothing if the GUI set point is out-of-bounds + + } + return DEVICE_OK; +} + + +int GenericLaser::OnFire(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::AfterSet) { + double input; + pProp->Get(input); + return Fire(input); + } + return DEVICE_OK; +} \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/GenericLaser.h b/DeviceAdapters/OxxiusCombiner/GenericLaser.h new file mode 100644 index 000000000..2a6d9e3d3 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/GenericLaser.h @@ -0,0 +1,43 @@ +#pragma once +#include "OxxiusCombinerHub.h" +using namespace std; + +#define POW_UPPER_LIMIT 100.0 + +class GenericLaser : public CShutterBase +{ +public: + virtual int Initialize()=0; + int Shutdown(); + + virtual void GetName(char* pszName) const; + virtual bool Busy(); + virtual int SetOpen(bool openCommand = true); + virtual int GetOpen(bool& isOpen); + virtual int Fire(double deltaT) = 0; + + int OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct); + virtual int OnCurrentSetPoint(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnEmissionOnOff(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnControlMode(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnAnalogMod(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnDigitalMod(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnState(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnAlarm(MM::PropertyBase* , MM::ActionType ) = 0; + int OnFire(MM::PropertyBase* , MM::ActionType ); + + virtual int OnPowerReadback(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnCurrentReadback(MM::PropertyBase* , MM::ActionType ) = 0; + virtual int OnOperatingMode(MM::PropertyBase* , MM::ActionType ) = 0; + +protected: // Common data to all lasers + string serialNumber_; + string name_; + unsigned int slot_; + OxxiusCombinerHub* parentHub_; + bool busy_; + bool laserOn_; + +private: + bool initialized_; +}; \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/Makefile.am b/DeviceAdapters/OxxiusCombiner/Makefile.am index e0d93215d..0c642455c 100644 --- a/DeviceAdapters/OxxiusCombiner/Makefile.am +++ b/DeviceAdapters/OxxiusCombiner/Makefile.am @@ -1,6 +1,16 @@ AM_CXXFLAGS = $(MMDEVAPI_CXXFLAGS) deviceadapter_LTLIBRARIES = libmmgr_dal_OxxiusCombiner.la -libmmgr_dal_OxxiusCombiner_la_SOURCES = OnBoardHW.cpp OnBoardHW.h Oxxius_combiner.cpp Oxxius_combiner.h +libmmgr_dal_OxxiusCombiner_la_SOURCES = \ + Cobolt08_01.cpp \ + CoherentObis.cpp \ + GenericLaser.cpp \ + OxxiusCombinerHub.cpp \ + OxxiusFlipMirror.cpp \ + OxxiusLBX.cpp \ + OxxiusLCX.cpp \ + OxxiusMDual.cpp \ + OxxiusShutter.cpp + libmmgr_dal_OxxiusCombiner_la_LIBADD = $(MMDEVAPI_LIBADD) libmmgr_dal_OxxiusCombiner_la_LDFLAGS = $(MMDEVAPI_LDFLAGS) diff --git a/DeviceAdapters/OxxiusCombiner/OnBoardHW.cpp b/DeviceAdapters/OxxiusCombiner/OnBoardHW.cpp deleted file mode 100644 index 88596fe6e..000000000 --- a/DeviceAdapters/OxxiusCombiner/OnBoardHW.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// FILE: OnBoardHW.cpp -// PROJECT: Micro-Manager -// SUBSYSTEM: DeviceAdapters -//----------------------------------------------------------------------------- -// DESCRIPTION: Describes the contents of the devices (lasers, modulators) -// operating inside a combiner -// COPYRIGHT: Oxxius SA, 2013-2018 -// LICENSE: LGPL -// AUTHOR: Tristan Martinez -// - -#include "OnBoardHW.h" -#include -#include - -using namespace std; - -OnBoardHW::OnBoardHW(unsigned int numberOfSlots) { - AOM1Position_ = 0; - AOM2Position_ = 0; - - if (numberOfSlots <= MAX_NUMBER_OF_SLOTS) { - slotMax_ = numberOfSlots; - } else { - slotMax_ = MAX_NUMBER_OF_SLOTS; - } - - for(unsigned int i = 0; i 0) & (slot <= MAX_NUMBER_OF_SLOTS) ) { - std::string modelStr = "", - wavelengthStr = "", - nominalPowerStr = "", - newSourceDescription = string(newSourceType), - token = "-"; - std::size_t found; - - found = newSourceDescription.find(token); - if (found!=std::string::npos) { - modelStr = newSourceDescription.substr(0, found); - } - - if (modelStr.compare("LBX") == 0) { // The source is a LBX - sourceType_[slot-1] = 10; - } else if (modelStr.compare("LCX") == 0) { // The source is a LCX - if( slot == AOM1Position_ ) { - sourceType_[slot-1] = 21; - } else if( slot == AOM2Position_ ) { - sourceType_[slot-1] = 22; - } else { - sourceType_[slot-1] = 20; - } - } else { // Should not happen: unkown type - sourceType_[slot-1] = 99; - } - - newSourceDescription.erase(0, found+1); - - found = newSourceDescription.find(token); - if (found!=std::string::npos) { - wavelengthStr = newSourceDescription.substr(0, found); - sourceWavelength_[slot-1] = (unsigned int) atoi(wavelengthStr.c_str()); - } - newSourceDescription.erase(0, found+1); - - nominalPowerStr.assign(newSourceDescription); - sourceNominalPower_[slot-1] = (unsigned int) atoi(nominalPowerStr.c_str()); - } -} - - -void OnBoardHW::GetSerialNumber(unsigned int slot, char * serialN) { - strcpy(serialN, sourceSerialNumber_[slot-1].c_str()); -} - - -void OnBoardHW::SetSerialNumber(unsigned int slot, const char* newSerialN) { - if(sourceType_[slot-1] != 0) { - sourceSerialNumber_[slot-1].assign(newSerialN); - } -} - - -void OnBoardHW::SetAOMPos(unsigned int AOM1, unsigned int AOM2) { - if (AOM1>0) - AOM1Position_ = AOM1 + 1; - - if (AOM2>0) - AOM2Position_ = AOM2 + 1; -} - - -void OnBoardHW::GetNominalPower(unsigned int slot, unsigned int nomPower) { - if(sourceType_[slot-1] != 0) { - nomPower = sourceNominalPower_[slot-1]; - } -} diff --git a/DeviceAdapters/OxxiusCombiner/OnBoardHW.h b/DeviceAdapters/OxxiusCombiner/OnBoardHW.h deleted file mode 100644 index d969c5a82..000000000 --- a/DeviceAdapters/OxxiusCombiner/OnBoardHW.h +++ /dev/null @@ -1,67 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// FILE: OnBoardHW.h -// PROJECT: Micro-Manager -// SUBSYSTEM: DeviceAdapters -//----------------------------------------------------------------------------- -// DESCRIPTION: Describes the contents of the devices (lasers, modulators) -// operating inside a combiner -// COPYRIGHT: Oxxius SA, 2013-2018 -// LICENSE: LGPL -// AUTHOR: Tristan Martinez -// - - -// Laser sources exists in different models... -// SourceType[] depicts the can take the following values: -// -// -// model[0] model[1] -// (major) (minor) -// 1 0 -> standard LBX -// 2 0 -> standard LCX -// 2 1 -> LCX linked to an AOM number 1 -// 2 2 -> LCX linked to an AOM number 2 -// 2 5 -> LCX with power adjustment - -#ifndef _OXXIUS_ONBOARDHW_H_ -#define _OXXIUS_ONBOARDHW_H_ - -#define MAX_NUMBER_OF_SLOTS 6 -#define MAX_CHARACTERS 256 - -#include -#include - -class OnBoardHW -{ -public: - OnBoardHW(unsigned int numberOfSlots); - ~OnBoardHW(); - - bool IsEmpty(); - - unsigned int GetType(unsigned int slot); - void SetType(unsigned int slot, const char* newSourceType); - - void GetSerialNumber(unsigned int slot, char* serialN); - void SetSerialNumber(unsigned int slot, const char* newSerialN); - - void SetAOMPos(unsigned int AOM1, unsigned int AOM2); - - void GetNominalPower(unsigned int slot, unsigned int nomPower); - -private: - unsigned int sourceType_[MAX_NUMBER_OF_SLOTS]; - unsigned int sourceWavelength_[MAX_NUMBER_OF_SLOTS]; - unsigned int sourceNominalPower_[MAX_NUMBER_OF_SLOTS]; - std::vector sourceSerialNumber_; -// std::array sourceSerialNumber_; -// std::array sourceDescription_; - - unsigned int slotMax_; - unsigned int wavelength_; - unsigned int AOM1Position_; - unsigned int AOM2Position_; -}; - -#endif // _OXXIUS_ONBOARDHW_H_ \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj b/DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj index 7966a9772..1e3a7d3ce 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj +++ b/DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj @@ -91,21 +91,31 @@ - - - - - - - + + {b8c95f39-54bf-40a9-807b-598df2821d55} + - + + + + + + + + + - - {b8c95f39-54bf-40a9-807b-598df2821d55} - + + + + + + + + + diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj.filters b/DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj.filters new file mode 100644 index 000000000..eefe3a775 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusCombiner.vcxproj.filters @@ -0,0 +1,69 @@ + + + + + {15751bdb-12d5-452c-8197-c6762010b6b3} + + + {d5eef910-aac2-4511-8c33-ad79c7499d4d} + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp new file mode 100644 index 000000000..73872ee42 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp @@ -0,0 +1,778 @@ +#include "OxxiusCombinerHub.h" +#include "GenericLaser.h" +#include "OxxiusShutter.h" +#include "OxxiusMDual.h" +#include "OxxiusFlipMirror.h" +#include "OxxiusLBX.h" +#include "OxxiusLCX.h" +#include "CoherentObis.h" +#include "Cobolt08_01.h" +using namespace std; + + +// Oxxius devices +const char* g_OxxiusCombinerDeviceName = "Combiner"; + +const char* g_LCXLaserDeviceName = "LCX laser source"; +const char* g_LCXLaser1DeviceName = "LCX laser source 1"; +const char* g_LCXLaser2DeviceName = "LCX laser source 2"; +const char* g_LCXLaser3DeviceName = "LCX laser source 3"; +const char* g_LCXLaser4DeviceName = "LCX laser source 4"; +const char* g_LCXLaser5DeviceName = "LCX laser source 5"; +const char* g_LCXLaser6DeviceName = "LCX laser source 6"; + +const char* g_LBXLaserDeviceName = "LBX laser source"; +const char* g_LBXLaser1DeviceName = "LBX laser source 1"; +const char* g_LBXLaser2DeviceName = "LBX laser source 2"; +const char* g_LBXLaser3DeviceName = "LBX laser source 3"; +const char* g_LBXLaser4DeviceName = "LBX laser source 4"; +const char* g_LBXLaser5DeviceName = "LBX laser source 5"; +const char* g_LBXLaser6DeviceName = "LBX laser source 6"; + +const char* g_OBISLaserDeviceName = "Obis laser source"; +const char* g_ObisLaser1DeviceName = "Obis laser source 1"; +const char* g_ObisLaser2DeviceName = "Obis laser source 2"; +const char* g_ObisLaser3DeviceName = "Obis laser source 3"; +const char* g_ObisLaser4DeviceName = "Obis laser source 4"; +const char* g_ObisLaser5DeviceName = "Obis laser source 5"; +const char* g_ObisLaser6DeviceName = "Obis laser source 6"; + +const char* g_OxxiusShutterDeviceName = "Shutter"; +const char* g_OxxiusShutter1DeviceName = "Shutter 1"; +const char* g_OxxiusShutter2DeviceName = "Shutter 2"; +const char* g_OxxiusMDualDeviceName = "MDual"; +const char* g_OxxiusMDualADeviceName = "MDual A"; +const char* g_OxxiusMDualBDeviceName = "MDual B"; +const char* g_OxxiusMDualCDeviceName = "MDual C"; +const char* g_OxxiusFlipMirrorDeviceName = "Flip-Mirror"; +const char* g_OxxiusFlipMirror1DeviceName = "Flip-Mirror 1"; +const char* g_OxxiusFlipMirror2DeviceName = "Flip-Mirror 2"; + + + + +const char* g_slotPrefix[7] = { "","L1 ","L2 ","L3 ","L4 ","L5 ","L6 " }; + +const char* convertable[3] = { "A", "B", "C" }; + +/////////////////////////////////////////////////////////////////////////////// +// Exported MMDevice API +/////////////////////////////////////////////////////////////////////////////// +MODULE_API void InitializeModuleData() +{ + RegisterDevice(g_OxxiusCombinerDeviceName, MM::HubDevice, "Oxxius laser combiner controlled through serial interface"); + + RegisterDevice(g_LCXLaser1DeviceName, MM::ShutterDevice, "LCX Laser on slot 1"); + RegisterDevice(g_LCXLaser2DeviceName, MM::ShutterDevice, "LCX Laser on slot 2"); + RegisterDevice(g_LCXLaser3DeviceName, MM::ShutterDevice, "LCX Laser on slot 3"); + RegisterDevice(g_LCXLaser4DeviceName, MM::ShutterDevice, "LCX Laser on slot 4"); + RegisterDevice(g_LCXLaser5DeviceName, MM::ShutterDevice, "LCX Laser on slot 5"); + RegisterDevice(g_LCXLaser6DeviceName, MM::ShutterDevice, "LCX Laser on slot 6"); + + RegisterDevice(g_LBXLaser1DeviceName, MM::ShutterDevice, "LBX Laser on slot 1"); + RegisterDevice(g_LBXLaser2DeviceName, MM::ShutterDevice, "LBX Laser on slot 2"); + RegisterDevice(g_LBXLaser3DeviceName, MM::ShutterDevice, "LBX Laser on slot 3"); + RegisterDevice(g_LBXLaser4DeviceName, MM::ShutterDevice, "LBX Laser on slot 4"); + RegisterDevice(g_LBXLaser5DeviceName, MM::ShutterDevice, "LBX Laser on slot 5"); + RegisterDevice(g_LBXLaser6DeviceName, MM::ShutterDevice, "LBX Laser on slot 6"); + + RegisterDevice(g_ObisLaser1DeviceName, MM::ShutterDevice, "Obis Laser on slot 1"); + RegisterDevice(g_ObisLaser2DeviceName, MM::ShutterDevice, "Obis Laser on slot 2"); + RegisterDevice(g_ObisLaser3DeviceName, MM::ShutterDevice, "Obis Laser on slot 3"); + RegisterDevice(g_ObisLaser4DeviceName, MM::ShutterDevice, "Obis Laser on slot 4"); + RegisterDevice(g_ObisLaser5DeviceName, MM::ShutterDevice, "Obis Laser on slot 5"); + RegisterDevice(g_ObisLaser6DeviceName, MM::ShutterDevice, "Obis Laser on slot 6"); + + RegisterDevice(g_OxxiusShutter1DeviceName, MM::ShutterDevice, "E-m shutter on channel 1"); + RegisterDevice(g_OxxiusShutter2DeviceName, MM::ShutterDevice, "E-m shutter on channel 2"); + RegisterDevice(g_OxxiusMDualADeviceName, MM::GenericDevice, "M-Dual on channel A"); + RegisterDevice(g_OxxiusMDualBDeviceName, MM::GenericDevice, "M-Dual on channel B"); + RegisterDevice(g_OxxiusMDualCDeviceName, MM::GenericDevice, "M-Dual on channel C"); + RegisterDevice(g_OxxiusFlipMirror1DeviceName, MM::StateDevice, "Flip-Mirror on slot 1"); + RegisterDevice(g_OxxiusFlipMirror2DeviceName, MM::StateDevice, "Flip-Mirror on slot 2"); + +} + +MODULE_API MM::Device* CreateDevice(const char* deviceNameChar) +{ + if (deviceNameChar == 0) + return 0; + + std::string deviceNameAndSlot = string(deviceNameChar); + + if (strcmp(deviceNameChar, g_OxxiusCombinerDeviceName) == 0) { + return new OxxiusCombinerHub(); + } + else if (deviceNameAndSlot.compare(0, strlen(g_LCXLaserDeviceName), g_LCXLaserDeviceName) == 0) { + return new OxxiusLCX(deviceNameChar); + } + else if (deviceNameAndSlot.compare(0, strlen(g_LBXLaserDeviceName), g_LBXLaserDeviceName) == 0) { + return new OxxiusLBX(deviceNameChar); + } + else if (deviceNameAndSlot.compare(0, strlen(g_OxxiusShutterDeviceName), g_OxxiusShutterDeviceName) == 0) { + return new OxxiusShutter(deviceNameChar); + } + else if (deviceNameAndSlot.compare(0, strlen(g_OxxiusMDualDeviceName), g_OxxiusMDualDeviceName) == 0) { + return new OxxiusMDual(deviceNameChar); + } + else if (deviceNameAndSlot.compare(0, strlen(g_OxxiusFlipMirrorDeviceName), g_OxxiusFlipMirrorDeviceName) == 0) { + return new OxxiusFlipMirror(deviceNameChar); + } + else if (deviceNameAndSlot.compare(0, strlen(g_OBISLaserDeviceName), g_OBISLaserDeviceName) == 0) { + return new CoherentObis(deviceNameChar); + } + return 0; +} + +MODULE_API void DeleteDevice(MM::Device* pDevice) +{ + delete pDevice; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Oxxius combiner implementation +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +/////////////////////////////////////////////////////////////////////////////// + + +OxxiusCombinerHub::OxxiusCombinerHub() : initialized_(false) +{ + // Initializing private variables + serialNumber_ = ""; + installedDevices_ = 0; + serialAnswer_ = ""; + interlockClosed_ = false; + keyActivated_ = false; + maxtemperature_ = 20.0; + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_COMBINER_NOT_FOUND, "Hub Device not found. The peer device is expected to be a Oxxius combiner"); + + + // Create pre-initialization properties + // ------------------------------------ + + // Communication port + CPropertyAction* pAct = new CPropertyAction(this, &OxxiusCombinerHub::OnPort); + CreateProperty(MM::g_Keyword_Port, "Undefined", MM::String, false, pAct, true); +} + +OxxiusCombinerHub::~OxxiusCombinerHub() +{ + Shutdown(); +} + +void OxxiusCombinerHub::GetName(char* name) const +{ + CDeviceUtils::CopyLimitedString(name, g_OxxiusCombinerDeviceName); +} + +bool OxxiusCombinerHub::Busy() +{ + return false; + +} + + +int OxxiusCombinerHub::Initialize() +{ + if (!initialized_) { + + // Set proprety list + // - - - - - - - - - + + // Name and description of the combiner: + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Name, g_OxxiusCombinerDeviceName, MM::String, true)); + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Description, "Oxxius L6Cc/L4Cc combiner", MM::String, true)); + + // Serial number of the combiner: + CPropertyAction* pAct = new CPropertyAction(this, &OxxiusCombinerHub::OnSerialNumber); + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_HubID, serialNumber_.c_str(), MM::String, true, pAct)); + + // Interlock circuit: + pAct = new CPropertyAction(this, &OxxiusCombinerHub::OnInterlock); + RETURN_ON_MM_ERROR(CreateProperty("Interlock circuit", "", MM::String, true, pAct)); + + // Emission key: + pAct = new CPropertyAction(this, &OxxiusCombinerHub::OnEmissionKey); + RETURN_ON_MM_ERROR(CreateProperty("EmissionKey", "", MM::String, true, pAct)); + + // Temperature: + pAct = new CPropertyAction(this, &OxxiusCombinerHub::OnTemperature); + RETURN_ON_MM_ERROR(CreateProperty("MaxTemperature", "", MM::Float, true, pAct)); + + + if (!IsCallbackRegistered()) + return DEVICE_NO_CALLBACK_REGISTERED; + + // Enumerates the installed AOMs and their position + bool AOM1en = false, AOM2en = false; + unsigned int ver = 0; + + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "AOM1 EN", false)); + ParseforBoolean(AOM1en); + + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "AOM2 EN", false)); + ParseforBoolean(AOM2en); + + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "SV?", false)); + ParseforVersion(ver); + + // A position equal to "0" stands for an absence of modulator + if (AOM1en) { + bool adcom = false; + string command = ""; + + if (ver < 1016) { //version check + adcom = true; + command = "AOM1 PO"; + } + else { + adcom = false; + command = "AOM1 POS"; + } + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, command.c_str(), adcom)); + ParseforInteger(AOM1pos_); + } + if (AOM2en) { + bool adcom = false; + string command = ""; + + if (ver < 1016) { //version check + adcom = true; + command = "AOM2 PO"; + } + else { + adcom = false; + command = "AOM2 POS"; + } + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, command.c_str(), adcom)); + ParseforInteger(AOM1pos_); + } + + + //Mpa position retreive + for (unsigned int i = 1; i <= MAX_NUMBER_OF_SLOTS; i++) { + string command = "IP"; + std::stringstream ss; + ss << i; + command += ss.str(); + + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, command.c_str(), true)); + if (serialAnswer_ != "????") { + mpa[i] = 1; + } + } + + + + RETURN_ON_MM_ERROR(UpdateStatus()); + + initialized_ = true; + + // RETURN_ON_MM_ERROR( DetectInstalledDevices() ); + } + return DEVICE_OK; +} + + + +int OxxiusCombinerHub::DetectInstalledDevices() +{ + if (initialized_) { + + // Enumerates the lasers (or devices) present on the combiner + unsigned int masque = 1; + unsigned int repartition = 0; + + //sending command ?CL + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "?CL", false)); + ParseforInteger(repartition); + + for (unsigned int querySlot = 1; querySlot <= MAX_NUMBER_OF_SLOTS; querySlot++) { + if ((repartition & masque) != 0) { + string answer; + // A laser source is listed, now querying for detailed information (model, etc) + + std::string detailedInfo, serialNumber; + + //send command to get devices information + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), querySlot, "INF?", false)); + ParseforString(detailedInfo); + + if (detailedInfo != "timeout") { + std::ostringstream nameSlotModel; + + //get the model (LCX or LBX or third-party) + std::string model = detailedInfo.substr(0, 3); + + if (model == "LBX" || model == "LSX") { + nameSlotModel << g_LBXLaserDeviceName << " " << querySlot; + } + else if (model == "LCX" || model == "LPX") { + nameSlotModel << g_LCXLaserDeviceName << " " << querySlot; + } + else if (detailedInfo == "ERR-100") { + //Dans le OBIS + nameSlotModel << g_OBISLaserDeviceName << " " << querySlot; + } + + MM::Device* pDev = ::CreateDevice(nameSlotModel.str().c_str()); + if (pDev) { + AddInstalledDevice(pDev); + installedDevices_++; + } + } + } + masque <<= 1; // Left-shift the bit mask and repeat + } + + // Creating Devices for the two electro-mechanical shutters: + for (unsigned int channel = 1; channel <= 2; channel++) { + std::ostringstream nameModelChannel; + nameModelChannel << g_OxxiusShutterDeviceName << " " << channel; + + MM::Device* pDev = ::CreateDevice(nameModelChannel.str().c_str()); + if (pDev) { + AddInstalledDevice(pDev); + installedDevices_++; + } + } + + // Creating Devices for the "Flip mirror" or MDUAL modules: + /*unsigned int FM1type = 0, FM2type = 0; + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "FM1C", false)); + ParseforInteger(FM1type); + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "FM2C", false)); + ParseforInteger(FM2type);*/ + + + // MDUAL module detection + for (unsigned int j = 0; j <= 2; j++) { + std::string MDSlot; + std::ostringstream com; + com << "IP" << convertable[j]; + + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, com.str().c_str(), true)); + ParseforString(MDSlot); + + com.str(""); + com.clear(); + com << g_OxxiusMDualDeviceName << " " << convertable[j]; + + if (MDSlot != "????") { + MM::Device* pDev = ::CreateDevice(com.str().c_str()); + if (pDev) { + AddInstalledDevice(pDev); + installedDevices_++; + } + + } + + } + + //Flip mirror module creation + + for (unsigned int j = 1; j <= 2; j++) { + unsigned int FMpresence; + std::ostringstream queryPhrase,FMName ; + queryPhrase << "FM" << j << "C"; + + RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, queryPhrase.str().c_str(), false)); + ParseforInteger(FMpresence); + + FMName << g_OxxiusFlipMirrorDeviceName << " " << j; + if ( (FMpresence == 1) || (FMpresence == 2) || (FMpresence == 3) ) { + MM::Device* pDev = ::CreateDevice(FMName.str().c_str()); + if (pDev) { + AddInstalledDevice(pDev); + installedDevices_++; + } + } + } + + } // if (initialized_) + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::Shutdown() +{ + initialized_ = false; + return DEVICE_OK; +} + + +/////////////////////////////////////////////////////////////////////////////// +// Action handlers +/////////////////////////////////////////////////////////////////////////////// + +int OxxiusCombinerHub::OnPort(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) + { + pProp->Set(port_.c_str()); + } + else if (eAct == MM::AfterSet) + { + pProp->Get(port_); + pProp->Set(port_.c_str()); + } + return DEVICE_OK; +} + + +int OxxiusCombinerHub::OnSerialNumber(MM::PropertyBase* pProp, MM::ActionType pAct) +{ + if (pAct == MM::BeforeGet) { + QueryCommand(this, GetCoreCallback(), NO_SLOT, "HID?", false); + ParseforString(serialNumber_); + pProp->Set(serialNumber_.c_str()); + } + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::OnInterlock(MM::PropertyBase* pProp, MM::ActionType pAct) +{ + if (pAct == MM::BeforeGet) { + QueryCommand(this, GetCoreCallback(), NO_SLOT, "INT?", false); + ParseforBoolean(interlockClosed_); + + if (interlockClosed_) { + pProp->Set("Closed"); + } + else { + pProp->Set("Open"); + } + } + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::OnEmissionKey(MM::PropertyBase* pProp, MM::ActionType pAct) +{ + if (pAct == MM::BeforeGet) { + QueryCommand(this, GetCoreCallback(), NO_SLOT, "KEY?", false); + ParseforBoolean(keyActivated_); + + if (keyActivated_) { + pProp->Set("Armed"); + } + else { + pProp->Set("Disarmed"); + } + } + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::OnTemperature(MM::PropertyBase* pProp, MM::ActionType pAct) +{ + if (pAct == MM::BeforeGet) { + // create an array of the temperatures of all the lasers + std::vector temperature_array; + float temp_var; + + for (int i = 1; i <= MAX_NUMBER_OF_SLOTS; i++) { + + if (i != GetObPos()) { + QueryCommand(this, GetCoreCallback(), i, "?BT", false); //for LBX and LCX lasers + ParseforFloat(temp_var); + } + else { + QueryCommand(this, GetCoreCallback(), i, "SOUR:TEMP:BAS?", false); // For OBIS laser + ParseforTemperature(temp_var); + } + temperature_array.push_back(temp_var); + } + + float maxTemp = temperature_array[0]; + for (auto i : temperature_array) { + if (i > maxTemp) { + maxTemp = i; + } + } + maxtemperature_ = maxTemp; + + pProp->Set(static_cast(maxtemperature_)); + + } + return DEVICE_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// Generic methods +/////////////////////////////////////////////////////////////////////////////// + +void OxxiusCombinerHub::LogError(int id, MM::Device* device, MM::Core* core, const char* functionName) //print log messages +{ + std::ostringstream os; + char deviceName[MM::MaxStrLength]; + device->GetName(deviceName); + os << "Error " << id << ", " << deviceName << ", " << functionName << endl; + core->LogMessage(device, os.str().c_str(), false); +} + + +/** + * Sends a serial command to a given slot, then stores the result in the receive buffer. + */ +int OxxiusCombinerHub::QueryCommand(MM::Device* device, MM::Core* core, const unsigned int destinationSlot, const char* command, bool adco) +{ + // First check: if the command string is empty, do nothing and return "DEVICE_OK" + if (strcmp(command, "") == 0) return DEVICE_OK; + + char rcvBuf_[RCV_BUF_LENGTH]; + // Compose the command to be sent to the combiner + std::string strCommand, strHZIn, strHZOut; + strCommand.assign(g_slotPrefix[destinationSlot]); + strCommand.append(command); + strHZIn.assign(g_slotPrefix[destinationSlot]); + strHZIn.append("HZ 9876"); + strHZOut.assign(g_slotPrefix[destinationSlot]); + strHZOut.append("HZ 0"); + + /* + std::ostringstream InfoMessage; + InfoMessage << "Now sending command :"; + InfoMessage << string(strCommand.c_str()); + LogError(DEVICE_OK, device, core, InfoMessage.str().c_str()); + */ + std::ostringstream InfoMessage2; + InfoMessage2 << "Send: " << command << " Received: "; + + // Preambule for specific commands + if (adco) { + int ret = core->SetSerialCommand(device, port_.c_str(), strHZIn.c_str(), "\r\n"); + ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); + if (ret != DEVICE_OK) { + LogError(ret, device, core, "QueryCommand-SetSerialCommand - preambule"); + return ret; + } + } + + // Send command through the serial interface + int ret = core->SetSerialCommand(device, port_.c_str(), strCommand.c_str(), "\r\n"); + if (ret != DEVICE_OK) { + LogError(ret, device, core, "QueryCommand-SetSerialCommand"); + return ret; + } + + // Get a response + ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); + + InfoMessage2 << rcvBuf_; + /* DEBUG ONLY */ + // LogError(DEVICE_OK, device, core, InfoMessage2.str().c_str()); + + if (ret != DEVICE_OK) { + LogError(ret, device, core, "QueryCommand-GetSerialAnswer"); + + // Keep on trying until we either get our answer, or 3 seconds have passed + int maxTimeMs = 3000; + // Wait for a (increasing) delay between each try + int delayMs = 10; + // Keep track of how often we tried + int counter = 1; + bool done = false; + MM::MMTime startTime(core->GetCurrentMMTime()); // Let's keep in mind that MMTime is counted in microseconds + + while (!done) { + counter++; + ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); + if ((ret == DEVICE_OK) || ((core->GetCurrentMMTime() - startTime) > (maxTimeMs * 1000.0))) + done = true; + else { + CDeviceUtils::SleepMs(delayMs); + delayMs *= 2; + } + } + ostringstream os; + if (ret == DEVICE_OK) + os << "QueryCommand-GetSerialAnswer: Succeeded reading from serial port after trying " << counter << "times."; + else + os << "QueryCommand-GetSerialAnswer: Failed reading from serial port after trying " << counter << "times."; + + core->LogMessage(device, os.str().c_str(), true); + + serialAnswer_.assign(rcvBuf_); + return ret; + } + serialAnswer_.assign(rcvBuf_); + ret = core->PurgeSerial(device, port_.c_str()); + + /* if( strcmp(serialAnswer_, "timeout") == 0) { + std::ostringstream syntaxErrorMessage; + syntaxErrorMessage << "Time out received against sent command '"; + syntaxErrorMessage << string(strCommand.c_str()); + syntaxErrorMessage << "'"; + + LogError(DEVICE_SERIAL_TIMEOUT, device, core, syntaxErrorMessage.str().c_str()); + return DEVICE_SERIAL_TIMEOUT; + } + */ + // Epilogue for specific commands + if (adco) { + int retEpi = core->SetSerialCommand(device, port_.c_str(), strHZOut.c_str(), "\r\n"); + retEpi = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); + if (retEpi != DEVICE_OK) { + LogError(retEpi, device, core, "QueryCommand-SetSerialCommand - Epilogue"); + return retEpi; + } + } + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::ParseforBoolean(bool& Bval) +{ + unsigned int intAnswer = (unsigned int)atoi(serialAnswer_.c_str()); + Bval = (intAnswer == 1); + + serialAnswer_.clear(); + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::ParseforFloat(float& Dval) +{ + Dval = (float)atof(serialAnswer_.c_str()); + + serialAnswer_.clear(); + + return DEVICE_OK; +} + +int OxxiusCombinerHub::ParseforDouble(double& Dval) +{ + Dval = (double)atof(serialAnswer_.c_str()); + + serialAnswer_.clear(); + + return DEVICE_OK; +} + + + +int OxxiusCombinerHub::ParseforInteger(unsigned int& Ival) +{ + Ival = (unsigned int)atoi(serialAnswer_.c_str()); + + serialAnswer_.clear(); + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::ParseforString(std::string& Sval) +{ + Sval.assign(serialAnswer_); + + serialAnswer_.clear(); + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::ParseforVersion(unsigned int& Vval) //cast the string into a comparable int +{ + std::string temp1; + std::string temp2(serialAnswer_); + + for (unsigned int i = 0; i <= (temp2.length()) - 1; i++) { + if (temp2.at(i) != '.') { + temp1 += temp2.at(i); + } + } + + stringstream s(temp1); + s >> Vval; + serialAnswer_.clear(); + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::ParseforPercent(double& Pval) //cast the string into a comparable int +{ + std::string percentage; + std::size_t found; + + percentage.assign(serialAnswer_); + + found = percentage.find("%"); + if (found != std::string::npos) { + Pval = atof(percentage.substr(0, found).c_str()); + } + + return DEVICE_OK; +} + + +int OxxiusCombinerHub::ParseforTemperature(float& Tval) // cast a Celsius temperature string into a comparable float +{ + std::string temperature; + std::size_t found; + + temperature.assign(serialAnswer_); + + found = temperature.find("C"); + if (found != std::string::npos) { + Tval = atof(temperature.substr(0, found).c_str()); + } + + return DEVICE_OK; +} + +int OxxiusCombinerHub::ParseforChar(char* Nval) +{ + strcpy(Nval, serialAnswer_.c_str()); + serialAnswer_.clear(); + + return DEVICE_OK; +} + +bool OxxiusCombinerHub::GetAOMpos1(unsigned int slot) +{ + bool res = false; + + if (slot == AOM1pos_) { + res = true; + } + + return res; +} + +bool OxxiusCombinerHub::GetAOMpos2(unsigned int slot) +{ + bool res = false; + + if (slot == AOM2pos_) { + res = true; + } + + return res; +} + +bool OxxiusCombinerHub::GetMPA(unsigned int slot) { + bool res = false; + + if (mpa[slot] == 1) { + res = true; + } + + return res; +} + +int OxxiusCombinerHub::GetObPos() { + return obPos_; +} diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h new file mode 100644 index 000000000..de99211c7 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h @@ -0,0 +1,143 @@ +#pragma once +#include "../../MMDevice/MMDevice.h" +#include "../../MMDevice/DeviceBase.h" +#include "../../MMDevice/ModuleInterface.h" +#include +#include +#include +#include +#include +#include +#include +#include // For system time +#include // For formatting time +#include // For string streams +using namespace std; + +//For Obis +#ifdef WIN32 + #include +#endif +#include "../../MMDevice/DeviceUtils.h" +#include "FixSnprintf.h" +#include +#include +// + +// +class OxxiusLBX; // advance declaration +class OxxiusLCX; // advance declaration +class CoherentObis; //advance declaration +class Cobolt08_01; //advance declaration +class OxxiusShutter; // advance declaration +class OxxiusMDual; // advance declaration +class OxxiusFlipMirror; // advance declaration + +// +#define MAX_NUMBER_OF_SLOTS 6 +#define RCV_BUF_LENGTH 256 +#define NO_SLOT 0 + +////////////////////////////////////////////////////////////////////////////// +// Error codes for LBX and LCX +// +#define ERR_PORT_CHANGE_FORBIDDEN 101 +#define ERR_NO_PORT_SET 102 +#define ERR_COMBINER_NOT_FOUND 201 +#define ERR_UNSUPPORTED_VERSION 202 + +////////////////////////////////////////////////////////////////////////////// +// Error codes for Obis +// +#define OBIS_ERR_PORT_CHANGE_FORBIDDEN 10004 +#define OBIS_ERR_DEVICE_NOT_FOUND 10005 + +#define OBIS_POWERCONVERSION 1000 //convert the power into mW from the W it wants the commands in + +////////////////////////////////////////////////////////////////////////////// +// Miscellaneous definitions +// +// Use the name 'return_value' that is unlikely to appear within 'result'. +#define RETURN_ON_MM_ERROR( result ) do { \ + int return_value = (result); \ + if (return_value != DEVICE_OK) { \ + return return_value; \ + } \ +} while (0) + + + + +////////////////////////////////////////////////////////////////////////////// +// Defining device adaptaters +// + + +class OxxiusCombinerHub : public HubBase +{ +public: + OxxiusCombinerHub(); + ~OxxiusCombinerHub(); + + // MMDevice API + // ------------ + int Initialize(); + int Shutdown(); + + void GetName(char* pszName) const; + bool Busy(); + int DetectInstalledDevices(); + unsigned int GetNumberOfInstalledDevices() { return installedDevices_; }; + // MM::DeviceDetectionStatus DetectDevice(void); + bool SupportsDeviceDetection(void) { return true; }; + + + // Property handlers + int OnPort(MM::PropertyBase* pPropt, MM::ActionType eAct); + int OnSerialNumber(MM::PropertyBase* pPropt, MM::ActionType eAct); + int OnInterlock(MM::PropertyBase* pPropt, MM::ActionType eAct); + int OnEmissionKey(MM::PropertyBase* pPropt, MM::ActionType eAct); + int OnTemperature(MM::PropertyBase* pPropt, MM::ActionType eAct); + + // Custom interface for child devices +// bool IsPortAvailable() {return portAvailable_;} + int QueryCommand(MM::Device* device, MM::Core* core, const unsigned int destinationSlot, const char* command, bool adco); + int ParseforBoolean(bool& destBoolean); + int ParseforFloat(float& destFloat); + int ParseforInteger(unsigned int& destInteger); + int ParseforString(string& destString); + int ParseforVersion(unsigned int& Vval); + int ParseforPercent(double& Pval); + int ParseforTemperature(float& Tval); + int ParseforChar(char* Nval); + + int ParseforDouble(double& destDouble); + // int TempAdminInt(const char* com); + // int TempAdminString(int com, string &res); + + bool GetAOMpos1(unsigned int slot); + bool GetAOMpos2(unsigned int slot); + bool GetMPA(unsigned int slot); + int GetObPos(); + +private: + void LogError(int id, MM::Device* device, MM::Core* core, const char* functionName); + + string port_; + bool initialized_; + unsigned int installedDevices_; + + string type_; + float maxtemperature_; + + string serialAnswer_; + + string serialNumber_; + bool interlockClosed_; + bool keyActivated_; + + unsigned int AOM1pos_; + unsigned int AOM2pos_; + unsigned int mpa[7]; + unsigned int obPos_; +}; diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp new file mode 100644 index 000000000..cddb613e8 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp @@ -0,0 +1,128 @@ +#include "OxxiusFlipMirror.h" + +#include +#include +#include +#include +#include "../../MMDevice/ModuleInterface.h" +using namespace std; + + +/////////////////////////////////////////////////////////////////////////////// +// +// Oxxius Flip-Mirror implementation +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +/////////////////////////////////////////////////////////////////////////////// + +OxxiusFlipMirror::OxxiusFlipMirror(const char* nameAndSlot) : initialized_(false) +{ + parentHub_ = 0; + core_ = GetCoreCallback(); + + std::string fSlot = string(nameAndSlot); + nameF_.assign(fSlot);// set laser name + fSlot = fSlot.substr(fSlot.length() - 1, 1); + slot_ = (unsigned int)atoi(fSlot.c_str());// set laser slot + + numPos_ = 0; + + // Set property list ///////////////////////////////////////////////////////////////////////////////////////////////////// NOT WORKING? (duplicate property name Name(4)) + // ----------------- + // Name (read only) + /*CreateProperty(MM::g_Keyword_Name, nameF_.c_str(), MM::String, true); + + CreateProperty(MM::g_Keyword_Description, "Flip-Mirror module", MM::String, true); + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); + + // parent ID display + CreateHubIDProperty();*/ +} + + +OxxiusFlipMirror::~OxxiusFlipMirror() +{ + Shutdown(); +} + + +int OxxiusFlipMirror::Initialize() +{ + if (!initialized_) { + parentHub_ = static_cast(GetParentHub()); + if (!parentHub_) { + return DEVICE_COMM_HUB_MISSING; + } + char hubLabel[MM::MaxStrLength]; + parentHub_->GetLabel(hubLabel); + SetParentID(hubLabel); // for backward compatibility + + CPropertyAction* pAct = new CPropertyAction(this, &OxxiusFlipMirror::OnSwitchPos);//setting the possible positions + RETURN_ON_MM_ERROR(CreateProperty("Switch Position", "0", MM::Integer, false, pAct)); + SetPropertyLimits("Switch Position", 0, 1); + + std::ostringstream descriPt2; + descriPt2 << ""; + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Description, descriPt2.str().c_str(), MM::String, true)); + + // Gate, or "closed" position +// RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_Closed_Position, "0", MM::String, false) ); + +// isOpen_ = false; // MDual closed posisiton is + + RETURN_ON_MM_ERROR(UpdateStatus()); + + initialized_ = true; + } + + return DEVICE_OK; +} + + +int OxxiusFlipMirror::Shutdown() +{ + initialized_ = false; + return DEVICE_OK; +} + + +void OxxiusFlipMirror::GetName(char* Name) const +{ + CDeviceUtils::CopyLimitedString(Name, nameF_.c_str()); +} + + +bool OxxiusFlipMirror::Busy() +{ + return false; +} + + +int OxxiusFlipMirror::OnSwitchPos(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + unsigned int currentPos = 0; + std::ostringstream command; + command << "FM" << slot_; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, command.str().c_str(), false)); + parentHub_->ParseforInteger(currentPos); + + //SetPosition(currentPos); + pProp->Set((long)currentPos); + } + else if (eAct == MM::AfterSet) { + long newPosition = 0; + + //GetPosition(newPosition); + pProp->Get(newPosition); + + std::ostringstream newCommand; + newCommand << "FM" << slot_ << " " << newPosition; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str(), false)); + } + return DEVICE_OK; +} \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h new file mode 100644 index 000000000..250e5e3fb --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h @@ -0,0 +1,41 @@ +#pragma once + +#include "OxxiusCombinerHub.h" + +#include "../../MMDevice/MMDevice.h" +#include "../../MMDevice/DeviceBase.h" +#include "../../MMDevice/ModuleInterface.h" +#include +#include +#include + +class OxxiusFlipMirror : public CStateDeviceBase +{ +public: + OxxiusFlipMirror(const char* name); + ~OxxiusFlipMirror(); + + // MMDevice API + // ------------ + int Initialize(); + int Shutdown(); + + void GetName(char* pszName) const; + bool Busy(); + unsigned long GetNumberOfPositions() const { return 2; }; + + // Action Interface + // ---------------- + int OnSwitchPos(MM::PropertyBase* pProp, MM::ActionType eAct); + + +private: + bool initialized_; + std::string nameF_; + unsigned int slot_; + MM::Core* core_; + + OxxiusCombinerHub* parentHub_; + + unsigned long numPos_; +}; diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusLBX.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusLBX.cpp new file mode 100644 index 000000000..114d90fe7 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusLBX.cpp @@ -0,0 +1,545 @@ +#include "OxxiusLBX.h" +using namespace std; + +OxxiusLBX::OxxiusLBX(const char* nameAndSlot) : initialized_(false) +{ + string tSlot = string(nameAndSlot); + + name_.assign(tSlot);// set laser name + tSlot = tSlot.substr(tSlot.length() - 1, 1); + slot_ = (unsigned int)atoi(tSlot.c_str());// set laser slot + + parentHub_; + busy_ = false; + laserOn_ = false; + alarm_ = ""; + state_ = ""; + digitalMod_ = ""; + analogMod_ = ""; + controlMode_ = ""; + + //MPA + mpa_number = -1; //probably not needed + + // powerSetPoint_ = 0.0; + maxRelPower_ = 100.0; + nominalPower_ = 100.0; + maxCurrent_ = 125.0; + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); + + // parent ID display + CreateHubIDProperty(); +} + + +OxxiusLBX::~OxxiusLBX() +{ + Shutdown(); +} + + + +int OxxiusLBX::Initialize() +{ + if (!initialized_) { + + size_t found; + string strSlot; + string spa; + + + parentHub_ = static_cast(GetParentHub()); + if (!parentHub_) { + return DEVICE_COMM_HUB_MISSING; + } + char hubLabel[MM::MaxStrLength]; + parentHub_->GetLabel(hubLabel); + SetParentID(hubLabel); // for backward compatibility + + // Set property list + // ----------------- + // Name (read only) + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true)); + + // Description (read only) + ostringstream descriPt1; + char sourceSerialNumber[] = "LAS-XXXXXXXXXX"; + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "HID?", false); + parentHub_->ParseforChar(sourceSerialNumber); + + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "IP", true); + parentHub_->ParseforString(spa); + + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "INF?", false); + parentHub_->ParseforString(strSlot); + + // Retrieves and delete the laser's type + found = strSlot.find("-"); + if (found != string::npos) { + strSlot.erase(0, found + 1); + } + + // Retrieves and define the laser's wavelength + found = strSlot.find("-"); + if (found != string::npos) { + waveLength = (unsigned int)atoi(strSlot.substr(0, found).c_str()); + } + + // Retrieves and define the nominal power + strSlot.erase(0, found + 1); + nominalPower_ = (float)atof(strSlot.substr(0, found).c_str()); + + + if (parentHub_->GetMPA(slot_)) { + mpa_number = slot_; + } + else { + mpa_number = -1; + } + + + // LBX model + descriPt1 << "LBX"; + descriPt1 << " source on slot " << slot_; + descriPt1 << ", " << sourceSerialNumber; + + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Description, descriPt1.str().c_str(), MM::String, true)); + + // Alarm (read only) + CPropertyAction* pAct = new CPropertyAction(this, &GenericLaser::OnAlarm); + RETURN_ON_MM_ERROR(CreateProperty("Alarm", "None", MM::String, true, pAct)); + + // Status (read only) + pAct = new CPropertyAction(this, &GenericLaser::OnState); + RETURN_ON_MM_ERROR(CreateProperty("State", "", MM::String, true, pAct)); + + // Emission selector (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnEmissionOnOff); + RETURN_ON_MM_ERROR(CreateProperty("Emission", "", MM::String, false, pAct)); + AddAllowedValue("Emission", "ON"); + AddAllowedValue("Emission", "OFF"); + + // Digital modulation selector (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnDigitalMod); + RETURN_ON_MM_ERROR(CreateProperty("Digital Modulation", "", MM::String, false, pAct)); + AddAllowedValue("Digital Modulation", "ON"); + AddAllowedValue("Digital Modulation", "OFF"); + + // Analog modulation selector (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnAnalogMod); + RETURN_ON_MM_ERROR(CreateProperty("Analog Modulation", "", MM::String, false, pAct)); + AddAllowedValue("Analog Modulation", "ON"); + AddAllowedValue("Analog Modulation", "OFF"); + + // Control mode selector (= APC or ACC) (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnControlMode); + RETURN_ON_MM_ERROR(CreateProperty("Control mode", "", MM::String, false, pAct)); + AddAllowedValue("Control mode", "ACC"); + AddAllowedValue("Control mode", "APC"); + + //Fire property + pAct = new CPropertyAction(this, &GenericLaser::OnFire); + RETURN_ON_MM_ERROR(CreateProperty("Fire", "0", MM::Float, false, pAct)); + + // Define the maximal current and power + maxRelPower_ = 100.0; + maxCurrent_ = 105.0; + + // Power set point (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnPowerSetPoint); + RETURN_ON_MM_ERROR(CreateProperty("Power set point", "0", MM::Float, false, pAct)); + SetPropertyLimits("Power set point", 0, maxRelPower_); + + // Current set point (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnCurrentSetPoint); + RETURN_ON_MM_ERROR(CreateProperty("Current set point", "0", MM::Float, false, pAct)); + SetPropertyLimits("Current set point", 0, maxCurrent_); + + RETURN_ON_MM_ERROR(UpdateStatus()); + + initialized_ = true; + } + + return DEVICE_OK; +} + + +/* +int OxxiusLBX::Shutdown() +{ + initialized_ = false; + return DEVICE_OK; +} +*/ + + +int OxxiusLBX::Fire(double deltaT) +{ + string activate_query = "DL 1"; + string deactivate_query = "DL 0"; + + if (laserOn_ == false) { + laserOn_ = true; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, activate_query.c_str(), false)); + } + CDeviceUtils::SleepMs((long)(deltaT)); + laserOn_ = false; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, deactivate_query.c_str(), false)); + //At the end, the laser is set to off + + return DEVICE_OK; +} + +//RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false)); + +/////////////////////////////////////////////////////////////////////////////// +// Action handlers +/////////////////////////////////////////////////////////////////////////////// + +int OxxiusLBX::OnAlarm(MM::PropertyBase* pProp, MM::ActionType) +{ + unsigned int alarmInt = 99; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?F", false)); + + parentHub_->ParseforInteger(alarmInt); + + switch (alarmInt) { + case 0: + alarm_ = "No Alarm"; + break; + case 1: + alarm_ = "Out-of-bounds diode current"; + break; + case 2: + alarm_ = "Unexpected laser power value"; + break; + case 3: + alarm_ = "Out-of-bounds supply voltage"; + break; + case 4: + alarm_ = "Out-of-bounds internal temperature"; + break; + case 5: + alarm_ = "Out-of-bounds baseplate temperature"; + break; + case 7: + alarm_ = "Interlock circuit open"; + break; + case 8: + alarm_ = "Soft reset"; + break; + default: + alarm_ = "Other alarm"; + } + + pProp->Set(alarm_.c_str()); + + return DEVICE_OK; +} + + +int OxxiusLBX::OnState(MM::PropertyBase* pProp, MM::ActionType) +{ + unsigned int stateInt = 99; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?STA", false)); + + parentHub_->ParseforInteger(stateInt); + + switch (stateInt) { + case 1: + state_ = "Warm-up phase"; + break; + case 2: + state_ = "Stand-by state"; + break; + case 3: + state_ = "Emission on"; + break; + case 4: + state_ = "Internal error"; + break; + case 5: + state_ = "Alarm"; + break; + case 6: + state_ = "Sleep state"; + break; + default: + state_ = "Other state"; + } + + pProp->Set(alarm_.c_str()); + + return DEVICE_OK; +} + + +int OxxiusLBX::OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + unsigned int status = 0; + ostringstream query; + + query << "?CS " << slot_; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, query.str().c_str(), false)); + parentHub_->ParseforInteger(status); + + switch (status) { + case 0: // LBX model: Emission off + laserOn_ = false; + break; + case 1: // LBX model: Emission on + laserOn_ = true; + break; + default: + laserOn_ = true; + } + + if (laserOn_) { + pProp->Set("ON"); + } + else { + pProp->Set("OFF"); + } + } + else if (eAct == MM::AfterSet) { + string newEmissionStatus, newCommand = ""; + + pProp->Get(newEmissionStatus); + + if (newEmissionStatus.compare("ON") == 0) { + newCommand = "DL 1"; + laserOn_ = true; + } + else if (newEmissionStatus.compare("OFF") == 0) { + newCommand = "DL 0"; + laserOn_ = false; + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false)); + } + return DEVICE_OK; +} + + +int OxxiusLBX::OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + unsigned int querySlot = NO_SLOT; + + if (eAct == MM::BeforeGet) { + string query; + + querySlot = slot_; + query = "?TTL"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, query.c_str(), false)); + + bool digiM; + parentHub_->ParseforBoolean(digiM); + + if (digiM) + digitalMod_.assign("ON"); + else + digitalMod_.assign("OFF"); + + pProp->Set(digitalMod_.c_str()); + + } + else if (eAct == MM::AfterSet) { + string newModSet, newCommand; + + pProp->Get(newModSet); + digitalMod_.assign(newModSet); + + if (digitalMod_ == "ON") { + querySlot = slot_; + newCommand.assign("TTL 1"); + } + + else if (digitalMod_ == "OFF") { + querySlot = slot_; + newCommand.assign("TTL 0"); + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, newCommand.c_str(), false)); + } + return DEVICE_OK; +} + + +int OxxiusLBX::OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + string query; + query = "?AM"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, query.c_str(), false)); + bool digiM; + parentHub_->ParseforBoolean(digiM); + + if (digiM) { + digitalMod_.assign("ON"); + } + else { + digitalMod_.assign("OFF"); + } + pProp->Set(digitalMod_.c_str()); + + } + else if (eAct == MM::AfterSet) { + ostringstream newCommand; + newCommand << "AM "; + + pProp->Get(digitalMod_); + + if (digitalMod_ == "OFF") + newCommand << "0"; + else + newCommand << "1"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.str().c_str(), false)); + } + return DEVICE_OK; +} + + +int OxxiusLBX::OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + unsigned int ctrlM = 1; + string command; + + command = "?APC"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + parentHub_->ParseforInteger(ctrlM); + + if (ctrlM == 1) { + controlMode_.assign("APC"); + } + else if (ctrlM == 0) { + controlMode_.assign("ACC"); + } + + pProp->Set(controlMode_.c_str()); + } + else if (eAct == MM::AfterSet) { + string newCommand; + + pProp->Get(controlMode_); + + if (controlMode_ == "ACC") { + newCommand.assign("APC 0"); + } + else if (controlMode_ == "APC") { + newCommand.assign("APC 1"); + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false)); + } + return DEVICE_OK; +} + +/* +int OxxiusLBX::OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + string command = "?SP"; + unsigned int thisSlot = slot_; + float absSetPoint_; + + + if ((0 < mpa_number) && (mpa_number < 7)) { + thisSlot = NO_SLOT; + command = "?PL"; + stringstream s; + s << mpa_number; + command += s.str(); + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, command.c_str(), false)); + parentHub_->ParseforFloat(absSetPoint_ ); + + pProp->Set(static_cast( absSetPoint_ )); + } + else if (eAct == MM::AfterSet) { + + double GUISetPoint = 0.0; + pProp->Get(GUISetPoint); + + if ((GUISetPoint >= 0.0) || (GUISetPoint <= nominalPower_)) { + string command = "P"; + unsigned int thisSlot = slot_; + + ostringstream newCommand; + char* powerSPString = new char[20]; + strcpy(powerSPString, CDeviceUtils::ConvertToString( static_cast(GUISetPoint) ) ); + + if ((0 < mpa_number) && (mpa_number < 7)) { + thisSlot = NO_SLOT; + command = "IP"; + command += CDeviceUtils::ConvertToString((int)(mpa_number)); + + strcpy(powerSPString, CDeviceUtils::ConvertToString(GUISetPoint)); + } + + newCommand << command << " " << powerSPString; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, newCommand.str().c_str(), false)); + } + else { + // If the value entered through the GUI is not valid, read the machine value + OnPowerSetPoint(pProp, MM::BeforeGet); + } + } + return DEVICE_OK; +} +*/ + + +int OxxiusLBX::OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + float machineSetPoint = 0.0; + string command = "?SC"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); + parentHub_->ParseforFloat(machineSetPoint); + + pProp->Set(machineSetPoint); + } + + else if (eAct == MM::AfterSet) { + + double GUISetPoint = 0.0; + pProp->Get(GUISetPoint); + + if ((GUISetPoint >= 0.0) || (GUISetPoint <= maxCurrent_)) { + + ostringstream newCommand; + string command = "C"; + + char* currentSPString = new char[20]; + strcpy(currentSPString, CDeviceUtils::ConvertToString(GUISetPoint)); + + newCommand << command << " " << currentSPString; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.str().c_str(), false)); + + } + } + return DEVICE_OK; +} + +/* +int OxxiusLBX::OnFire(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::AfterSet) { + double input; + pProp->Get(input); + return Fire(input); + } + return DEVICE_OK; +} +*/ \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusLBX.h b/DeviceAdapters/OxxiusCombiner/OxxiusLBX.h new file mode 100644 index 000000000..e5e3034d3 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusLBX.h @@ -0,0 +1,46 @@ +#pragma once +#include "GenericLaser.h" +using namespace std; + +class OxxiusLBX : public GenericLaser +{ +public: + OxxiusLBX(const char* nameAndSlot); + ~OxxiusLBX(); + + int Initialize() ; + // int Shutdown() ; + + int Fire(double deltaT) ; + + // int OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) ; + int OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) ; + int OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct) ; + int OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct) ; + int OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct) ; + int OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct) ; + int OnState(MM::PropertyBase* pProp, MM::ActionType eAct) ; + int OnAlarm(MM::PropertyBase* pProp, MM::ActionType eAct) ; + // int OnFire(MM::PropertyBase* pProp, MM::ActionType eAct) ; + + int OnPowerReadback(MM::PropertyBase* , MM::ActionType ) { return DEVICE_OK; }; + int OnCurrentReadback(MM::PropertyBase* , MM::ActionType ) { return DEVICE_OK; }; + int OnOperatingMode(MM::PropertyBase* , MM::ActionType ) { return DEVICE_OK; }; + + +private: + bool initialized_; + + //// SPECIFIC TO LBX + float maxRelPower_; + float nominalPower_; + float maxCurrent_; + unsigned int waveLength; + string state_; + string alarm_; + string controlMode_; + string analogMod_; + string digitalMod_; + + int mpa_number; +}; diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusLCX.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusLCX.cpp new file mode 100644 index 000000000..0c2e941bc --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusLCX.cpp @@ -0,0 +1,575 @@ +#include "OxxiusLCX.h" +using namespace std; + +OxxiusLCX::OxxiusLCX(const char* nameAndSlot) +{ + initialized_ = false; + + string tSlot = string(nameAndSlot); + + name_.assign(tSlot);// set laser name + tSlot = tSlot.substr(tSlot.length() - 1, 1); + slot_ = (unsigned int)atoi(tSlot.c_str());// set laser slot + + parentHub_; + busy_ = false; + laserOn_ = false; + alarm_ = ""; + state_ = ""; + digitalMod_ = ""; + analogMod_ = ""; + controlMode_ = ""; + + //Maybe useless + link_AOM1 = false; + link_AOM2 = false; + pow_adj = false; + mpa_number = -1; + + // powerSetPoint_ = 0.0; + maxRelPower_ = 0.0; + nominalPower_ = 0.0; + maxCurrent_ = 125.0; + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); + + // parent ID display + CreateHubIDProperty(); +} + + +OxxiusLCX::~OxxiusLCX() +{ + Shutdown(); +} + + + +int OxxiusLCX::Initialize() +{ + if (!initialized_) { + + size_t found; + string strSlot; + string spa; + + + parentHub_ = static_cast(GetParentHub()); + if (!parentHub_) { + return DEVICE_COMM_HUB_MISSING; + } + char hubLabel[MM::MaxStrLength]; + parentHub_->GetLabel(hubLabel); + SetParentID(hubLabel); // for backward compatibility + + // Set property list + // ----------------- + // Name (read only) + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true)); + + // Description (read only) + ostringstream descriPt1; + char sourceSerialNumber[] = "LAS-XXXXXXXXXX"; + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "HID?", false); + parentHub_->ParseforChar(sourceSerialNumber); + + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "IP", true); + parentHub_->ParseforString(spa); + + parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "INF?", false); + parentHub_->ParseforString(strSlot); + + // Retrieves and delete the laser's type + found = strSlot.find("-"); + if (found != string::npos) { + strSlot.erase(0, found + 1); + } + + // Retrieves and define the laser's wavelength + found = strSlot.find("-"); + if (found != string::npos) { + waveLength = (unsigned int)atoi(strSlot.substr(0, found).c_str()); + } + + // Retrieves and define the nominal power + strSlot.erase(0, found + 1); + nominalPower_ = (float)atof(strSlot.substr(0, found).c_str()); + + + + if (parentHub_->GetMPA(slot_)) { + mpa_number = slot_; + } + else { + mpa_number = -1; + } + + + if (parentHub_->GetAOMpos1(slot_)) { //laser has AMO1 + link_AOM1 = true; + } + if (parentHub_->GetAOMpos2(slot_)) { //laser has AMO2 + link_AOM2 = true; + } + else if (spa != "????") { //self modulating lcx + pow_adj = true; + } + + descriPt1 << "LCX"; + + descriPt1 << " source on slot " << slot_; + descriPt1 << ", " << sourceSerialNumber; + + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Description, descriPt1.str().c_str(), MM::String, true)); + + // Alarm (read only) + CPropertyAction* pAct = new CPropertyAction(this, &GenericLaser::OnAlarm); + RETURN_ON_MM_ERROR(CreateProperty("Alarm", "None", MM::String, true, pAct)); + + // Status (read only) + pAct = new CPropertyAction(this, &GenericLaser::OnState); + RETURN_ON_MM_ERROR(CreateProperty("State", "", MM::String, true, pAct)); + + // Emission selector (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnEmissionOnOff); + RETURN_ON_MM_ERROR(CreateProperty("Emission", "", MM::String, false, pAct)); + AddAllowedValue("Emission", "ON"); + AddAllowedValue("Emission", "OFF"); + + // Digital modulation selector (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnDigitalMod); + RETURN_ON_MM_ERROR(CreateProperty("Digital Modulation", "", MM::String, false, pAct)); + AddAllowedValue("Digital Modulation", "ON"); + AddAllowedValue("Digital Modulation", "OFF"); + + // Analog modulation selector (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnAnalogMod); + RETURN_ON_MM_ERROR(CreateProperty("Analog Modulation", "", MM::String, false, pAct)); + AddAllowedValue("Analog Modulation", "ON"); + AddAllowedValue("Analog Modulation", "OFF"); + + // Control mode selector (= APC or ACC) (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnControlMode); + RETURN_ON_MM_ERROR(CreateProperty("Control mode", "", MM::String, false, pAct)); + AddAllowedValue("Control mode", "ACC"); + AddAllowedValue("Control mode", "APC"); + + //Fire property + pAct = new CPropertyAction(this, &GenericLaser::OnFire); + RETURN_ON_MM_ERROR(CreateProperty("Fire", "0", MM::Float, false, pAct)); + + + + // Retrieves and define the laser's maximal power + string maxpowCmd = "DL SPM"; + + maxRelPower_ = 100.0; + + + // Retrieves and define the laser's maximal current + maxCurrent_ = 125.0; + + + // Power set point (write/read) + pAct = new CPropertyAction(this, &GenericLaser::OnPowerSetPoint); + RETURN_ON_MM_ERROR(CreateProperty("Power set point", "0", MM::Float, false, pAct)); + SetPropertyLimits("Power set point", 0, maxRelPower_); + + RETURN_ON_MM_ERROR(UpdateStatus()); + + initialized_ = true; + } + + return DEVICE_OK; +} + + +int OxxiusLCX::Fire(double deltaT) +{ + string activate_query = "DL 1"; + string deactivate_query = "DL 0"; + + if (laserOn_ == false) { + laserOn_ = true; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, activate_query.c_str(), false)); + } + CDeviceUtils::SleepMs((long)(deltaT)); + laserOn_ = false; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, deactivate_query.c_str(), false)); + //At the end, the laser is set to off + + return DEVICE_OK; +} + +//RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false)); + +/////////////////////////////////////////////////////////////////////////////// +// Action handlers +/////////////////////////////////////////////////////////////////////////////// + +int OxxiusLCX::OnAlarm(MM::PropertyBase* pProp, MM::ActionType) +{ + unsigned int alarmInt = 99; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?F", false)); + + parentHub_->ParseforInteger(alarmInt); + + switch (alarmInt) { + case 0: + alarm_ = "No Alarm"; + break; + case 1: + alarm_ = "Out-of-bounds diode current"; + break; + case 2: + alarm_ = "Unexpected laser power value"; + break; + case 3: + alarm_ = "Out-of-bounds supply voltage"; + break; + case 4: + alarm_ = "Out-of-bounds internal temperature"; + break; + case 5: + alarm_ = "Out-of-bounds baseplate temperature"; + break; + case 7: + alarm_ = "Interlock circuit open"; + break; + case 8: + alarm_ = "Soft reset"; + break; + default: + alarm_ = "Other alarm"; + } + + pProp->Set(alarm_.c_str()); + + return DEVICE_OK; +} + + +int OxxiusLCX::OnState(MM::PropertyBase* pProp, MM::ActionType) +{ + unsigned int stateInt = 99; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?STA", false)); + + parentHub_->ParseforInteger(stateInt); + + switch (stateInt) { + case 1: + state_ = "Warm-up phase"; + break; + case 2: + state_ = "Stand-by state"; + break; + case 3: + state_ = "Emission on"; + break; + case 4: + state_ = "Internal error"; + break; + case 5: + state_ = "Alarm"; + break; + case 6: + state_ = "Sleep state"; + break; + default: + state_ = "Other state"; + } + + pProp->Set(alarm_.c_str()); + + return DEVICE_OK; +} + + + +int OxxiusLCX::OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + unsigned int status = 0; + ostringstream query; + + query << "?CS " << slot_; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, query.str().c_str(), false)); + parentHub_->ParseforInteger(status); + + switch (status) { + case 2: // LCX model: shutter closed + laserOn_ = false; + break; + case 3: // LCX model: shutter open + laserOn_ = true; + break; + default: + laserOn_ = true; + } + + if (laserOn_) { + pProp->Set("ON"); + } + else { + pProp->Set("OFF"); + } + } + else if (eAct == MM::AfterSet) { + string newEmissionStatus, newCommand = ""; + + pProp->Get(newEmissionStatus); + + if (newEmissionStatus.compare("ON") == 0) { + newCommand = "DL 1"; + laserOn_ = true; + } + else if (newEmissionStatus.compare("OFF") == 0) { + newCommand = "DL 0"; + laserOn_ = false; + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false)); + } + return DEVICE_OK; +} + + +int OxxiusLCX::OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + unsigned int querySlot = NO_SLOT; + + if (eAct == MM::BeforeGet) { + string query; + + + querySlot = NO_SLOT; + if (link_AOM1 == true) { + query = "AOM1 TTL"; + } + else if (link_AOM2 == true) { + query = "AOM2 TTL"; + } + else { + query = ""; + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, query.c_str(), false)); + + bool digiM; + parentHub_->ParseforBoolean(digiM); + + if (digiM) + digitalMod_.assign("ON"); + else + digitalMod_.assign("OFF"); + + pProp->Set(digitalMod_.c_str()); + + } + else if (eAct == MM::AfterSet) { + string newModSet, newCommand; + + pProp->Get(newModSet); + digitalMod_.assign(newModSet); + + if (digitalMod_ == "ON") { + querySlot = NO_SLOT; + + if (link_AOM1 == true) { + newCommand.assign("AOM1 TTL 1"); + } + else if (link_AOM2 == true) { + newCommand.assign("AOM2 TTL 1"); + } + else { + newCommand.assign(""); + } + + } + else if (digitalMod_ == "OFF") { + querySlot = NO_SLOT; + + if (link_AOM1 == true) { + newCommand.assign("AOM1 TTL 0"); + } + else if (link_AOM2 == true) { + newCommand.assign("AOM2 TTL 0"); + } + else { + newCommand.assign(""); + } + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, newCommand.c_str(), false)); + } + return DEVICE_OK; +} + + +int OxxiusLCX::OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + unsigned int querySlot = NO_SLOT; + + if (eAct == MM::BeforeGet) { + string query; + querySlot = NO_SLOT; + + if (link_AOM1 == true) { + query = "AOM1 AM"; + } + else if (link_AOM2 == true) { + query = "AOM2 AM"; + } + else { + query = ""; + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, query.c_str(), false)); + bool digiM; + parentHub_->ParseforBoolean(digiM); + + if (digiM) { + digitalMod_.assign("ON"); + } + else { + digitalMod_.assign("OFF"); + } + pProp->Set(digitalMod_.c_str()); + + } + else if (eAct == MM::AfterSet) { + ostringstream newCommand; + + querySlot = NO_SLOT; + if (link_AOM1 == true) { + newCommand << "AOM1 AM"; + } + if (link_AOM2 == true) { + newCommand << "AOM2 AM"; + } + else { + return DEVICE_OK; + } + + pProp->Get(digitalMod_); + + if (digitalMod_ == "OFF") + newCommand << "0"; + else + newCommand << "1"; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, newCommand.str().c_str(), false)); + } + return DEVICE_OK; +} + + +int OxxiusLCX::OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + controlMode_.assign("APC"); + pProp->Set(controlMode_.c_str()); + } + else if (eAct == MM::AfterSet) { + string newCommand; + + pProp->Get(controlMode_); + + controlMode_ = "APC"; + pProp->Set(controlMode_.c_str()); + + } + return DEVICE_OK; +} + +/* +int OxxiusLCX::OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + string command = "?SP"; + unsigned int thisSlot = slot_; + float absSetPoint_; + + if ((0 < mpa_number) && (mpa_number < 7)) { + thisSlot = NO_SLOT; + command = "?PL"; + stringstream s; + s << mpa_number; + command += s.str(); + } + else { + if (link_AOM1 == true) { + thisSlot = NO_SLOT; + command = "?SP1"; + } + else if (link_AOM2 == true) { + thisSlot = NO_SLOT; + command = "?SP2"; + } + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, command.c_str(), false)); + parentHub_->ParseforFloat(absSetPoint_); + + pProp->Set((100 * absSetPoint_) / nominalPower_); + } + else if (eAct == MM::AfterSet) { + + double GUISetPoint = 0.0; + pProp->Get(GUISetPoint); + + if ((GUISetPoint >= 0.0) || (GUISetPoint <= maxRelPower_)) { + string command = "P"; + unsigned int thisSlot = slot_; + + ostringstream newCommand; + char* powerSPString = new char[20]; + strcpy(powerSPString, CDeviceUtils::ConvertToString((GUISetPoint * nominalPower_) / 100)); + + if ((0 < mpa_number) && (mpa_number < 7)) { + thisSlot = NO_SLOT; + command = "IP"; + command += CDeviceUtils::ConvertToString((int)(mpa_number)); + + strcpy(powerSPString, CDeviceUtils::ConvertToString(GUISetPoint)); + } + else { + if (link_AOM1 == true) { + thisSlot = NO_SLOT; + command = "P"; + } + else if (link_AOM2 == true) { + thisSlot = NO_SLOT; + command = "P2"; + } + else if (pow_adj == true) { + command = "IP"; + strcpy(powerSPString, CDeviceUtils::ConvertToString(GUISetPoint)); + } + } + + newCommand << command << " " << powerSPString; + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, newCommand.str().c_str(), false)); + } + else { + // If the value entered through the GUI is not valid, read the machine value + OnPowerSetPoint(pProp, MM::BeforeGet); + } + } + return DEVICE_OK; +} +*/ + +/* +int OxxiusLCX::OnFire(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::AfterSet) { + double input; + pProp->Get(input); + return Fire(input); + } + return DEVICE_OK; +} +*/ \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusLCX.h b/DeviceAdapters/OxxiusCombiner/OxxiusLCX.h new file mode 100644 index 000000000..b361a596b --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusLCX.h @@ -0,0 +1,47 @@ +#pragma once +#include "GenericLaser.h" +using namespace std; + +class OxxiusLCX : public GenericLaser +{ +public: + OxxiusLCX(const char* nameAndSlot); + ~OxxiusLCX(); + + int Initialize(); + + int Fire(double deltaT); + + // int OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; }; //never called because it's a LCX laser + int OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnState(MM::PropertyBase* pProp, MM::ActionType eAct); + int OnAlarm(MM::PropertyBase* pProp, MM::ActionType eAct); + // int OnFire(MM::PropertyBase* pProp, MM::ActionType eAct); + + int OnPowerReadback(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; }; + int OnCurrentReadback(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; }; + int OnOperatingMode(MM::PropertyBase* pProp, MM::ActionType eAct) { return DEVICE_OK; }; + +private: + bool initialized_; + + //// SPECIFIC TO LCX + float maxRelPower_; + float nominalPower_; + float maxCurrent_; + unsigned int waveLength; + string state_; + string alarm_; + string controlMode_; + string analogMod_; + string digitalMod_; + + bool link_AOM1;//->LCX linked to a AOM number 1 + bool link_AOM2;//->LCX linked to a AOM number 2 + bool pow_adj; //-> LCX with power adjustment + int mpa_number; //-> LCX linked to mpa number n +}; \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp new file mode 100644 index 000000000..cb4b5ab36 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp @@ -0,0 +1,170 @@ +#include "OxxiusMDual.h" + +#include +#include +#include +#include +#include "../../MMDevice/ModuleInterface.h" +using namespace std; + +/////////////////////////////////////////////////////////////////////////////// +// +// Oxxius M-Dual implementation +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +/////////////////////////////////////////////////////////////////////////////// + +OxxiusMDual::OxxiusMDual(const char* nameAndSlot) : initialized_(false) +{ + parentHub_ = 0; + core_ = GetCoreCallback(); + + std::string tSlot = string(nameAndSlot); + name_.assign(tSlot); // sets MDual name + + slot_ = tSlot.substr(tSlot.length() - 1, 1); + + // Set property list + // ----------------- + // Name (read only) + CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true); + + CreateProperty(MM::g_Keyword_Description, "M-Dual module", MM::String, true); + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); + + // parent ID display + CreateHubIDProperty(); +} + + +OxxiusMDual::~OxxiusMDual() +{ + Shutdown(); +} + + +int OxxiusMDual::Initialize() +{ + if (!initialized_) { + parentHub_ = static_cast(GetParentHub()); + if (!parentHub_) { + return DEVICE_COMM_HUB_MISSING; + } + char hubLabel[MM::MaxStrLength]; + parentHub_->GetLabel(hubLabel); + SetParentID(hubLabel); // for backward compatibility + + + // Set property list + // ----------------- + CPropertyAction* pAct = new CPropertyAction(this, &OxxiusMDual::OnSetRatio);//setting the possible positions + RETURN_ON_MM_ERROR(CreateProperty("Split ratio", "0", MM::Float, false, pAct)); + SetPropertyLimits("Split ratio", 0.0, 100.0); + + // Set property list + // ----------------- + // State + /*CPropertyAction* pAct = new CPropertyAction (this, &OxxiusMDual::OnState); + RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_State, "0", MM::Integer, false, pAct) ); + SetPropertyLimits("Set Position", 0, 100);*/ + + /*char pos[3]; + for (unsigned int i=0; iQueryCommand(this, GetCoreCallback(), NO_SLOT, command.str().c_str()) ); + parentHub_->ParseforInteger(currentPos); + + //SetPosition(currentPos); + pProp->Set((long)currentPos); + } + else if (eAct == MM::AfterSet) { + long newPosition = 0; + + //GetPosition(newPosition); + pProp->Get(newPosition); + + std::ostringstream newCommand; + newCommand << "IP" << slot_ << " " << newPosition; + + RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str()) ); + } + return DEVICE_OK; +}*/ + + +int OxxiusMDual::OnSetRatio(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + double currentRatio = 0.0; + std::ostringstream command; + command << "IP" << slot_; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, command.str().c_str(), true)); + parentHub_->ParseforPercent(currentRatio); + + pProp->Set(currentRatio); + } + + else if (eAct == MM::AfterSet) { + double newRatio = 0.0; + + pProp->Get(newRatio); + if ((newRatio >= 0.0) || (newRatio <= 100.0)) { + std::ostringstream newCommand; + newCommand << "IP" << slot_ << " " << newRatio; + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str(), true)); + } + } + return DEVICE_OK; +} \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusMDual.h b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.h new file mode 100644 index 000000000..b610a44ad --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.h @@ -0,0 +1,37 @@ +#pragma once + +#include "OxxiusCombinerHub.h" + +#include "../../MMDevice/MMDevice.h" +#include "../../MMDevice/DeviceBase.h" +#include "../../MMDevice/ModuleInterface.h" +#include +#include +#include + +class OxxiusMDual : public CGenericBase +{ +public: + OxxiusMDual(const char* name); + ~OxxiusMDual(); + + // MMDevice API + // ------------ + int Initialize(); + int Shutdown(); + + void GetName(char* pszName) const; + bool Busy(); + + // Action Interface + // ---------------- + int OnSetRatio(MM::PropertyBase* pProp, MM::ActionType eAct); + +private: + bool initialized_; + std::string name_; + std::string slot_; + MM::Core* core_; + + OxxiusCombinerHub* parentHub_; +}; diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp new file mode 100644 index 000000000..ffad899cc --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp @@ -0,0 +1,148 @@ +#include "OxxiusShutter.h" + +#include +#include +#include +#include +#include "../../MMDevice/ModuleInterface.h" +using namespace std; + +/////////////////////////////////////////////////////////////////////////////// +// +// Oxxius shutter implementation +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +/////////////////////////////////////////////////////////////////////////////// + +OxxiusShutter::OxxiusShutter(const char* nameAndSlot) : initialized_(false) +{ + isOpen_ = false; + parentHub_ = 0; + + name_.assign(nameAndSlot); + + std::string strChnl = string(nameAndSlot); + strChnl = strChnl.substr(strChnl.length() - 1, 1); + channel_ = (unsigned int)atoi(strChnl.c_str()); + + // Set property list + // ----------------- + // Name (read only) + CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true); + + std::ostringstream shutterDesc; + shutterDesc << "Electro-mechanical shutter on channel " << channel_ << "."; + CreateProperty(MM::g_Keyword_Description, shutterDesc.str().c_str(), MM::String, true); + + InitializeDefaultErrorMessages(); + SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); + + // parent ID display + CreateHubIDProperty(); +} + + +OxxiusShutter::~OxxiusShutter() +{ + Shutdown(); +} + + +int OxxiusShutter::Initialize() +{ + if (!initialized_) { + parentHub_ = static_cast(GetParentHub()); + if (!parentHub_) { + return DEVICE_COMM_HUB_MISSING; + } + char hubLabel[MM::MaxStrLength]; + parentHub_->GetLabel(hubLabel); + SetParentID(hubLabel); // for backward compatibility + + // Set property list + // ----------------- + + // Open/Close selector (write/read) + CPropertyAction* pAct = new CPropertyAction(this, &OxxiusShutter::OnState); + RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_State, "", MM::String, false, pAct)); + AddAllowedValue(MM::g_Keyword_State, "Open"); + AddAllowedValue(MM::g_Keyword_State, "Closed"); + + // Closing the shutter on Initialization + RETURN_ON_MM_ERROR(SetProperty(MM::g_Keyword_State, "Closed")); + + RETURN_ON_MM_ERROR(UpdateStatus()); + + initialized_ = true; + } + + return DEVICE_OK; +} + + +int OxxiusShutter::Shutdown() +{ + initialized_ = false; + return DEVICE_OK; +} + + +void OxxiusShutter::GetName(char* Name) const +{ + CDeviceUtils::CopyLimitedString(Name, name_.c_str()); +} + + +bool OxxiusShutter::Busy() +{ + return false; +} + + +int OxxiusShutter::SetOpen(bool openCommand) +{ + if (openCommand) + return SetProperty(MM::g_Keyword_State, "Open"); + else + return SetProperty(MM::g_Keyword_State, "Closed"); +} + + +int OxxiusShutter::GetOpen(bool& isOpen) +{ + isOpen = isOpen_; + return DEVICE_OK; +} + + +int OxxiusShutter::OnState(MM::PropertyBase* pProp, MM::ActionType eAct) +{ + if (eAct == MM::BeforeGet) { + if (isOpen_) { + pProp->Set("Open"); + } + else { + pProp->Set("Closed"); + } + } + else if (eAct == MM::AfterSet) { + + std::string newState = ""; + pProp->Get(newState); + + std::ostringstream newCommand; + newCommand << "SH" << channel_ << " "; + + if (newState.compare("Open") == 0) { + newCommand << "1"; + isOpen_ = true; + } + else if (newState.compare("Closed") == 0) { + newCommand << "0"; + isOpen_ = false; + } + + RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str(), false)); + } + return DEVICE_OK; +} \ No newline at end of file diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusShutter.h b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.h new file mode 100644 index 000000000..e637e98c9 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.h @@ -0,0 +1,50 @@ +#pragma once + +#include "OxxiusCombinerHub.h" + +#include "../../MMDevice/MMDevice.h" +#include "../../MMDevice/DeviceBase.h" +#include "../../MMDevice/ModuleInterface.h" +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////// +// +// Device adaptaters for "shutter" source in Combiner +// +////////////////////////////////////////////////////////////////////////////// + +class OxxiusShutter : public CShutterBase +{ +public: + OxxiusShutter(const char* nameAndChannel); + ~OxxiusShutter(); + + // MMDevice API + // ------------ + int Initialize(); + int Shutdown(); + + void GetName(char* pszName) const; + bool Busy(); + + // Shutter API + int SetOpen(bool openCommand = true); + int GetOpen(bool& isOpen); + int Fire(double /*deltaT*/) { return DEVICE_UNSUPPORTED_COMMAND; } + + // Action Interface + // ---------------- + int OnState(MM::PropertyBase* pProp, MM::ActionType eAct); + +private: + bool initialized_; + std::string name_; + + OxxiusCombinerHub* parentHub_; + bool isOpen_; + unsigned int channel_; + + MM::MMTime changedTime_; +}; diff --git a/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp b/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp deleted file mode 100644 index 49e042ddd..000000000 --- a/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.cpp +++ /dev/null @@ -1,1920 +0,0 @@ - -/////////////////////////////////////////////////////////////////////////////// -// FILE: OxxiusCombiner.cpp -// PROJECT: Micro-Manager -// SUBSYSTEM: DeviceAdapters -//----------------------------------------------------------------------------- -// DESCRIPTION: Controls Oxxius lasers and combiners through a serial port -// COPYRIGHT: Oxxius SA, 2013-2019 -// LICENSE: LGPL -// AUTHORS: Tristan Martinez, Pierre Bretagne -// - - -#include "Oxxius_combiner.h" -#include -#include -#include -#include -#include "ModuleInterface.h" -using namespace std; - -// -#define MAX_NUMBER_OF_SLOTS 6 -#define RCV_BUF_LENGTH 256 -#define NO_SLOT 0 - -// Oxxius devices -const char* g_OxxiusCombinerDeviceName = "Combiner"; -const char* g_OxxiusLaserBoxxDeviceName = "LaserBoxx source"; -const char* g_OxxiusLaserBoxx1DeviceName = "LaserBoxx source 1"; -const char* g_OxxiusLaserBoxx2DeviceName = "LaserBoxx source 2"; -const char* g_OxxiusLaserBoxx3DeviceName = "LaserBoxx source 3"; -const char* g_OxxiusLaserBoxx4DeviceName = "LaserBoxx source 4"; -const char* g_OxxiusLaserBoxx5DeviceName = "LaserBoxx source 5"; -const char* g_OxxiusLaserBoxx6DeviceName = "LaserBoxx source 6"; - -const char* g_ObisLaserDeviceName = "Obis laser source"; -const char* g_ObisLaser1DeviceName = "Obis laser Source 1"; -const char* g_ObisLaser2DeviceName = "Obis laser Source 2"; -const char* g_ObisLaser3DeviceName = "Obis laser Source 3"; -const char* g_ObisLaser4DeviceName = "Obis laser Source 4"; -const char* g_ObisLaser5DeviceName = "Obis laser Source 5"; -const char* g_ObisLaser6DeviceName = "Obis laser Source 6"; - -const char* g_OxxiusShutterDeviceName = "Shutter"; -const char* g_OxxiusShutter1DeviceName = "Shutter 1"; -const char* g_OxxiusShutter2DeviceName = "Shutter 2"; -const char* g_OxxiusMDualDeviceName = "MDual"; -const char* g_OxxiusMDualADeviceName = "MDual A"; -const char* g_OxxiusMDualBDeviceName = "MDual B"; -const char* g_OxxiusMDualCDeviceName = "MDual C"; -const char* g_OxxiusFlipMirrorDeviceName = "Flip-Mirror"; -const char* g_OxxiusFlipMirror1DeviceName = "Flip-Mirror 1"; -const char* g_OxxiusFlipMirror2DeviceName = "Flip-Mirror 2"; - - - - -const char* g_slotPrefix[7] = {"","L1 ","L2 ","L3 ","L4 ","L5 ","L6 "}; - -const char* convertable[3] = { "A", "B", "C" }; - -/////////////////////////////////////////////////////////////////////////////// -// Exported MMDevice API -/////////////////////////////////////////////////////////////////////////////// -MODULE_API void InitializeModuleData() -{ - RegisterDevice(g_OxxiusCombinerDeviceName, MM::HubDevice, "Oxxius laser combiner controlled through serial interface"); - RegisterDevice(g_OxxiusLaserBoxx1DeviceName, MM::ShutterDevice, "LaserBoxx on slot 1"); - RegisterDevice(g_OxxiusLaserBoxx2DeviceName, MM::ShutterDevice, "LaserBoxx on slot 2"); - RegisterDevice(g_OxxiusLaserBoxx3DeviceName, MM::ShutterDevice, "LaserBoxx on slot 3"); - RegisterDevice(g_OxxiusLaserBoxx4DeviceName, MM::ShutterDevice, "LaserBoxx on slot 4"); - RegisterDevice(g_OxxiusLaserBoxx5DeviceName, MM::ShutterDevice, "LaserBoxx on slot 5"); - RegisterDevice(g_OxxiusLaserBoxx6DeviceName, MM::ShutterDevice, "LaserBoxx on slot 6"); - - RegisterDevice(g_ObisLaser1DeviceName, MM::ShutterDevice, "Obis Laser on slot 1"); - RegisterDevice(g_ObisLaser2DeviceName, MM::ShutterDevice, "Obis Laser on slot 2"); - RegisterDevice(g_ObisLaser3DeviceName, MM::ShutterDevice, "Obis Laser on slot 3"); - RegisterDevice(g_ObisLaser4DeviceName, MM::ShutterDevice, "Obis Laser on slot 4"); - RegisterDevice(g_ObisLaser5DeviceName, MM::ShutterDevice, "Obis Laser on slot 5"); - RegisterDevice(g_ObisLaser6DeviceName, MM::ShutterDevice, "Obis Laser on slot 6"); - - RegisterDevice(g_OxxiusShutter1DeviceName, MM::ShutterDevice, "E-m shutter on channel 1"); - RegisterDevice(g_OxxiusShutter2DeviceName, MM::ShutterDevice, "E-m shutter on channel 2"); - RegisterDevice(g_OxxiusMDualADeviceName, MM::GenericDevice, "M-Dual on channel A"); - RegisterDevice(g_OxxiusMDualBDeviceName, MM::GenericDevice, "M-Dual on channel B"); - RegisterDevice(g_OxxiusMDualCDeviceName, MM::GenericDevice, "M-Dual on channel C"); - RegisterDevice(g_OxxiusFlipMirror1DeviceName, MM::GenericDevice, "Flip-Mirror on slot 1"); - RegisterDevice(g_OxxiusFlipMirror2DeviceName, MM::GenericDevice, "Flip-Mirror on slot 2"); - -} - -MODULE_API MM::Device* CreateDevice(const char* deviceNameChar) -{ - if (deviceNameChar == 0) - return 0; - - std::string deviceNameAndSlot = string(deviceNameChar); - - if (strcmp(deviceNameChar,g_OxxiusCombinerDeviceName) == 0) { - return new OxxiusCombinerHub(); - } else if ( deviceNameAndSlot.compare(0, strlen(g_OxxiusLaserBoxxDeviceName), g_OxxiusLaserBoxxDeviceName) == 0 ) { - return new OxxiusLaserBoxx(deviceNameChar); - } else if ( deviceNameAndSlot.compare(0, strlen(g_OxxiusShutterDeviceName), g_OxxiusShutterDeviceName) == 0 ) { - return new OxxiusShutter(deviceNameChar); - } else if (deviceNameAndSlot.compare(0, strlen(g_OxxiusMDualDeviceName), g_OxxiusMDualDeviceName) == 0) { - return new OxxiusMDual(deviceNameChar); - } else if (deviceNameAndSlot.compare(0, strlen(g_OxxiusFlipMirrorDeviceName), g_OxxiusFlipMirrorDeviceName) == 0) { - return new OxxiusFlipMirror(deviceNameChar); - } else if (deviceNameAndSlot.compare(0, strlen(g_ObisLaserDeviceName), g_ObisLaserDeviceName) == 0) { -// return new OxxiusObisSupport(deviceNameChar); - } - return 0; -} - -MODULE_API void DeleteDevice(MM::Device* pDevice) -{ - delete pDevice; -} - -/////////////////////////////////////////////////////////////////////////////// -// -// Oxxius combiner implementation -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -/////////////////////////////////////////////////////////////////////////////// - - -OxxiusCombinerHub::OxxiusCombinerHub() : initialized_(false) -{ - // Initializing private variables - serialNumber_ = ""; - installedDevices_ = 0; - serialAnswer_ = ""; - interlockClosed_ = false; - keyActivated_ = false; - - InitializeDefaultErrorMessages(); - SetErrorText(ERR_COMBINER_NOT_FOUND, "Hub Device not found. The peer device is expected to be a Oxxius combiner"); - - - // Create pre-initialization properties - // ------------------------------------ - - // Communication port - CPropertyAction* pAct = new CPropertyAction(this, &OxxiusCombinerHub::OnPort); - CreateProperty(MM::g_Keyword_Port, "Undefined", MM::String, false, pAct, true); -} - -OxxiusCombinerHub::~OxxiusCombinerHub() -{ - Shutdown(); -} - -void OxxiusCombinerHub::GetName(char* name) const -{ - CDeviceUtils::CopyLimitedString(name, g_OxxiusCombinerDeviceName); -} - -bool OxxiusCombinerHub::Busy() -{ - return false; - -} - - -int OxxiusCombinerHub::Initialize() -{ - if(!initialized_) { - - // Set proprety list - // - - - - - - - - - - - // Name and description of the combiner: - RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_Name, g_OxxiusCombinerDeviceName, MM::String, true) ); - RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_Description, "Oxxius L6Cc/L4Cc combiner", MM::String, true) ); - - // Serial number of the combiner: - CPropertyAction* pAct = new CPropertyAction (this, &OxxiusCombinerHub::OnSerialNumber); - RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_HubID, serialNumber_.c_str(), MM::String, true, pAct) ); - - // Interlock circuit: - pAct = new CPropertyAction (this, &OxxiusCombinerHub::OnInterlock); - RETURN_ON_MM_ERROR( CreateProperty("Interlock circuit", "", MM::String, true, pAct) ); - - // Emission key: - pAct = new CPropertyAction (this, &OxxiusCombinerHub::OnEmissionKey); - RETURN_ON_MM_ERROR( CreateProperty("EmissionKey", "", MM::String, true, pAct) ); - - if (!IsCallbackRegistered()) - return DEVICE_NO_CALLBACK_REGISTERED; - - // Enumerates the installed AOMs and their position - bool AOM1en = false, AOM2en = false; - unsigned int ver = 0; - - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "AOM1 EN", false)); - ParseforBoolean(AOM1en); - - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "AOM2 EN", false)); - ParseforBoolean(AOM2en); - - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "SV?", false)); - ParseforVersion(ver); - - // A position equal to "0" stands for an absence of modulator - if (AOM1en) { - bool adcom = false; - string command = ""; - - if (ver < 1016) { //version check - adcom = true; - command = "AOM1 PO"; - } - else { - adcom = false; - command = "AOM1 POS"; - } - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, command.c_str(), adcom)); - ParseforInteger(AOM1pos_); - } - if (AOM2en) { - bool adcom = false; - string command = ""; - - if (ver < 1016) { //version check - adcom = true; - command = "AOM2 PO"; - } - else { - adcom = false; - command = "AOM2 POS"; - } - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, command.c_str(), adcom)); - ParseforInteger(AOM1pos_); - } - - - //Mpa position retreive - for (unsigned int i = 1; i <= MAX_NUMBER_OF_SLOTS; i++) { - string command = "IP"; - std::stringstream ss; - ss << i; - command += ss.str(); - - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, command.c_str(), true)); - if (serialAnswer_ != "????") { - mpa[i] = 1; - } - } - - - - RETURN_ON_MM_ERROR( UpdateStatus() ); - - initialized_ = true; - - // RETURN_ON_MM_ERROR( DetectInstalledDevices() ); - } - return DEVICE_OK; -} - - - -int OxxiusCombinerHub::DetectInstalledDevices() -{ - if (initialized_) { - - // Enumerates the lasers (or devices) present on the combiner - unsigned int masque = 1; - unsigned int repartition = 0; - - //sending command ?CL - RETURN_ON_MM_ERROR( QueryCommand(this, GetCoreCallback(), NO_SLOT, "?CL", false) ); - ParseforInteger(repartition); - - for(unsigned int querySlot=1; querySlot<=MAX_NUMBER_OF_SLOTS; querySlot++) { - if ((repartition & masque) != 0) { - string answer; - // A laser source is listed, now querying for detailed information (model, etc) - - std::string detailedInfo, serialNumber; - - //send command to get devices information - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), querySlot, "INF?", false)); - ParseforString(detailedInfo); - - if (detailedInfo != "timeout") { - std::ostringstream nameSlotModel; - nameSlotModel << g_OxxiusLaserBoxxDeviceName << " " << querySlot; - - MM::Device* pDev = ::CreateDevice(nameSlotModel.str().c_str()); - if (pDev) { - AddInstalledDevice(pDev); - installedDevices_++; - } - } - } - masque <<= 1; // Left-shift the bit mask and repeat - } - - // Creating Devices for the two electro-mechanical shutters: - for(unsigned int channel=1; channel<=2; channel++) { - std::ostringstream nameModelChannel; - nameModelChannel << g_OxxiusShutterDeviceName << " " << channel; - - MM::Device* pDev = ::CreateDevice(nameModelChannel.str().c_str()); - if (pDev) { - AddInstalledDevice(pDev); - installedDevices_++; - } - } - - // Creating Devices for the "Flip mirror" or MDUAL modules: - /*unsigned int FM1type = 0, FM2type = 0; - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "FM1C", false)); - ParseforInteger(FM1type); - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "FM2C", false)); - ParseforInteger(FM2type);*/ - - - //Mdual module creation - for (unsigned int j = 0; j <= 2; j++) { - std::string MDSlot; - std::ostringstream com; - com << "IP" << convertable[j]; - - std::ostringstream InfoMessage4; /////test in hub - InfoMessage4 << "test" << com.str(); - LogError(DEVICE_OK, this, GetCoreCallback(), InfoMessage4.str().c_str()); - - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, com.str().c_str(), true)); - ParseforString(MDSlot); - - com.str(""); - com.clear(); - com << g_OxxiusMDualDeviceName << " " << convertable[j]; - - if (MDSlot != "????") { - MM::Device* pDev = ::CreateDevice(com.str().c_str()); - if (pDev) { - AddInstalledDevice(pDev); - installedDevices_++; - } - - } - - } - - //Flip mirror module creation - - for (unsigned int j = 1; j <= 4; j++) { - unsigned int FMSlot; - std::ostringstream com; - com << "FM" << j << "C"; - - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, com.str().c_str(), false)); - ParseforInteger(FMSlot); - - com.str(""); - com.clear(); - com << g_OxxiusFlipMirrorDeviceName << " " << j; - - if (FMSlot == 1) { - - std::ostringstream InfoMessage4; /////test - InfoMessage4 << "test " << com.str().c_str(); - LogError(DEVICE_OK, this, GetCoreCallback(), InfoMessage4.str().c_str()); - - MM::Device* pDev = ::CreateDevice(com.str().c_str()); - if (pDev) { - AddInstalledDevice(pDev); - installedDevices_++; - } - - } - - } - - - //Laser OBIS creation - RETURN_ON_MM_ERROR(QueryCommand(this, GetCoreCallback(), NO_SLOT, "OB", true)); - ParseforInteger(obPos_); - - if (obPos_ != 0 && obPos_ != -1) { - std::ostringstream nameSlotModel; - nameSlotModel << g_ObisLaserDeviceName << " " << obPos_; - - MM::Device* pDev = ::CreateDevice(nameSlotModel.str().c_str()); - if (pDev) { - AddInstalledDevice(pDev); - installedDevices_++; - } - } - - /*switch (FM1type) { - case 4: { // MDual detected - MM::Device* pDev = ::CreateDevice(g_OxxiusMDualDeviceName); - if (pDev) { - AddInstalledDevice(pDev); - installedDevices_++; - } - break; - } - case 0: - default: - // nop - break; - }*/ - } - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::Shutdown() -{ - initialized_ = false; - return DEVICE_OK; -} - - -/////////////////////////////////////////////////////////////////////////////// -// Action handlers -/////////////////////////////////////////////////////////////////////////////// - -int OxxiusCombinerHub::OnPort(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) - { - pProp->Set(port_.c_str()); - } - else if (eAct == MM::AfterSet) - { - pProp->Get(port_); - pProp->Set(port_.c_str()); - } - return DEVICE_OK; -} - - -int OxxiusCombinerHub::OnSerialNumber(MM::PropertyBase* pProp, MM::ActionType pAct) -{ - if (pAct == MM::BeforeGet) { - QueryCommand(this, GetCoreCallback(), NO_SLOT, "HID?", false); - ParseforString(serialNumber_); - pProp->Set(serialNumber_.c_str()); - } - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::OnInterlock(MM::PropertyBase* pProp, MM::ActionType pAct) -{ - if (pAct == MM::BeforeGet) { - QueryCommand(this, GetCoreCallback(), NO_SLOT, "INT?", false); - ParseforBoolean(interlockClosed_); - - if( interlockClosed_) { - pProp->Set("Closed"); - } else { - pProp->Set("Open"); - } - } - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::OnEmissionKey(MM::PropertyBase* pProp, MM::ActionType pAct) -{ - if (pAct == MM::BeforeGet) { - QueryCommand(this, GetCoreCallback(), NO_SLOT, "KEY?", false); - ParseforBoolean(keyActivated_); - - if( keyActivated_) { - pProp->Set("Armed"); - } else { - pProp->Set("Disarmed"); - } - } - - return DEVICE_OK; -} - - -/////////////////////////////////////////////////////////////////////////////// -// Generic methods -/////////////////////////////////////////////////////////////////////////////// - -void OxxiusCombinerHub::LogError(int id, MM::Device* device, MM::Core* core, const char* functionName) //prinnt log messages -{ - std::ostringstream os; - char deviceName[MM::MaxStrLength]; - device->GetName(deviceName); - os << "Error " << id << ", " << deviceName << ", " << functionName << endl; - core->LogMessage(device, os.str().c_str(), false); -} - - -/** - * Sends a serial command to a given slot, then stores the result in the receive buffer. - */ -int OxxiusCombinerHub::QueryCommand(MM::Device* device, MM::Core* core, const unsigned int destinationSlot, const char* command, bool adco) -{ - // First check: if the command string is empty, do nothing and return "DEVICE_OK" - if( strcmp(command, "") == 0) return DEVICE_OK; - - char rcvBuf_[RCV_BUF_LENGTH]; - // Compose the command to be sent to the combiner - std::string strCommand, strHZIn, strHZOut; - strCommand.assign(g_slotPrefix[destinationSlot]); - strCommand.append(command); - strHZIn.assign(g_slotPrefix[destinationSlot]); - strHZIn.append("HZ 9876"); - strHZOut.assign(g_slotPrefix[destinationSlot]); - strHZOut.append("HZ 0"); - -/* - std::ostringstream InfoMessage; - InfoMessage << "Now sending command :"; - InfoMessage << string(strCommand.c_str()); - LogError(DEVICE_OK, device, core, InfoMessage.str().c_str()); -*/ - std::ostringstream InfoMessage2; - InfoMessage2 << "Send: " << command << " Received: "; - - // Preambule for specific commands - if (adco) { - int ret = core->SetSerialCommand(device, port_.c_str(), strHZIn.c_str(), "\r\n"); - ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); - if (ret != DEVICE_OK) { - LogError(ret, device, core, "QueryCommand-SetSerialCommand - preambule"); - return ret; - } - } - - // Send command through the serial interface - int ret = core->SetSerialCommand(device, port_.c_str(), strCommand.c_str(), "\r\n"); - if (ret != DEVICE_OK) { - LogError(ret, device, core, "QueryCommand-SetSerialCommand"); - return ret; - } - - // Get a response - ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); - - InfoMessage2 << rcvBuf_ ; - /* DEBUG ONLY */ - // LogError(DEVICE_OK, device, core, InfoMessage2.str().c_str()); - - if (ret != DEVICE_OK) { - LogError(ret, device, core, "QueryCommand-GetSerialAnswer"); - - // Keep on trying until we either get our answer, or 3 seconds have passed - int maxTimeMs = 3000; - // Wait for a (increasing) delay between each try - int delayMs = 10; - // Keep track of how often we tried - int counter = 1; - bool done = false; - MM::MMTime startTime (core->GetCurrentMMTime()); // Let's keep in mind that MMTime is counted in microseconds - - while (!done) { - counter++; - ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); - if ((ret == DEVICE_OK) || - ((core->GetCurrentMMTime() - startTime) > - MM::MMTime::fromMs(maxTimeMs))) { - done = true; - } else { - CDeviceUtils::SleepMs(delayMs); - delayMs *= 2; - } - } - ostringstream os; - if (ret == DEVICE_OK) - os << "QueryCommand-GetSerialAnswer: Succeeded reading from serial port after trying " << counter << "times."; - else - os << "QueryCommand-GetSerialAnswer: Failed reading from serial port after trying " << counter << "times."; - - core->LogMessage(device, os.str().c_str(), true); - - serialAnswer_.assign(rcvBuf_); - return ret; - } - serialAnswer_.assign(rcvBuf_); - ret = core->PurgeSerial(device, port_.c_str()); - -/* if( strcmp(serialAnswer_, "timeout") == 0) { - std::ostringstream syntaxErrorMessage; - syntaxErrorMessage << "Time out received against sent command '"; - syntaxErrorMessage << string(strCommand.c_str()); - syntaxErrorMessage << "'"; - - LogError(DEVICE_SERIAL_TIMEOUT, device, core, syntaxErrorMessage.str().c_str()); - return DEVICE_SERIAL_TIMEOUT; - } -*/ - // Epilogue for specific commands - if (adco) { - int ret = core->SetSerialCommand(device, port_.c_str(), strHZOut.c_str(), "\r\n"); - ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); - if (ret != DEVICE_OK) { - LogError(ret, device, core, "QueryCommand-SetSerialCommand - Epilogue"); - return ret; - } - } - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::ParseforBoolean(bool &Bval) -{ - unsigned int intAnswer = (unsigned int)atoi(serialAnswer_.c_str()); - Bval = (intAnswer == 1); - - serialAnswer_.clear(); - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::ParseforFloat(float &Dval) -{ - Dval = (float) atof(serialAnswer_.c_str()); - - serialAnswer_.clear(); - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::ParseforInteger(unsigned int &Ival) -{ - Ival = (unsigned int)atoi(serialAnswer_.c_str()); - - serialAnswer_.clear(); - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::ParseforString(std::string &Sval) -{ - Sval.assign(serialAnswer_); - - serialAnswer_.clear(); - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::ParseforVersion(unsigned int &Vval) //cast the string into a comparable int -{ - std::string temp1; - std::string temp2(serialAnswer_); - - for (unsigned int i = 0; i <= (temp2.length())-1; i++) { - if (temp2.at(i) != '.') { - temp1 += temp2.at(i); - } - } - - stringstream s(temp1); - s >> Vval; - serialAnswer_.clear(); - - return DEVICE_OK; -} - - -int OxxiusCombinerHub::ParseforPercent(double &Pval) //cast the string into a comparable int -{ - std::string percentage; - std::size_t found; - - percentage.assign(serialAnswer_); - - found = percentage.find("%"); - if (found != std::string::npos) { - Pval = atof(percentage.substr(0, found).c_str()); - } - - return DEVICE_OK; -} - - - -int OxxiusCombinerHub::ParseforChar(char* Nval) -{ - strcpy(Nval,serialAnswer_.c_str()); - serialAnswer_.clear(); - - return DEVICE_OK; -} - -bool OxxiusCombinerHub::GetAOMpos1(unsigned int slot) -{ - bool res = false; - - if (slot == AOM1pos_) { - res = true; - } - - return res; -} - -bool OxxiusCombinerHub::GetAOMpos2(unsigned int slot) -{ - bool res = false; - - if (slot == AOM2pos_) { - res = true; - } - - return res; -} - -bool OxxiusCombinerHub::GetMPA(unsigned int slot) { - bool res = false; - - if (mpa[slot] == 1) { - res = true; - } - - return res; -} - -int OxxiusCombinerHub::GetObPos() { - return obPos_; -} - - -/////////////////////////////////////////////////////////////////////////////// -// -// Oxxius generic LaserBoxx implementation -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -/////////////////////////////////////////////////////////////////////////////// - -/*std::ostringstream InfoMessageB; //////////// test out of hub - InfoMessageB << "testB" << "-" << slot_; - LogMessage(InfoMessageB.str().c_str(), false);*/ - -OxxiusLaserBoxx::OxxiusLaserBoxx(const char* nameAndSlot) : initialized_(false) -{ - std::string tSlot = string(nameAndSlot); - - name_.assign(tSlot);// set laser name - tSlot = tSlot.substr(tSlot.length()-1, 1); - slot_ = (unsigned int)atoi(tSlot.c_str());// set laser slot - - parentHub_ ; - busy_ = false; - laserOn_ = false; - alarm_ = ""; - state_ = ""; - digitalMod_ = ""; - analogMod_ = ""; - controlMode_ = ""; - - // powerSetPoint_ = 0.0; - maxRelPower_ = 0.0; - nominalPower_ = 0.0; - maxCurrent_ = 125.0; - - InitializeDefaultErrorMessages(); - SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); - - // parent ID display - CreateHubIDProperty(); -} - - -OxxiusLaserBoxx::~OxxiusLaserBoxx() -{ - Shutdown(); -} - - -void OxxiusLaserBoxx::GetName(char* Name) const -{ - CDeviceUtils::CopyLimitedString(Name, name_.c_str()); -} - - -int OxxiusLaserBoxx::Initialize() -{ - if (!initialized_) { - - std::size_t found; - std::string strSlot; - std::string spa; - - - parentHub_ = static_cast(GetParentHub()); - if (!parentHub_ ) { - return DEVICE_COMM_HUB_MISSING; - } - char hubLabel[MM::MaxStrLength]; - parentHub_->GetLabel(hubLabel); - SetParentID(hubLabel); // for backward compatibility - - // Set property list - // ----------------- - // Name (read only) - RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true) ); - - // Description (read only) - std::ostringstream descriPt1; - char sourceSerialNumber[] = "LAS-XXXXXXXXXX"; - parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "HID?", false); - parentHub_->ParseforChar(sourceSerialNumber); - - parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "IP", true); - parentHub_->ParseforString(spa); - - parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "INF?", false); - parentHub_->ParseforString(strSlot); - - // Retrieves and define the laser's type - found = strSlot.find("-"); - if (found != std::string::npos) { - type = strSlot.substr(0, found); - } - strSlot.erase(0, found + 1); - - // Retrieves and define the laser's wavelength - found = strSlot.find("-"); - if (found != std::string::npos) { - waveLength = (unsigned int)atoi(strSlot.substr(0, found).c_str()); - - } - - // Retrieves and define the nominal power - strSlot.erase(0, found + 1); - nominalPower_ = (float) atof(strSlot.substr(0, found).c_str()); - - //set laser AOM if needed - // model[0] model[1] - // (major) (minor) - // 1 0 -> standard LBX - // 1 1n -> LBX linked to mpa number n - // 2 0 -> standard LCX - // 2 1 -> LCX linked to a AOM number 1 - // 2 2 -> LCX linked to a AOM number 2 - // 2 5 -> LCX with power adjustment - // 2 1n -> LCX linked to mpa number n - - - if (parentHub_->GetMPA(slot_)) { - model_[1] = 10 + slot_; - } else { - model_[1] = 0; - } - - if (type.compare("LBX") == 0) { // The source is a LBX - model_[0] = 1; - } - else if (type.compare("LCX") == 0) { // The source is a LCX - model_[0] = 2; - if (parentHub_->GetAOMpos1(slot_)) { //laser has AMO1 - model_[1] = 1; - } - if (parentHub_->GetAOMpos2(slot_)){ //laser has AMO2 - model_[1] = 2; - } - else if (spa != "????") { //self modulating lcx - model_[1] = 5; - } - } - else { // Should not happen: unkown type - model_[0] = 9; - model_[1] = 9; - } - - switch (model_[0]) { - case 1: // LBX model - descriPt1 << "LBX"; - break; - case 2: // LCX model - descriPt1 << "LCX"; - break; - default: // Should not happen - descriPt1 << "Unknown"; - break; - } - descriPt1 << " source on slot " << slot_; - descriPt1 << ", " << sourceSerialNumber; - - RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_Description, descriPt1.str().c_str(), MM::String, true) ); - - // Alarm (read only) - CPropertyAction* pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnAlarm); - RETURN_ON_MM_ERROR( CreateProperty("Alarm", "None", MM::String, true, pAct) ); - - // Status (read only) - pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnState); - RETURN_ON_MM_ERROR( CreateProperty("State", "", MM::String, true, pAct) ); - - // Emission selector (write/read) - pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnEmissionOnOff); - RETURN_ON_MM_ERROR( CreateProperty("Emission", "", MM::String, false, pAct) ); - AddAllowedValue("Emission", "ON"); - AddAllowedValue("Emission", "OFF"); - - // Digital modulation selector (write/read) - pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnDigitalMod); - RETURN_ON_MM_ERROR( CreateProperty("Digital Modulation", "", MM::String, false, pAct) ); - AddAllowedValue("Digital Modulation", "ON"); - AddAllowedValue("Digital Modulation", "OFF"); - - // Analog modulation selector (write/read) - pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnAnalogMod); - RETURN_ON_MM_ERROR( CreateProperty("Analog Modulation", "", MM::String, false, pAct) ); - AddAllowedValue("Analog Modulation", "ON"); - AddAllowedValue("Analog Modulation", "OFF"); - - // Control mode selector (= APC or ACC) (write/read) - pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnControlMode); - RETURN_ON_MM_ERROR( CreateProperty("Control mode", "", MM::String, false, pAct) ); - AddAllowedValue("Control mode", "ACC"); - AddAllowedValue("Control mode", "APC"); - - - - // Retrieves and define the laser's maximal power - std::string maxpowCmd = "DL SPM"; - switch (model_[0]) { - case 1: // LBX model - switch (model_[1]) { - case 0: // Standard LBX - parentHub_->QueryCommand(this, GetCoreCallback(), slot_, maxpowCmd.c_str(), true); - parentHub_->ParseforFloat(maxRelPower_); - maxRelPower_ = 100 * maxRelPower_ / nominalPower_; - break; - default: // LBX + MPA - maxRelPower_ = 100.0; - break; - } - break; - case 2: // LCX model - maxRelPower_ = 100.0; - break; - default: // Should not happen - maxRelPower_ = 0.0; - break; - } - - - // Retrieves and define the laser's maximal current - maxCurrent_ = 125.0; - - - // Power set point (write/read) - pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnPowerSetPoint); - RETURN_ON_MM_ERROR( CreateProperty("Power set point", "0", MM::Float, false, pAct) ); - SetPropertyLimits("Power set point", 0, maxRelPower_); - - // Power set point (write/read) - pAct = new CPropertyAction (this, &OxxiusLaserBoxx::OnCurrentSetPoint); - RETURN_ON_MM_ERROR( CreateProperty("Current set point", "0", MM::Float, false, pAct) ); - SetPropertyLimits("Current set point", 0, maxCurrent_); - - RETURN_ON_MM_ERROR( UpdateStatus() ); - - initialized_ = true; - } - - return DEVICE_OK; -} - - - -int OxxiusLaserBoxx::Shutdown() -{ - initialized_ = false; - return DEVICE_OK; -} - - -bool OxxiusLaserBoxx::Busy() -{ - return busy_; -} - - -int OxxiusLaserBoxx::SetOpen(bool openCommand) -{ - laserOn_ = openCommand; - return DEVICE_OK; -} - - -int OxxiusLaserBoxx::GetOpen(bool& isOpen) -{ - isOpen = laserOn_; - return DEVICE_OK; -} - - -/////////////////////////////////////////////////////////////////////////////// -// Action handlers -/////////////////////////////////////////////////////////////////////////////// - -int OxxiusLaserBoxx::OnAlarm(MM::PropertyBase* pProp, MM::ActionType) -{ - unsigned int alarmInt = 99; - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?F", false) ); - - parentHub_->ParseforInteger(alarmInt); - - switch (alarmInt) { - case 0: - alarm_ = "No Alarm"; - break; - case 1: - alarm_ = "Out-of-bounds diode current"; - break; - case 2: - alarm_ = "Unexpected laser power value"; - break; - case 3: - alarm_ = "Out-of-bounds supply voltage"; - break; - case 4: - alarm_ = "Out-of-bounds internal temperature"; - break; - case 5: - alarm_ = "Out-of-bounds baseplate temperature"; - break; - case 7: - alarm_ = "Interlock circuit open"; - break; - case 8: - alarm_ = "Soft reset"; - break; - default: - alarm_ = "Other alarm"; - } - - pProp->Set(alarm_.c_str()); - - return DEVICE_OK; -} - - -int OxxiusLaserBoxx::OnState(MM::PropertyBase* pProp, MM::ActionType) -{ - unsigned int stateInt = 99; - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), slot_, "?STA", false) ); - - parentHub_->ParseforInteger(stateInt); - - switch (stateInt) { - case 1: - state_ = "Warm-up phase"; - break; - case 2: - state_ = "Stand-by state"; - break; - case 3: - state_ = "Emission on"; - break; - case 4: - state_ = "Internal error"; - break; - case 5: - state_ = "Alarm"; - break; - case 6: - state_ = "Sleep state"; - break; - default: - state_ = "Other state"; - } - - pProp->Set(alarm_.c_str()); - - return DEVICE_OK; -} - - -int OxxiusLaserBoxx::OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) { - unsigned int status = 0; - std::ostringstream query; - - query << "?CS " << slot_; - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, query.str().c_str(), false) ); - parentHub_->ParseforInteger(status); - - switch (status) { - case 0: // LBX model: Emission off - case 2: // LCX model: shutter closed - laserOn_ = false; - break; - case 1: // LBX model: Emission on - case 3: // LCX model: shutter open - laserOn_ = true; - break; - default: - laserOn_ = true; - } - - if (laserOn_) { - pProp->Set("ON"); - } else { - pProp->Set("OFF"); - } - } - else if (eAct == MM::AfterSet) { - std::string newEmissionStatus, newCommand = ""; - - pProp->Get(newEmissionStatus); - - if( newEmissionStatus.compare("ON") == 0 ) { - newCommand = "DL 1"; - laserOn_ = true; - } else if ( newEmissionStatus.compare("OFF") == 0 ) { - newCommand = "DL 0"; - laserOn_ = false; - } - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false) ); - } - return DEVICE_OK; -} - - -int OxxiusLaserBoxx::OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - unsigned int querySlot = NO_SLOT; - - if (eAct == MM::BeforeGet) { - std::string query; - - // The slot and command depend on the model - switch (model_[0]) { - case 1: // LBX model: retreiving the modulation status - querySlot = slot_; - query = "?TTL"; - break; - case 2: // LCX model: retreiving the modulation status - querySlot = NO_SLOT; - switch (model_[1]) { - case 1: - query = "AOM1 TTL"; - break; - case 2: - query = "AOM2 TTL"; - break; - default: - query = ""; - } - break; - default: // Should not happen - return DEVICE_OK; - } - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, query.c_str(), false) ); - - bool digiM; - parentHub_->ParseforBoolean(digiM); - - if (digiM) - digitalMod_.assign("ON"); - else - digitalMod_.assign("OFF"); - - pProp->Set(digitalMod_.c_str()); - - } else if (eAct == MM::AfterSet) { - std::string newModSet, newCommand; - - pProp->Get(newModSet); - digitalMod_.assign(newModSet); - - if (digitalMod_ == "ON") { - switch (model_[0]) { - case 1: // LBX model: setting the modulation on - querySlot = slot_; - newCommand.assign("TTL 1"); - break; - case 2: // LCX model: setting the modulation on - querySlot = NO_SLOT; - - switch (model_[1]) { - case 1: - newCommand.assign("AOM1 TTL 1"); - break; - case 2: - newCommand.assign("AOM2 TTL 1"); - break; - default: - newCommand.assign(""); - } - break; - default: // Should not happen - return DEVICE_OK; - } - - } else if (digitalMod_ == "OFF") { - switch (model_[0]) { - case 1: // LBX model: setting the modulation off - querySlot = slot_; - newCommand.assign("TTL 0"); - break; - case 2: // LCX model: setting the modulation off - querySlot = NO_SLOT; - switch (model_[1]) { - case 1: - newCommand.assign("AOM1 TTL 0"); - break; - case 2: - newCommand.assign("AOM2 TTL 0"); - break; - default: - newCommand.assign(""); - } - break; - default: // Should not happen - return DEVICE_OK; - } - } - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, newCommand.c_str(), false) ); - } - return DEVICE_OK; -} - - -int OxxiusLaserBoxx::OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - unsigned int querySlot = NO_SLOT; - - if (eAct == MM::BeforeGet) { - std::string query; - - // The slot and command depend on the model - switch (model_[0]) { - case 1: // LBX model: retreiving the modulation state - querySlot = slot_; - query = "?AM"; - break; - case 2: // LCX model: retreiving the modulation state - querySlot = NO_SLOT; - switch (model_[1]) { - case 1: - query = "AOM1 AM"; - break; - case 2: - query = "AOM2 AM"; - break; - default: - query = ""; - } - break; - default: // Should not happen - return DEVICE_OK; - } - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, query.c_str(), false) ); - bool digiM; - parentHub_->ParseforBoolean(digiM); - - if (digiM) { - digitalMod_.assign("ON"); - } else { - digitalMod_.assign("OFF"); - } - pProp->Set(digitalMod_.c_str()); - - } else if (eAct == MM::AfterSet) { - std::ostringstream newCommand; - - - - switch (model_[0]) { - case 1: // LBX model: setting the modulation on - querySlot = slot_; - newCommand << "AM "; - break; - case 2: // LCX model: setting the modulation on - querySlot = NO_SLOT; - switch (model_[1]) { - case 1: - case 2: - newCommand << "AOM" << model_[1] << " AM "; - break; - default: // No modulation without a modulator - return DEVICE_OK; - } - break; - default: // Should not happen - return DEVICE_OK; - } - - pProp->Get(digitalMod_); - - if (digitalMod_ == "OFF") - newCommand << "0"; - else - newCommand << "1"; - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), querySlot, newCommand.str().c_str(), false) ); - } - return DEVICE_OK; -} - - -int OxxiusLaserBoxx::OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) { - unsigned int ctrlM = 1; - std::string command; - - // The slot and command depend on the model - switch (model_[0]) { - case 1: // LBX model - command = "?APC"; - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), slot_, command.c_str(), false)); - parentHub_->ParseforInteger(ctrlM); - - break; - - case 2: // LCX model -> always in APC - ctrlM = 1; - break; - - default:; // Should not happen - } - - if (ctrlM == 1) { - controlMode_.assign("APC"); - } else if (ctrlM == 0) { - controlMode_.assign("ACC"); - } - - pProp->Set(controlMode_.c_str()); - } - else if (eAct == MM::AfterSet) { - std::string newCommand; - - pProp->Get(controlMode_); - - switch (model_[0]) { - case 1: // LBX model - if (controlMode_ == "ACC") { - newCommand.assign("APC 0"); - } else if (controlMode_ == "APC") { - newCommand.assign("APC 1"); - } - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), slot_, newCommand.c_str(), false) ); - - break; - - case 2: // LCX model -> always in APC - controlMode_ = "APC"; - pProp->Set(controlMode_.c_str()); - break; - - default:; // Should not happen - } - } - return DEVICE_OK; -} - - -int OxxiusLaserBoxx::OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) { - std::string command = "?SP"; - unsigned int thisSlot = slot_; - float absSetPoint_; - - if ((10 < model_[1]) && (model_[1] < 17)) { - thisSlot = NO_SLOT; - command = "?PL"; - stringstream s; - s << (model_[1] - 10); - command += s.str(); - } - else if (model_[0] == 2) { - switch (model_[1]) { - case 1: // LCX on AOM1 - thisSlot = NO_SLOT; - command = "?SP1"; - break; - - case 2: // LCX on AOM2 - thisSlot = NO_SLOT; - command = "?SP2"; - break; - default: // LCX without AOM: identical to LBX polling - break; - } - } - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, command.c_str(), false) ); - parentHub_->ParseforFloat(absSetPoint_); - - pProp->Set( (100 * absSetPoint_) / nominalPower_ ); - } - else if (eAct == MM::AfterSet) { - - double GUISetPoint = 0.0; - pProp->Get(GUISetPoint); - - if( (GUISetPoint >= 0.0)||(GUISetPoint <= maxRelPower_) ) { - std::string command = "P"; - unsigned int thisSlot = slot_; - - std::ostringstream newCommand; - char * powerSPString = new char[20]; - strcpy(powerSPString , CDeviceUtils::ConvertToString( (GUISetPoint * nominalPower_) / 100 )); - - if ((10 < model_[1]) && (model_[1] < 17)) { - thisSlot = NO_SLOT; - command = "IP"; - command += CDeviceUtils::ConvertToString((int)(model_[1] - 10)); - - strcpy(powerSPString , CDeviceUtils::ConvertToString(GUISetPoint) ); - } - else if (model_[0] == 2) { - switch (model_[1]) { - case 1: // LCX on AOM1 - thisSlot = NO_SLOT; - command = "P"; - break; - case 2: // LCX on AOM2 - thisSlot = NO_SLOT; - command = "P2"; - break; - case 5: // LCX with power adjustment - command = "IP"; - strcpy(powerSPString , CDeviceUtils::ConvertToString(GUISetPoint) ); - break; - default: - break; - } - } - newCommand << command << " " << powerSPString; - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, newCommand.str().c_str(), false) ); - } else { - // If the value entered through the GUI is not valid, read the machine value - OnPowerSetPoint(pProp,MM::BeforeGet); - } - } - return DEVICE_OK; -} - - - -int OxxiusLaserBoxx::OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) { - float machineSetPoint = 0.0; - std::string command = "?SC"; - unsigned int thisSlot = slot_; - - if (model_[0] == 1) { // Current modification only allowed on LBX models - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, command.c_str(), false) ); - parentHub_->ParseforFloat(machineSetPoint); - } - - pProp->Set( machineSetPoint ); - } - - else if (eAct == MM::AfterSet) { - - double GUISetPoint = 0.0; - pProp->Get(GUISetPoint); - - if( (GUISetPoint >= 0.0)||(GUISetPoint <= maxCurrent_) ) { - - std::ostringstream newCommand; - std::string command = "C"; - unsigned int thisSlot = slot_; - - char * currentSPString = new char[20]; - strcpy(currentSPString , CDeviceUtils::ConvertToString(GUISetPoint) ); - - if (model_[0] == 1) { // Current modification only allowed on LBX models - newCommand << command << " " << currentSPString; - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), thisSlot, newCommand.str().c_str(), false) ); - } - } - } - return DEVICE_OK; -} - - - - -/////////////////////////////////////////////////////////////////////////////// -// -// Oxxius shutter implementation -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -/////////////////////////////////////////////////////////////////////////////// - -OxxiusShutter::OxxiusShutter(const char* nameAndSlot) : initialized_(false) -{ - isOpen_ = false; - parentHub_ = 0; - - name_.assign(nameAndSlot); - - std::string strChnl = string(nameAndSlot); - strChnl = strChnl.substr(strChnl.length()-1, 1); - channel_ = (unsigned int) atoi(strChnl.c_str()); - - // Set property list - // ----------------- - // Name (read only) - CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true); - - std::ostringstream shutterDesc; - shutterDesc << "Electro-mechanical shutter on channel " << channel_ << "."; - CreateProperty(MM::g_Keyword_Description, shutterDesc.str().c_str(), MM::String, true); - - InitializeDefaultErrorMessages(); - SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); - - // parent ID display - CreateHubIDProperty(); -} - - -OxxiusShutter::~OxxiusShutter() -{ - Shutdown(); -} - - -int OxxiusShutter::Initialize() -{ - if (!initialized_) { - parentHub_ = static_cast(GetParentHub()); - if (!parentHub_ ) { - return DEVICE_COMM_HUB_MISSING; - } - char hubLabel[MM::MaxStrLength]; - parentHub_->GetLabel(hubLabel); - SetParentID(hubLabel); // for backward compatibility - - // Set property list - // ----------------- - - // Open/Close selector (write/read) - CPropertyAction* pAct = new CPropertyAction (this, &OxxiusShutter::OnState); - RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_State, "", MM::String, false, pAct) ); - AddAllowedValue(MM::g_Keyword_State, "Open"); - AddAllowedValue(MM::g_Keyword_State, "Closed"); - - // Closing the shutter on Initialization - RETURN_ON_MM_ERROR( SetProperty(MM::g_Keyword_State, "Closed") ); - - RETURN_ON_MM_ERROR( UpdateStatus() ); - - initialized_ = true; - } - - return DEVICE_OK; -} - - -int OxxiusShutter::Shutdown() -{ - initialized_ = false; - return DEVICE_OK; -} - - -void OxxiusShutter::GetName(char* Name) const -{ - CDeviceUtils::CopyLimitedString(Name, name_.c_str()); -} - - -bool OxxiusShutter::Busy() -{ - return false; -} - - -int OxxiusShutter::SetOpen(bool openCommand) -{ - if (openCommand) - return SetProperty(MM::g_Keyword_State, "Open"); - else - return SetProperty(MM::g_Keyword_State, "Closed"); -} - - -int OxxiusShutter::GetOpen(bool& isOpen) -{ - isOpen = isOpen_; - return DEVICE_OK; -} - - -int OxxiusShutter::OnState(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) { - if (isOpen_) { - pProp->Set("Open"); - } else { - pProp->Set("Closed"); - } - } - else if (eAct == MM::AfterSet) { - - std::string newState = ""; - pProp->Get(newState); - - std::ostringstream newCommand; - newCommand << "SH" << channel_ << " "; - - if( newState.compare("Open") == 0 ) { - newCommand << "1"; - isOpen_ = true; - } else if ( newState.compare("Closed") == 0 ) { - newCommand << "0"; - isOpen_ = false; - } - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str(), false)); - } - return DEVICE_OK; -} - - - -/////////////////////////////////////////////////////////////////////////////// -// -// Oxxius M-Dual implementation -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -/////////////////////////////////////////////////////////////////////////////// - -OxxiusMDual::OxxiusMDual(const char* nameAndSlot) : initialized_(false) -{ - parentHub_ = 0; - core_ = GetCoreCallback(); - - std::string tSlot = string(nameAndSlot); - name_.assign(tSlot); // sets MDual name - - slot_ = tSlot.substr(tSlot.length() - 1, 1); - - // Set property list - // ----------------- - // Name (read only) - CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true); - - CreateProperty(MM::g_Keyword_Description, "M-Dual module", MM::String, true); - - InitializeDefaultErrorMessages(); - SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); - - // parent ID display - CreateHubIDProperty(); -} - - -OxxiusMDual::~OxxiusMDual() -{ - Shutdown(); -} - - -int OxxiusMDual::Initialize() -{ - if (!initialized_) { - parentHub_ = static_cast(GetParentHub()); - if (!parentHub_ ) { - return DEVICE_COMM_HUB_MISSING; - } - char hubLabel[MM::MaxStrLength]; - parentHub_->GetLabel(hubLabel); - SetParentID(hubLabel); // for backward compatibility - - - // Set property list - // ----------------- - CPropertyAction* pAct = new CPropertyAction(this, &OxxiusMDual::OnSetRatio);//setting the possible positions - RETURN_ON_MM_ERROR(CreateProperty("Split ratio", "0", MM::Float, false, pAct)); - SetPropertyLimits("Split ratio", 0.0, 100.0); - - // Set property list - // ----------------- - // State - /*CPropertyAction* pAct = new CPropertyAction (this, &OxxiusMDual::OnState); - RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_State, "0", MM::Integer, false, pAct) ); - SetPropertyLimits("Set Position", 0, 100);*/ - - /*char pos[3]; - for (unsigned int i=0; iQueryCommand(this, GetCoreCallback(), NO_SLOT, command.str().c_str()) ); - parentHub_->ParseforInteger(currentPos); - - //SetPosition(currentPos); - pProp->Set((long)currentPos); - } - else if (eAct == MM::AfterSet) { - long newPosition = 0; - - //GetPosition(newPosition); - pProp->Get(newPosition); - - std::ostringstream newCommand; - newCommand << "IP" << slot_ << " " << newPosition; - - RETURN_ON_MM_ERROR( parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str()) ); - } - return DEVICE_OK; -}*/ - - -int OxxiusMDual::OnSetRatio(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) { - double currentRatio = 0.0; - std::ostringstream command; - command << "IP" << slot_; - - RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, command.str().c_str(), true)); - parentHub_->ParseforPercent(currentRatio); - - pProp->Set(currentRatio); - } - - else if (eAct == MM::AfterSet) { - double newRatio = 0.0; - - pProp->Get(newRatio); - if( (newRatio >= 0.0) || (newRatio <= 100.0) ) { - std::ostringstream newCommand; - newCommand << "IP" << slot_ << " " << newRatio; - - RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str(), true)); - } - } - return DEVICE_OK; -} - -/////////////////////////////////////////////////////////////////////////////// -// -// Oxxius Flip-Mirror implementation -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -/////////////////////////////////////////////////////////////////////////////// - -OxxiusFlipMirror::OxxiusFlipMirror(const char* nameAndSlot) : initialized_(false) -{ - parentHub_ = 0; - core_ = GetCoreCallback(); - - std::string fSlot = string(nameAndSlot); - nameF_.assign(fSlot);// set laser name - fSlot = fSlot.substr(fSlot.length() - 1, 1); - slot_ = (unsigned int)atoi(fSlot.c_str());// set laser slot - - // Set property list ///////////////////////////////////////////////////////////////////////////////////////////////////// NOT WORKING? (duplicate property name Name(4)) - // ----------------- - // Name (read only) - /*CreateProperty(MM::g_Keyword_Name, nameF_.c_str(), MM::String, true); - - CreateProperty(MM::g_Keyword_Description, "Flip-Mirror module", MM::String, true); - - InitializeDefaultErrorMessages(); - SetErrorText(ERR_NO_PORT_SET, "Hub Device not found. The Laser combiner is needed to create this device"); - - // parent ID display - CreateHubIDProperty();*/ -} - - -OxxiusFlipMirror::~OxxiusFlipMirror() -{ - Shutdown(); -} - - -int OxxiusFlipMirror::Initialize() -{ - if (!initialized_) { - parentHub_ = static_cast(GetParentHub()); - if (!parentHub_) { - return DEVICE_COMM_HUB_MISSING; - } - char hubLabel[MM::MaxStrLength]; - parentHub_->GetLabel(hubLabel); - SetParentID(hubLabel); // for backward compatibility - - CPropertyAction* pAct = new CPropertyAction(this, &OxxiusFlipMirror::OnSwitchPos);//setting the possible positions - RETURN_ON_MM_ERROR(CreateProperty("Switch Position", "0", MM::Integer, false, pAct)); - SetPropertyLimits("Switch Position", 0, 1); - - std::ostringstream descriPt2; - descriPt2 << ""; - RETURN_ON_MM_ERROR(CreateProperty(MM::g_Keyword_Description, descriPt2.str().c_str(), MM::String, true)); - - // Gate, or "closed" position -// RETURN_ON_MM_ERROR( CreateProperty(MM::g_Keyword_Closed_Position, "0", MM::String, false) ); - -// isOpen_ = false; // MDual closed posisiton is - - RETURN_ON_MM_ERROR(UpdateStatus()); - - initialized_ = true; - } - - return DEVICE_OK; -} - - -int OxxiusFlipMirror::Shutdown() -{ - initialized_ = false; - return DEVICE_OK; -} - - -void OxxiusFlipMirror::GetName(char* Name) const -{ - CDeviceUtils::CopyLimitedString(Name, nameF_.c_str()); -} - - -bool OxxiusFlipMirror::Busy() -{ - return false; -} - - -int OxxiusFlipMirror::OnSwitchPos(MM::PropertyBase* pProp, MM::ActionType eAct) -{ - if (eAct == MM::BeforeGet) { - unsigned int currentPos = 0; - std::ostringstream command; - command << "FM" << slot_; - - RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, command.str().c_str(), false)); - parentHub_->ParseforInteger(currentPos); - - //SetPosition(currentPos); - pProp->Set((long)currentPos); - } - else if (eAct == MM::AfterSet) { - long newPosition = 0; - - //GetPosition(newPosition); - pProp->Get(newPosition); - - std::ostringstream newCommand; - newCommand << "FM" << slot_ << " " << newPosition; - - RETURN_ON_MM_ERROR(parentHub_->QueryCommand(this, GetCoreCallback(), NO_SLOT, newCommand.str().c_str(), false)); - } - return DEVICE_OK; -} diff --git a/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.h b/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.h deleted file mode 100644 index e31480a1a..000000000 --- a/DeviceAdapters/OxxiusCombiner/Oxxius_combiner.h +++ /dev/null @@ -1,349 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// FILE: OxxiusCombiner.h -// PROJECT: Micro-Manager -// SUBSYSTEM: DeviceAdapters -//----------------------------------------------------------------------------- -// DESCRIPTION: Controls Oxxius combiners through a serial interface -// COPYRIGHT: Oxxius SA, 2013-2018 -// LICENSE: LGPL -// AUTHOR: Tristan Martinez -// - -#ifndef _OXXIUS_COMBINER_H_ -#define _OXXIUS_COMBINER_H_ - -#include "MMDevice.h" -#include "DeviceBase.h" -#include "ModuleInterface.h" -#include -#include -#include - - -////////////////////////////////////////////////////////////////////////////// -// Error codes -// -#define ERR_PORT_CHANGE_FORBIDDEN 101 -#define ERR_NO_PORT_SET 102 -#define ERR_COMBINER_NOT_FOUND 201 -#define ERR_UNSUPPORTED_VERSION 202 - -////////////////////////////////////////////////////////////////////////////// -// Miscellaneous definitions -// -// Use the name 'return_value' that is unlikely to appear within 'result'. -#define RETURN_ON_MM_ERROR( result ) do { \ - int return_value = (result); \ - if (return_value != DEVICE_OK) { \ - return return_value; \ - } \ -} while (0) - - -////////////////////////////////////////////////////////////////////////////// -// Defining device adaptaters -// - -class OxxiusCombinerHub: public HubBase -{ -public: - OxxiusCombinerHub(); - ~OxxiusCombinerHub(); - - // MMDevice API - // ------------ - int Initialize(); - int Shutdown(); - - void GetName(char* pszName) const; - bool Busy(); - int DetectInstalledDevices(); - unsigned int GetNumberOfInstalledDevices() {return installedDevices_;}; -// MM::DeviceDetectionStatus DetectDevice(void); - bool SupportsDeviceDetection(void) {return true;}; - - - // Property handlers - int OnPort(MM::PropertyBase* pPropt, MM::ActionType eAct); - int OnSerialNumber(MM::PropertyBase* pPropt, MM::ActionType eAct); - int OnInterlock(MM::PropertyBase* pPropt, MM::ActionType eAct); - int OnEmissionKey(MM::PropertyBase* pPropt, MM::ActionType eAct); - - // Custom interface for child devices -// bool IsPortAvailable() {return portAvailable_;} - int QueryCommand(MM::Device* device, MM::Core* core, const unsigned int destinationSlot, const char* command, bool adco); - int ParseforBoolean(bool &destBoolean); - int ParseforFloat(float &destFloat); - int ParseforInteger(unsigned int &destInteger); - int ParseforString(std::string &destString); - int ParseforVersion(unsigned int &Vval); - int ParseforPercent(double &Pval); - int ParseforChar(char* Nval); - // int TempAdminInt(const char* com); - // int TempAdminString(int com, std::string &res); - - bool GetAOMpos1(unsigned int slot); - bool GetAOMpos2(unsigned int slot); - bool GetMPA(unsigned int slot); - int GetObPos(); - -private: - void LogError(int id, MM::Device* device, MM::Core* core, const char* functionName); - - std::string port_; - bool initialized_; - unsigned int installedDevices_; - - std::string serialAnswer_; - - std::string serialNumber_; - bool interlockClosed_; - bool keyActivated_; - - unsigned int AOM1pos_; - unsigned int AOM2pos_; - unsigned int mpa[7]; - unsigned int obPos_; -}; - -////////////////////////////////////////////////////////////////////////////// -// -// Device adaptaters for "LaserBoxx" source -// -////////////////////////////////////////////////////////////////////////////// - -class OxxiusLaserBoxx: public CShutterBase -{ -public: - OxxiusLaserBoxx(const char* nameAndSlot); - ~OxxiusLaserBoxx(); - - // MMDevice API - // ------------ - int Initialize(); - int Shutdown(); - - void GetName(char* pszName) const; - bool Busy(); - - int SetOpen(bool openCommand = true); - int GetOpen(bool& isOpen); - int Fire(double /*deltaT*/) { return DEVICE_UNSUPPORTED_COMMAND; } -// int LaserOnOff(int); - - // Action interface - // ---------------- -// int OnPower(MM::PropertyBase* pProp, MM::ActionType eAct); -// int OnCurrent(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct); - - int OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct); - - int OnState(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnAlarm(MM::PropertyBase* pProp, MM::ActionType eAct); -// int OnHours(MM::PropertyBase* pProp, MM::ActionType eAct); - - unsigned int aomp1; - unsigned int aomp2; - -private: - std::string name_; - unsigned int slot_; - unsigned int model_[2]; - OxxiusCombinerHub* parentHub_; - bool initialized_; - bool busy_; - - // double powerSetPoint_; - // double currentSetPoint_; - float maxRelPower_; - float nominalPower_; - float maxCurrent_; - unsigned int waveLength; - std::string type; - - - bool laserOn_; - std::string state_; - std::string alarm_; -// std::string serialNumber_; -// std::string softVersion_; - std::string controlMode_; - std::string analogMod_; - std::string digitalMod_; -}; - -////////////////////////////////////////////////////////////////////////////// -// -// Device adaptaters for "Obis" source in Combiner -// -////////////////////////////////////////////////////////////////////////////// -/* -class OxxiusObisSupport : public CShutterBase -{ -public: - OxxiusObisSupport(const char* nameAndSlot); - ~OxxiusObisSupport(); - - // MMDevice API - // ------------ - int Initialize(); - int Shutdown(); - - void GetName(char* pszName) const; - bool Busy(); - - int SetOpen(bool openCommand = true); - int GetOpen(bool& isOpen); - int Fire(double ) { return DEVICE_UNSUPPORTED_COMMAND; } - // int LaserOnOff(int); - - // Action interface - // ---------------- - // int OnPower(MM::PropertyBase* pProp, MM::ActionType eAct); - // int OnCurrent(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnPowerSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnCurrentSetPoint(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnEmissionOnOff(MM::PropertyBase* pProp, MM::ActionType eAct); - - int OnControlMode(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnAnalogMod(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnDigitalMod(MM::PropertyBase* pProp, MM::ActionType eAct); - - int OnState(MM::PropertyBase* pProp, MM::ActionType eAct); - int OnAlarm(MM::PropertyBase* pProp, MM::ActionType eAct); - // int OnHours(MM::PropertyBase* pProp, MM::ActionType eAct); - - unsigned int aomp1; - unsigned int aomp2; - -private: - std::string name_; - unsigned int slot_; - unsigned int model_[2]; - OxxiusCombinerHub* parentHub_; - bool initialized_; - bool busy_; - - double powerSetPoint_; - double currentSetPoint_; - unsigned int maxPower_; - unsigned int waveLength; - std::string type; - // double maxCurrent_; - - - bool laserOn_; - std::string state_; - std::string alarm_; - // std::string serialNumber_; - // std::string softVersion_; - std::string controlMode_; - std::string analogMod_; - std::string digitalMod_; -}; -*/ -////////////////////////////////////////////////////////////////////////////// -// -// Device adaptaters for "shutter" source in Combiner -// -////////////////////////////////////////////////////////////////////////////// - -class OxxiusShutter: public CShutterBase -{ -public: - OxxiusShutter(const char* nameAndChannel); - ~OxxiusShutter(); - - // MMDevice API - // ------------ - int Initialize(); - int Shutdown(); - - void GetName(char* pszName) const; - bool Busy(); - - // Shutter API - int SetOpen(bool openCommand = true); - int GetOpen(bool& isOpen); - int Fire(double /*deltaT*/) { return DEVICE_UNSUPPORTED_COMMAND; } - - // Action Interface - // ---------------- - int OnState(MM::PropertyBase* pProp, MM::ActionType eAct); - -private: - bool initialized_; - std::string name_; - - OxxiusCombinerHub* parentHub_; - bool isOpen_; - unsigned int channel_; - - MM::MMTime changedTime_; -}; - - -class OxxiusMDual: public CGenericBase -{ -public: - OxxiusMDual(const char* name); - ~OxxiusMDual(); - - // MMDevice API - // ------------ - int Initialize(); - int Shutdown(); - - void GetName(char* pszName) const; - bool Busy(); - - // Action Interface - // ---------------- - int OnSetRatio(MM::PropertyBase* pProp, MM::ActionType eAct); - -private: - bool initialized_; - std::string name_; - std::string slot_; - MM::Core* core_; - - OxxiusCombinerHub* parentHub_; -}; - - -class OxxiusFlipMirror : public CGenericBase -{ -public: - OxxiusFlipMirror(const char* name); - ~OxxiusFlipMirror(); - - // MMDevice API - // ------------ - int Initialize(); - int Shutdown(); - - void GetName(char* pszName) const; - bool Busy(); - //unsigned long GetNumberOfPositions()const { return numPos_; } - - // Action Interface - // ---------------- - int OnSwitchPos(MM::PropertyBase* pProp, MM::ActionType eAct); - - -private: - bool initialized_; - std::string nameF_; - unsigned int slot_; - MM::Core* core_; - - OxxiusCombinerHub* parentHub_; - - unsigned long numPos_; -}; -#endif // _OXXIUS_COMBINER_H_ \ No newline at end of file From c36577224edf2ae29511fb56aed6f0185af9cf70 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Mon, 25 Sep 2023 15:42:10 -0500 Subject: [PATCH 2/4] OxxiusCombiner: Clean up #includes Remove FixSnprintf.h, which is no longer available or needed. Include only the necessary headers from MMDevice, and let the build system set the path. --- DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp | 3 +++ DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h | 7 ++----- DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp | 1 - DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h | 4 +--- DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp | 1 - DeviceAdapters/OxxiusCombiner/OxxiusMDual.h | 4 +--- DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp | 1 - DeviceAdapters/OxxiusCombiner/OxxiusShutter.h | 4 +--- 8 files changed, 8 insertions(+), 17 deletions(-) diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp index 73872ee42..9f6f3f9cf 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp +++ b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp @@ -7,6 +7,9 @@ #include "OxxiusLCX.h" #include "CoherentObis.h" #include "Cobolt08_01.h" + +#include "ModuleInterface.h" + using namespace std; diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h index de99211c7..117001914 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h +++ b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.h @@ -1,7 +1,5 @@ #pragma once -#include "../../MMDevice/MMDevice.h" -#include "../../MMDevice/DeviceBase.h" -#include "../../MMDevice/ModuleInterface.h" +#include "DeviceBase.h" #include #include #include @@ -18,8 +16,7 @@ using namespace std; #ifdef WIN32 #include #endif -#include "../../MMDevice/DeviceUtils.h" -#include "FixSnprintf.h" +#include "DeviceUtils.h" #include #include // diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp index cddb613e8..1cd2a3345 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp +++ b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.cpp @@ -4,7 +4,6 @@ #include #include #include -#include "../../MMDevice/ModuleInterface.h" using namespace std; diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h index 250e5e3fb..80d781372 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h +++ b/DeviceAdapters/OxxiusCombiner/OxxiusFlipMirror.h @@ -2,9 +2,7 @@ #include "OxxiusCombinerHub.h" -#include "../../MMDevice/MMDevice.h" -#include "../../MMDevice/DeviceBase.h" -#include "../../MMDevice/ModuleInterface.h" +#include "DeviceBase.h" #include #include #include diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp index cb4b5ab36..7360b3a11 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp +++ b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.cpp @@ -4,7 +4,6 @@ #include #include #include -#include "../../MMDevice/ModuleInterface.h" using namespace std; /////////////////////////////////////////////////////////////////////////////// diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusMDual.h b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.h index b610a44ad..e3a769de8 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusMDual.h +++ b/DeviceAdapters/OxxiusCombiner/OxxiusMDual.h @@ -2,9 +2,7 @@ #include "OxxiusCombinerHub.h" -#include "../../MMDevice/MMDevice.h" -#include "../../MMDevice/DeviceBase.h" -#include "../../MMDevice/ModuleInterface.h" +#include "DeviceBase.h" #include #include #include diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp index ffad899cc..b985b1db7 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp +++ b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.cpp @@ -4,7 +4,6 @@ #include #include #include -#include "../../MMDevice/ModuleInterface.h" using namespace std; /////////////////////////////////////////////////////////////////////////////// diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusShutter.h b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.h index e637e98c9..8ce63db4b 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusShutter.h +++ b/DeviceAdapters/OxxiusCombiner/OxxiusShutter.h @@ -2,9 +2,7 @@ #include "OxxiusCombinerHub.h" -#include "../../MMDevice/MMDevice.h" -#include "../../MMDevice/DeviceBase.h" -#include "../../MMDevice/ModuleInterface.h" +#include "DeviceBase.h" #include #include #include From 936fac9320c980bb2db6b671043d2011eb749930 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Mon, 25 Sep 2023 15:43:22 -0500 Subject: [PATCH 3/4] OxxiusCombiner: Update MMTime usage Required to compile with current MMDevice. --- DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp index 9f6f3f9cf..107c38b35 100644 --- a/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp +++ b/DeviceAdapters/OxxiusCombiner/OxxiusCombinerHub.cpp @@ -585,12 +585,12 @@ int OxxiusCombinerHub::QueryCommand(MM::Device* device, MM::Core* core, const un // Keep track of how often we tried int counter = 1; bool done = false; - MM::MMTime startTime(core->GetCurrentMMTime()); // Let's keep in mind that MMTime is counted in microseconds + MM::MMTime startTime(GetCurrentMMTime()); while (!done) { counter++; ret = core->GetSerialAnswer(device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r\n"); - if ((ret == DEVICE_OK) || ((core->GetCurrentMMTime() - startTime) > (maxTimeMs * 1000.0))) + if ((ret == DEVICE_OK) || ((GetCurrentMMTime() - startTime) > MM::MMTime::fromMs(maxTimeMs))) done = true; else { CDeviceUtils::SleepMs(delayMs); From 43c1ac0e311c44592545e696e6e6e59ffac67469 Mon Sep 17 00:00:00 2001 From: "Mark A. Tsuchida" Date: Mon, 25 Sep 2023 15:44:16 -0500 Subject: [PATCH 4/4] OxxiusCombiner: Add LGPL license --- DeviceAdapters/OxxiusCombiner/license.txt | 142 ++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 DeviceAdapters/OxxiusCombiner/license.txt diff --git a/DeviceAdapters/OxxiusCombiner/license.txt b/DeviceAdapters/OxxiusCombiner/license.txt new file mode 100644 index 000000000..56b20e458 --- /dev/null +++ b/DeviceAdapters/OxxiusCombiner/license.txt @@ -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 \ No newline at end of file