diff --git a/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtccontext.cpp b/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtccontext.cpp index 0b910e80..a4738812 100644 --- a/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtccontext.cpp +++ b/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtccontext.cpp @@ -1132,8 +1132,8 @@ void CRTCContext::AddMicrovectorMovement(const LibMCDriver_ScanLab_uint64 nMicro int32_t intX = (int32_t)dX; int32_t intY = (int32_t)dY; - int32_t intDelayLaserOn = -1; - int32_t intDelayLaserOff = -1; + int32_t intDelayLaserOn = pMicroVector->m_LaserOnDelay == -1.0 ? -1 : round( pMicroVector->m_LaserOnDelay * 100000); + int32_t intDelayLaserOff = pMicroVector->m_LaserOffDelay == -1.0 ? -1 : round(pMicroVector->m_LaserOffDelay * 100000); m_pScanLabSDK->n_micro_vector_abs(m_CardNo, intX, intY, intDelayLaserOn, intDelayLaserOff); diff --git a/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtcrecordinginstance.cpp b/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtcrecordinginstance.cpp index 202ad822..f2122586 100644 --- a/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtcrecordinginstance.cpp +++ b/Drivers/ScanLab/Implementation/libmcdriver_scanlab_rtcrecordinginstance.cpp @@ -641,6 +641,7 @@ void CRTCRecordingInstance::disableRecording() } +#include void CRTCRecordingInstance::readRecordedDataBlockFromRTC(uint32_t DataStart, uint32_t DataEnd) { @@ -737,7 +738,8 @@ void CRTCRecordingInstance::executeListWithRecording() } else { - if (!MesBusy) { + //if (!MesBusy) { + if (!Busy) { readRecordedDataBlockFromRTC(LastPosition, MesPosition); LastPosition = MesPosition; } @@ -747,7 +749,8 @@ void CRTCRecordingInstance::executeListWithRecording() m_pSDK->n_measurement_status(m_CardNo, &MesBusy, &MesPosition); - } while (MesBusy || (MesPosition != LastPosition)); // Wait for the job to be finished executing + } while (Busy || (MesPosition != LastPosition)); // Wait for the job to be finished executing + //} while (MesBusy || (MesPosition != LastPosition)); // Wait for the job to be finished executing } diff --git a/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml b/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml index a95e7d54..ec5e246f 100644 --- a/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml +++ b/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml @@ -108,7 +108,7 @@ - + @@ -332,6 +332,10 @@ Custom implementation + + + + diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h index c22afe7c..e2d40171 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h @@ -252,6 +252,17 @@ typedef LibMCDriver_ScanLabSMCResult (*PLibMCDriver_ScanLabSMCSMCJob_StopExecuti */ typedef LibMCDriver_ScanLabSMCResult (*PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationDataPtr) (LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pSimulationDataTable); +/** +* Returns raw simulation data. +* +* @param[in] pSMCJob - SMCJob instance. +* @param[in] nDataBufferSize - Number of elements in buffer +* @param[out] pDataNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pDataBuffer - uint8 buffer of Raw binary simulation data. +* @return error code or 0 (success) +*/ +typedef LibMCDriver_ScanLabSMCResult (*PLibMCDriver_ScanLabSMCSMCJob_LoadRawSimulationDataPtr) (LibMCDriver_ScanLabSMC_SMCJob pSMCJob, const LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8 * pDataBuffer); + /** * Returns a characteristic value of a job. * @@ -874,6 +885,7 @@ typedef struct { PLibMCDriver_ScanLabSMCSMCJob_WaitForExecutionPtr m_SMCJob_WaitForExecution; PLibMCDriver_ScanLabSMCSMCJob_StopExecutionPtr m_SMCJob_StopExecution; PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationDataPtr m_SMCJob_LoadSimulationData; + PLibMCDriver_ScanLabSMCSMCJob_LoadRawSimulationDataPtr m_SMCJob_LoadRawSimulationData; PLibMCDriver_ScanLabSMCSMCJob_GetJobCharacteristicPtr m_SMCJob_GetJobCharacteristic; PLibMCDriver_ScanLabSMCSMCJob_GetJobDurationPtr m_SMCJob_GetJobDuration; PLibMCDriver_ScanLabSMCSMCJob_ExecuteLaserInitSequencePtr m_SMCJob_ExecuteLaserInitSequence; diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp index c0028e96..cb0a095a 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp @@ -244,6 +244,7 @@ class ELibMCDriver_ScanLabSMCException : public std::exception { case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "CSVPARSERUNKNOWNFIELDPARSERTYPE"; case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "CSVPARSERINTERPOLATEINDEXOUTOFRANGE"; case LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDMAXPOWERVALUE: return "INVALIDMAXPOWERVALUE"; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONWORKINGFILEISNOTINITIALIZED: return "SIMULATIONWORKINGFILEISNOTINITIALIZED"; } return "UNKNOWN"; } @@ -318,6 +319,7 @@ class ELibMCDriver_ScanLabSMCException : public std::exception { case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "Unknown Field Parser Type."; case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "Index out of range in Interpolate."; case LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDMAXPOWERVALUE: return "Invalid max power value."; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONWORKINGFILEISNOTINITIALIZED: return "Simulation working file is not initialized."; } return "unknown error"; } @@ -554,6 +556,7 @@ class CSMCJob : public CBase { inline void WaitForExecution(const LibMCDriver_ScanLabSMC_uint32 nTimeOutInMilliseconds); inline void StopExecution(); inline void LoadSimulationData(classParam pSimulationDataTable); + inline void LoadRawSimulationData(std::vector & DataBuffer); inline LibMCDriver_ScanLabSMC_double GetJobCharacteristic(const eJobCharacteristic eValueType); inline LibMCDriver_ScanLabSMC_double GetJobDuration(); inline void ExecuteLaserInitSequence(); @@ -798,6 +801,7 @@ class CDriver_ScanLabSMC : public CDriver { pWrapperTable->m_SMCJob_WaitForExecution = nullptr; pWrapperTable->m_SMCJob_StopExecution = nullptr; pWrapperTable->m_SMCJob_LoadSimulationData = nullptr; + pWrapperTable->m_SMCJob_LoadRawSimulationData = nullptr; pWrapperTable->m_SMCJob_GetJobCharacteristic = nullptr; pWrapperTable->m_SMCJob_GetJobDuration = nullptr; pWrapperTable->m_SMCJob_ExecuteLaserInitSequence = nullptr; @@ -1079,6 +1083,15 @@ class CDriver_ScanLabSMC : public CDriver { if (pWrapperTable->m_SMCJob_LoadSimulationData == nullptr) return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 + pWrapperTable->m_SMCJob_LoadRawSimulationData = (PLibMCDriver_ScanLabSMCSMCJob_LoadRawSimulationDataPtr) GetProcAddress(hLibrary, "libmcdriver_scanlabsmc_smcjob_loadrawsimulationdata"); + #else // _WIN32 + pWrapperTable->m_SMCJob_LoadRawSimulationData = (PLibMCDriver_ScanLabSMCSMCJob_LoadRawSimulationDataPtr) dlsym(hLibrary, "libmcdriver_scanlabsmc_smcjob_loadrawsimulationdata"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_SMCJob_LoadRawSimulationData == nullptr) + return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 pWrapperTable->m_SMCJob_GetJobCharacteristic = (PLibMCDriver_ScanLabSMCSMCJob_GetJobCharacteristicPtr) GetProcAddress(hLibrary, "libmcdriver_scanlabsmc_smcjob_getjobcharacteristic"); #else // _WIN32 @@ -1711,6 +1724,10 @@ class CDriver_ScanLabSMC : public CDriver { if ( (eLookupError != 0) || (pWrapperTable->m_SMCJob_LoadSimulationData == nullptr) ) return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("libmcdriver_scanlabsmc_smcjob_loadrawsimulationdata", (void**)&(pWrapperTable->m_SMCJob_LoadRawSimulationData)); + if ( (eLookupError != 0) || (pWrapperTable->m_SMCJob_LoadRawSimulationData == nullptr) ) + return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("libmcdriver_scanlabsmc_smcjob_getjobcharacteristic", (void**)&(pWrapperTable->m_SMCJob_GetJobCharacteristic)); if ( (eLookupError != 0) || (pWrapperTable->m_SMCJob_GetJobCharacteristic == nullptr) ) return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; @@ -2187,6 +2204,19 @@ class CDriver_ScanLabSMC : public CDriver { CheckError(m_pWrapper->m_WrapperTable.m_SMCJob_LoadSimulationData(m_pHandle, hSimulationDataTable)); } + /** + * CSMCJob::LoadRawSimulationData - Returns raw simulation data. + * @param[out] DataBuffer - Raw binary simulation data. + */ + void CSMCJob::LoadRawSimulationData(std::vector & DataBuffer) + { + LibMCDriver_ScanLabSMC_uint64 elementsNeededData = 0; + LibMCDriver_ScanLabSMC_uint64 elementsWrittenData = 0; + CheckError(m_pWrapper->m_WrapperTable.m_SMCJob_LoadRawSimulationData(m_pHandle, 0, &elementsNeededData, nullptr)); + DataBuffer.resize((size_t) elementsNeededData); + CheckError(m_pWrapper->m_WrapperTable.m_SMCJob_LoadRawSimulationData(m_pHandle, elementsNeededData, &elementsWrittenData, DataBuffer.data())); + } + /** * CSMCJob::GetJobCharacteristic - Returns a characteristic value of a job. * @param[in] eValueType - Type of job diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp index 487a3b34..8cc4bb7d 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp @@ -162,6 +162,7 @@ typedef void * LibMCDriver_ScanLabSMC_pvoid; #define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE 1054 /** Unknown Field Parser Type. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE 1055 /** Index out of range in Interpolate. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDMAXPOWERVALUE 1056 /** Invalid max power value. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONWORKINGFILEISNOTINITIALIZED 1057 /** Simulation working file is not initialized. */ /************************************************************************************************************************* Error strings for LibMCDriver_ScanLabSMC @@ -236,6 +237,7 @@ inline const char * LIBMCDRIVER_SCANLABSMC_GETERRORSTRING (LibMCDriver_ScanLabSM case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "Unknown Field Parser Type."; case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "Index out of range in Interpolate."; case LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDMAXPOWERVALUE: return "Invalid max power value."; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONWORKINGFILEISNOTINITIALIZED: return "Simulation working file is not initialized."; default: return "unknown error"; } } diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.cpp index 493ea62f..532dd175 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.cpp @@ -252,6 +252,9 @@ CScanLabSMCSDK::CScanLabSMCSDK(const std::string& sDLLNameUTF8, const std::strin this->ptr_slsc_job_write_digital_x = (PScanLabSMCPtr_slsc_job_write_digital_x)_loadScanLabSMCAddress(hLibrary, "slsc_job_write_digital_x"); this->ptr_slsc_job_write_digital_mask_x = (PScanLabSMCPtr_slsc_job_write_digital_mask_x)_loadScanLabSMCAddress(hLibrary, "slsc_job_write_digital_mask_x"); + this->ptr_slsc_cfg_register_callback_job_calculated = (PScanLabSMCPtr_slsc_cfg_register_callback_job_calculated)_loadScanLabSMCAddress(hLibrary, "slsc_cfg_register_callback_job_calculated"); + this->ptr_slsc_job_begin_module = (PScanLabSMCPtr_slsc_job_begin_module)_loadScanLabSMCAddress(hLibrary, "slsc_job_begin_module"); + m_LibraryHandle = (void*) hLibrary; } @@ -695,6 +698,22 @@ slscReturnValue CScanLabSMCSDK::slsc_job_write_digital_mask_x(size_t Handle, sls return this->ptr_slsc_job_write_digital_mask_x(Handle, Channel, Mask, Value, TimeDelay); } +slscReturnValue CScanLabSMCSDK::slsc_cfg_register_callback_job_calculated(size_t Handle, slsc_JobCallback Callback, void* Context) +{ + if (m_pLogJournal.get() != nullptr) + m_pLogJournal->logCall("slsc_cfg_register_callback_job_calculated", std::to_string(Handle) + ", " + std::to_string(intptr_t(Callback)) + ", " + std::to_string(intptr_t(Context))); + + return this->ptr_slsc_cfg_register_callback_job_calculated(Handle, Callback, Context); +} + +slscReturnValue CScanLabSMCSDK::slsc_job_begin_module(size_t Handle, size_t* JobID, const double* StartPosition, const char* ModuleFileName) +{ + if (m_pLogJournal.get() != nullptr) + m_pLogJournal->logCall("slsc_job_begin_module", std::to_string(Handle) + ", &" + std::to_string(intptr_t(JobID)) + ", [" + std::to_string(StartPosition[0]) + ", " + std::to_string(StartPosition[1]) + "], " + std::string(ModuleFileName)); + + return this->ptr_slsc_job_begin_module(Handle, JobID, StartPosition, ModuleFileName); +} + void CScanLabSMCSDK::setJournal(PScanLabSMCSDKJournal pLogJournal) { m_pLogJournal = pLogJournal; diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.hpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.hpp index 1da7abf1..a7d46e23 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.hpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_sdk.hpp @@ -260,6 +260,11 @@ namespace LibMCDriver_ScanLabSMC { typedef slscReturnValue(SCANLABSMC_CALLINGCONVENTION* PScanLabSMCPtr_slsc_job_write_digital_x) (size_t Handle, slsc_DigitalOutput Channel, uint16_t Value, double TimeDelay); typedef slscReturnValue(SCANLABSMC_CALLINGCONVENTION* PScanLabSMCPtr_slsc_job_write_digital_mask_x) (size_t Handle, slsc_DigitalOutput Channel, uint16_t Mask, uint16_t Value, double TimeDelay); + typedef void (*slsc_JobCallback)(size_t JobID, void* Context); + typedef slscReturnValue(SCANLABSMC_CALLINGCONVENTION* PScanLabSMCPtr_slsc_cfg_register_callback_job_calculated) (size_t Handle, slsc_JobCallback Callback, void* Context); + + typedef slscReturnValue(SCANLABSMC_CALLINGCONVENTION* PScanLabSMCPtr_slsc_job_begin_module) (size_t Handle, size_t* JobID, const double* StartPosition, const char* ModuleFileName); + class CScanLabSMCSDKJournal { private: std::map m_DefinedVariables; @@ -298,6 +303,8 @@ namespace LibMCDriver_ScanLabSMC { }; typedef std::shared_ptr PScanLabSMCSDK_DLLDirectoryCache; + //typedef void (*slsc_ExecTimeCallback)(size_t JobID, double ExecTime, void* Context); + typedef void (*slsc_JobCallback)(size_t JobID, void* Context); class CScanLabSMCSDK { private: @@ -350,6 +357,8 @@ namespace LibMCDriver_ScanLabSMC { PScanLabSMCPtr_slsc_ctrl_write_digital_mask_x ptr_slsc_ctrl_write_digital_mask_x = nullptr; PScanLabSMCPtr_slsc_job_write_digital_x ptr_slsc_job_write_digital_x = nullptr; PScanLabSMCPtr_slsc_job_write_digital_mask_x ptr_slsc_job_write_digital_mask_x = nullptr; + PScanLabSMCPtr_slsc_cfg_register_callback_job_calculated ptr_slsc_cfg_register_callback_job_calculated = nullptr; + PScanLabSMCPtr_slsc_job_begin_module ptr_slsc_job_begin_module = nullptr; public: @@ -413,6 +422,8 @@ namespace LibMCDriver_ScanLabSMC { slscReturnValue slsc_job_write_digital_x(size_t Handle, slsc_DigitalOutput Channel, uint16_t Value, double TimeDelay); slscReturnValue slsc_job_write_digital_mask_x(size_t Handle, slsc_DigitalOutput Channel, uint16_t Mask, uint16_t Value, double TimeDelay); + slscReturnValue slsc_cfg_register_callback_job_calculated(size_t Handle, slsc_JobCallback Callback, void* Context); + slscReturnValue slsc_job_begin_module(size_t Handle, size_t* JobID, const double* StartPosition, const char* ModuleFileName); }; diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp index 349f66f8..dfba61c3 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp @@ -132,6 +132,11 @@ void CSMCJob::LoadSimulationData(LibMCEnv::PDataTable pSimulationDataTable) m_pJobInstance->ReadSimulationFile(pSimulationDataTable); } +void CSMCJob::LoadRawSimulationData(LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8* pDataBuffer) +{ + m_pJobInstance->LoadRawSimulationData(nDataBufferSize, pDataNeededCount, pDataBuffer); +} + LibMCDriver_ScanLabSMC_double CSMCJob::GetJobCharacteristic(const LibMCDriver_ScanLabSMC::eJobCharacteristic eValueType) { return m_pJobInstance->GetJobCharacteristic (eValueType); diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp index 5ef02a9c..ffccd409 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp @@ -96,6 +96,8 @@ class CSMCJob : public virtual ISMCJob, public virtual CBase { void LoadSimulationData(LibMCEnv::PDataTable pSimulationDataTable) override; + void LoadRawSimulationData(LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8* pDataBuffer) override; + LibMCDriver_ScanLabSMC_double GetJobCharacteristic(const LibMCDriver_ScanLabSMC::eJobCharacteristic eValueType) override; LibMCDriver_ScanLabSMC_double GetJobDuration() override; diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp index be46e892..f5e1e2f9 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp @@ -45,7 +45,7 @@ Abstract: This is a stub class definition of CSMCJob #include #include #include -//#include +#include #include using namespace LibMCDriver_ScanLabSMC::Impl; @@ -65,32 +65,45 @@ CSMCJobInstance::CSMCJobInstance(PSMCContextHandle pContextHandle, double dStart m_bSendToHardware (bSendToHardware), m_dMaxPowerInWatts (dMaxPowerInWatts) { - - - - if (m_pWorkingDirectory.get() == nullptr) throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); if (m_pContextHandle.get() == nullptr) throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); - m_pSDK = m_pContextHandle->getSDK(); + m_pSDK = m_pContextHandle->getSDK(); auto contextHandle = m_pContextHandle->getHandle(); - // Initialize digital output to 0 - m_pSDK->checkError(contextHandle, m_pSDK->slsc_ctrl_write_digital_x(contextHandle, slsc_DigitalOutput::slsc_DigitalOutput_1, 0)); - - // Begin job - m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_begin(contextHandle, &m_JobID)); - - // Set digital output to 1 - m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_write_digital_x(contextHandle, slsc_DigitalOutput::slsc_DigitalOutput_1, 1, 0 ) ); + if (m_bSendToHardware) { - slsc_RecordSet eRecordSetA = slsc_RecordSet::slsc_RecordSet_SetPositions; - slsc_RecordSet eRecordSetB = slsc_RecordSet::slsc_RecordSet_LaserSwitches; + // Initialize digital output to 0 + m_pSDK->checkError(contextHandle, m_pSDK->slsc_ctrl_write_digital_x(contextHandle, slsc_DigitalOutput::slsc_DigitalOutput_1, 0)); + + // Begin job + m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_begin(contextHandle, &m_JobID)); + + // Set digital output to 1 + m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_write_digital_x(contextHandle, slsc_DigitalOutput::slsc_DigitalOutput_1, 1, 0)); + + slsc_RecordSet eRecordSetA = slsc_RecordSet::slsc_RecordSet_SetPositions; + slsc_RecordSet eRecordSetB = slsc_RecordSet::slsc_RecordSet_LaserSwitches; + + m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_start_record(contextHandle, eRecordSetA, eRecordSetB)); + } + else + { + // To start Module recording at start position (0,0). + size_t JobID = 0; + double StartPosition[2] = { 0.0, 0.0 }; + + m_tmpSimulationFile = m_pWorkingDirectory->AddManagedTempFile("slm"); + + auto sSimulationFileName = m_tmpSimulationFile->GetAbsoluteFileName(); + + std::cout << "Starting planning layer : module file name : " << sSimulationFileName << std::endl; + m_pSDK->slsc_job_begin_module(contextHandle, &JobID, StartPosition, sSimulationFileName.c_str()); + } - m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_start_record(contextHandle, eRecordSetA, eRecordSetB)); if (dMaxPowerInWatts < SCANLABSMC_MIN_MAXPOWERINWATTS || dMaxPowerInWatts > SCANLABSMC_MAX_MAXPOWERINWATTS) throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDMAXPOWERVALUE); @@ -402,7 +415,7 @@ void CSMCJobInstance::Execute(const bool bBlocking) { auto contextHandle = m_pContextHandle->getHandle(); - //std::cout << "Waiting for execution" << std::endl; + std::cout << "Waiting for execution" << std::endl; slsc_ExecState execState1 = slsc_ExecState::slsc_ExecState_NotInitOrError; while (execState1 != slsc_ExecState::slsc_ExecState_ReadyForExecution) { @@ -410,11 +423,11 @@ void CSMCJobInstance::Execute(const bool bBlocking) std::this_thread::sleep_for(std::chrono::milliseconds(1)); } - //std::cout << "Starting execution" << std::endl; + std::cout << "Starting execution" << std::endl; m_pSDK->checkError(contextHandle, m_pSDK->slsc_ctrl_start_execution(contextHandle)); - //std::cout << "Waiting for execution finished" << std::endl; + std::cout << "Waiting for execution finished" << std::endl; slsc_ExecState execState2 = slsc_ExecState::slsc_ExecState_Executing; while (execState2 == slsc_ExecState::slsc_ExecState_Executing) { @@ -422,16 +435,16 @@ void CSMCJobInstance::Execute(const bool bBlocking) std::this_thread::sleep_for(std::chrono::milliseconds(10)); } - + std::cout << "Execution is finished" << std::endl; } bool CSMCJobInstance::IsExecuting() -{ - return false; +{ + return false; } void CSMCJobInstance::WaitForExecution(const LibMCDriver_ScanLabSMC_uint32 nTimeOutInMilliseconds) -{ +{ } @@ -1052,3 +1065,21 @@ void CSMCJobInstance::AddLayerToList(LibMCEnv::PToolpathLayer pLayer) } +void CSMCJobInstance::LoadRawSimulationData(LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8* pDataBuffer) +{ + if(pDataNeededCount == nullptr) + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); + + if (m_tmpSimulationFile.get() == nullptr) + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONWORKINGFILEISNOTINITIALIZED); + + *pDataNeededCount = m_tmpSimulationFile->GetSize(); + + if (pDataBuffer) + { + std::vector tmpFileContentBuffer; + tmpFileContentBuffer.resize((size_t)nDataBufferSize); + m_tmpSimulationFile->ReadContent(tmpFileContentBuffer); + memcpy(pDataBuffer, tmpFileContentBuffer.data(), tmpFileContentBuffer.size()); + } +} \ No newline at end of file diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp index 886273e7..efd08b0d 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp @@ -65,6 +65,7 @@ class CSMCJobInstance { bool m_bSendToHardware; double m_dMaxPowerInWatts; + LibMCEnv::PWorkingFile m_tmpSimulationFile; void drawPolylineEx(slscHandle contextHandle, const uint64_t nPointsBufferSize, const LibMCDriver_ScanLabSMC::sPoint2D* pPointsBuffer, bool bIsClosed, double dPowerInWatts); void drawHatchesEx(const LibMCDriver_ScanLabSMC_uint64 nHatchesBufferSize, const LibMCDriver_ScanLabSMC::sHatch2D* pHatchesBuffer, const LibMCDriver_ScanLabSMC_double dMarkSpeed, const LibMCDriver_ScanLabSMC_double dJumpSpeed, const LibMCDriver_ScanLabSMC_double dPowerInWatts, const LibMCDriver_ScanLabSMC_double dZValue); @@ -112,6 +113,8 @@ class CSMCJobInstance { void ExecuteLaserShutdownSequence(); + void LoadRawSimulationData(LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8* pDataBuffer); + private: void ReadSimulationFile_SMC_v0_8(LibMCEnv::PDataTable pDataTable); diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp index 9a809817..7b0463af 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp @@ -265,6 +265,17 @@ LIBMCDRIVER_SCANLABSMC_DECLSPEC LibMCDriver_ScanLabSMCResult libmcdriver_scanlab */ LIBMCDRIVER_SCANLABSMC_DECLSPEC LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadsimulationdata(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pSimulationDataTable); +/** +* Returns raw simulation data. +* +* @param[in] pSMCJob - SMCJob instance. +* @param[in] nDataBufferSize - Number of elements in buffer +* @param[out] pDataNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pDataBuffer - uint8 buffer of Raw binary simulation data. +* @return error code or 0 (success) +*/ +LIBMCDRIVER_SCANLABSMC_DECLSPEC LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadrawsimulationdata(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, const LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8 * pDataBuffer); + /** * Returns a characteristic value of a job. * diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp index 65abca8a..73283199 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp @@ -435,6 +435,14 @@ class ISMCJob : public virtual IBase { */ virtual void LoadSimulationData(LibMCEnv::PDataTable pSimulationDataTable) = 0; + /** + * ISMCJob::LoadRawSimulationData - Returns raw simulation data. + * @param[in] nDataBufferSize - Number of elements in buffer + * @param[out] pDataNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pDataBuffer - uint8 buffer of Raw binary simulation data. + */ + virtual void LoadRawSimulationData(LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8 * pDataBuffer) = 0; + /** * ISMCJob::GetJobCharacteristic - Returns a characteristic value of a job. * @param[in] eValueType - Type of job diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp index d07b6923..4fa02c14 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp @@ -653,6 +653,32 @@ LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadsimulationdata(Li } } +LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadrawsimulationdata(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, const LibMCDriver_ScanLabSMC_uint64 nDataBufferSize, LibMCDriver_ScanLabSMC_uint64* pDataNeededCount, LibMCDriver_ScanLabSMC_uint8 * pDataBuffer) +{ + IBase* pIBaseClass = (IBase *)pSMCJob; + + try { + if ((!pDataBuffer) && !(pDataNeededCount)) + throw ELibMCDriver_ScanLabSMCInterfaceException (LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); + ISMCJob* pISMCJob = dynamic_cast(pIBaseClass); + if (!pISMCJob) + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDCAST); + + pISMCJob->LoadRawSimulationData(nDataBufferSize, pDataNeededCount, pDataBuffer); + + return LIBMCDRIVER_SCANLABSMC_SUCCESS; + } + catch (ELibMCDriver_ScanLabSMCInterfaceException & Exception) { + return handleLibMCDriver_ScanLabSMCException(pIBaseClass, Exception); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException); + } + catch (...) { + return handleUnhandledException(pIBaseClass); + } +} + LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_getjobcharacteristic(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, eLibMCDriver_ScanLabSMCJobCharacteristic eValueType, LibMCDriver_ScanLabSMC_double * pValue) { IBase* pIBaseClass = (IBase *)pSMCJob; @@ -2245,6 +2271,8 @@ LibMCDriver_ScanLabSMCResult LibMCDriver_ScanLabSMC::Impl::LibMCDriver_ScanLabSM *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_stopexecution; if (sProcName == "libmcdriver_scanlabsmc_smcjob_loadsimulationdata") *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_loadsimulationdata; + if (sProcName == "libmcdriver_scanlabsmc_smcjob_loadrawsimulationdata") + *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_loadrawsimulationdata; if (sProcName == "libmcdriver_scanlabsmc_smcjob_getjobcharacteristic") *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_getjobcharacteristic; if (sProcName == "libmcdriver_scanlabsmc_smcjob_getjobduration") diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp index 487a3b34..8cc4bb7d 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp @@ -162,6 +162,7 @@ typedef void * LibMCDriver_ScanLabSMC_pvoid; #define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE 1054 /** Unknown Field Parser Type. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE 1055 /** Index out of range in Interpolate. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDMAXPOWERVALUE 1056 /** Invalid max power value. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONWORKINGFILEISNOTINITIALIZED 1057 /** Simulation working file is not initialized. */ /************************************************************************************************************************* Error strings for LibMCDriver_ScanLabSMC @@ -236,6 +237,7 @@ inline const char * LIBMCDRIVER_SCANLABSMC_GETERRORSTRING (LibMCDriver_ScanLabSM case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "Unknown Field Parser Type."; case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "Index out of range in Interpolate."; case LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDMAXPOWERVALUE: return "Invalid max power value."; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONWORKINGFILEISNOTINITIALIZED: return "Simulation working file is not initialized."; default: return "unknown error"; } }