#include "stdafx.h" #include "OxfordController.h" #include "OxfordControllerWrapper.h" using namespace OTSController; int OxfordController::CreateController() { if (ManagedGlobals::oxfordController == nullptr) { ManagedGlobals::oxfordController = gcnew OxfordControllerWrapper(); } if (!ManagedGlobals::oxfordController->Init()) { return (int)OxfordWrapperErrorCode::CONTROLLER_INIT_FAILED; } if (!ManagedGlobals::oxfordController->IsConnected()) { return (int)OxfordWrapperErrorCode::CONTROLLER_NOT_CONNECTED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::IsConnected() { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->IsConnected()) { return (int)OxfordWrapperErrorCode::CONTROLLER_NOT_CONNECTED; } return (int)OxfordWrapperErrorCode::SUCCEED; } void OxfordController::CloseClient() { ManagedGlobals::oxfordController->CloseClient(); } int OxfordController::GetPositionXY(double& a_dPosX, double& a_dPosY) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetPositionXY(a_dPosX, a_dPosY)) { LogErrorTrace(__FILE__,__LINE__,_T("GetPositionXY command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetPositionXY(double a_dPosX, double a_dPosY) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetPositionXY(a_dPosX, a_dPosY)) { LogErrorTrace(__FILE__, __LINE__, _T("SetPositionXY command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::GetWorkingDistance(double& a_dWorkingDistance) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetWorkingDistance(a_dWorkingDistance)) { LogErrorTrace(__FILE__, __LINE__, _T("GetWorkingDistance command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetWorkingDistance(double a_dWorkingDistance) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetWorkingDistance(a_dWorkingDistance)) { LogErrorTrace(__FILE__, __LINE__, _T("SetWorkingDistance command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::GetMagnification(double& a_dMagnification) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetMagnification(a_dMagnification)) { LogErrorTrace(__FILE__, __LINE__, _T("GetMagnification command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetMagnification(double a_dMagnification) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetMagnification(a_dMagnification)) { LogErrorTrace(__FILE__, __LINE__, _T("SetMagnification command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::GetHighVoltage(double& a_dHighVoltage) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetHighVoltage(a_dHighVoltage)) { LogErrorTrace(__FILE__, __LINE__, _T("GetHighVoltage command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetHighVoltage(double a_dHighVoltage) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetHighVoltage(a_dHighVoltage)) { LogErrorTrace(__FILE__, __LINE__, _T("SetHighVoltage command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::GetBeamOn(bool& a_bBeamOn) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetBeamOn(a_bBeamOn)) { LogErrorTrace(__FILE__, __LINE__, _T("GetBeamOn command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetBeamOn(bool a_bBeamOn) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetBeamOn(a_bBeamOn)) { LogErrorTrace(__FILE__, __LINE__, _T("SetBeamOn command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::GetBeamBlank(bool& a_bBeamBlank) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetBeamBlank(a_bBeamBlank)) { LogErrorTrace(__FILE__, __LINE__, _T("GetBeamBlank command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetBeamBlank(bool a_bBeamBlank) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetBeamBlank(a_bBeamBlank)) { LogErrorTrace(__FILE__, __LINE__, _T("SetBeamBlank command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::GetExternal(bool& a_bExternal) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetExternalScan(a_bExternal)) { LogErrorTrace(__FILE__, __LINE__, _T("GetExternal command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetExternal(bool a_bExternal) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetExternalScan(a_bExternal)) { LogErrorTrace(__FILE__, __LINE__, _T("SetExternal command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetBeamPosition(const double a_dPosX, const double a_dPosY) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetBeamPosition(a_dPosX, a_dPosY)) { LogErrorTrace(__FILE__, __LINE__, _T("SetBeamPosition command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::CollectXrayData(const long a_nAcTime, long* a_pnCounts, unsigned long a_nBufferSize) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->CollectXrayPoint(a_nAcTime, a_pnCounts, a_nBufferSize)) { LogErrorTrace(__FILE__, __LINE__, _T("CollectXrayData command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::CollectXrayDataAtPos(const double a_dPosX, const double a_dPosY, const long a_nAcTime, long* a_pnCounts, DWORD a_nBufferSize) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->CollectXrayPoint(a_dPosX, a_dPosY, a_nAcTime, a_pnCounts, a_nBufferSize)) { LogErrorTrace(__FILE__, __LINE__, _T("CollectXrayDataAtPos command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::CollectXrayList(const long a_nAcTime, OxfordXrayData* a_pXrayDataList, const long a_nXrayDataCount, DWORD a_nBufferSize) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->CollectXrayPoints(a_nAcTime, a_pXrayDataList, a_nXrayDataCount, a_nBufferSize)) { LogErrorTrace(__FILE__, __LINE__, _T("CollectXrayList command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::CollectXrayArea(const long a_nAcTime, OxfordXrayData* a_pXrayDataList, const long a_nXrayDataCount, DWORD a_nBufferSize) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->CollectXrayArea(a_nAcTime, a_pXrayDataList, a_nXrayDataCount, a_nBufferSize)) { LogErrorTrace(__FILE__, __LINE__, _T("CollectXrayList command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetScanSpeed(const long a_nMilliseconds) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetScanSpeed(a_nMilliseconds)) { LogErrorTrace(__FILE__, __LINE__, _T("SetScanSpeed command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::GetImageSize(long& a_nWidth, long& a_nHeight) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->GetImageSize(a_nWidth, a_nHeight)) { LogErrorTrace(__FILE__, __LINE__, _T("GetImageSize command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::SetImageSize(const long a_nWidth, const long a_nHeight) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->SetImageSize(a_nWidth, a_nHeight)) { LogErrorTrace(__FILE__, __LINE__, _T("SetImageSize command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::CollectImage(unsigned char* a_pImageBits) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->CollectImage(a_pImageBits)) { LogErrorTrace(__FILE__, __LINE__, _T("CollectImage command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } int OxfordController::QuantifySpectrum(unsigned char* cResult) { if (ManagedGlobals::oxfordController == nullptr) { return (int)OxfordWrapperErrorCode::NO_VALID_CONTROLLER; } if (!ManagedGlobals::oxfordController->QuantifySpectrum(cResult)) { LogErrorTrace(__FILE__, __LINE__, _T("CollectImage command failed.")); return (int)OxfordWrapperErrorCode::COMMAND_FAILED; } return (int)OxfordWrapperErrorCode::SUCCEED; } //}