int MCL_NanoDrive_XYStage::Initialize() { // BEGIN LOCKING HandleListLock(); int err = DEVICE_OK; int possHandle = 0; bool valid = false; ProductInformation pi; memset(&pi, 0, sizeof(ProductInformation)); if (initialized_) { // If already initialized, no need to continue goto INIT_ERROR; } if(!MCL_CorrectDriverVersion()) { err = MCL_INVALID_DRIVER; goto INIT_ERROR; } int numHandles = MCL_GrabAllHandles(); if (numHandles == 0) { // No handles, i.e. no devices currently attached err = MCL_INVALID_HANDLE; goto INIT_ERROR; } int* handlesToUseOrRelease = NULL; handlesToUseOrRelease = (int*) malloc(sizeof(int*) * numHandles); MCL_GetAllHandles(handlesToUseOrRelease, numHandles); HandleListType* device = (HandleListType*)GlobalHeapAllocate(sizeof(HandleListType)); device->Initialize(possHandle, XY_TYPE); for (int i = 0; i < numHandles; i++) { possHandle = handlesToUseOrRelease[i]; device->setHandle(possHandle); MCL_GetProductInfo(&pi, possHandle); // check to see which axes are valid bool validXaxis = ((pi.axis_bitmap & VALIDX) == VALIDX); bool validYaxis = ((pi.axis_bitmap & VALIDY) == VALIDY); if ( (validXaxis && validYaxis) && (!HandleExistsOnLockedList(device)) && (possHandle > 0) ) { valid = true; HandleListAddToLockedList(device); MCLhandle_ = possHandle; // release handles not in use. for (int j = i+1; j < numHandles; j++) { possHandle = handlesToUseOrRelease[j]; if (!HandleExistsOnLockedList(possHandle) && possHandle > 0) { MCL_ReleaseHandle(possHandle); } } break; // found a valid handle, so no need to check any further } else { if (!HandleExistsOnLockedList(possHandle) && possHandle > 0) { MCL_ReleaseHandle(possHandle); } } } free (handlesToUseOrRelease); if (!valid) { GlobalHeapFree(device); err = MCL_INVALID_HANDLE; goto INIT_ERROR; } xMin_ = 0; yMin_ = 0; xMax_ = MCL_GetCalibration(XAXIS, MCLhandle_); if (xMax_ < 0) { err = (int) xMax_; goto INIT_ERROR; } yMax_ = MCL_GetCalibration(YAXIS, MCLhandle_); if (yMax_ < 0) { err = (int) yMax_; goto INIT_ERROR; } if (pi.Product_id == 0x1230 || pi.Product_id == 0x1253 || pi.Product_id == 0x2201 || pi.Product_id == 0x2203 || pi.Product_id == 0x2253) { stepSizeX_um_ = xMax_ / NUM_STEPS_20; stepSizeY_um_ = yMax_ / NUM_STEPS_20; is20Bit_ = true; } else { stepSizeX_um_ = xMax_ / NUM_STEPS_16; stepSizeY_um_ = yMax_ / NUM_STEPS_16; is20Bit_ = false; } curXpos_ = MCL_SingleReadN(XAXIS, MCLhandle_); if ((int)curXpos_ < 0) { err = (int) curXpos_; goto INIT_ERROR; } curYpos_ = MCL_SingleReadN(YAXIS, MCLhandle_); if ((int)curYpos_ < 0) { err = (int) curYpos_; goto INIT_ERROR; } serialNumber_ = MCL_GetSerialNumber(MCLhandle_); if (serialNumber_ < 0) { err = (int) serialNumber_; goto INIT_ERROR; } err = SetDeviceProperties(); if (err != DEVICE_OK) { goto INIT_ERROR; } err = UpdateStatus(); if (err != DEVICE_OK) { goto INIT_ERROR; } initialized_ = true; INIT_ERROR: // END LOCKING HandleListUnlock(); return err; }
int MCL_MicroDrive_ZStage::Initialize() { // BEGIN LOCKING -> make sure to unlock before any return call HandleListLock(); int err = DEVICE_OK; std::stringstream ss; bool valid = false; unsigned char axisBitmap; int possHandle = 0; if (initialized_) { err = DEVICE_OK; goto ZSTAGE_INIT_EXIT; } if(!MCL_CorrectDriverVersion()) { err = MCL_INVALID_DRIVER; goto ZSTAGE_INIT_EXIT; } int numHandles = MCL_GrabAllHandles(); if (numHandles == 0) { err = MCL_INVALID_HANDLE; goto ZSTAGE_INIT_EXIT; } int* handlesToUseOrRelease = NULL; handlesToUseOrRelease = (int*) malloc(sizeof(int*) * numHandles); MCL_GetAllHandles(handlesToUseOrRelease, numHandles); HandleListType* device = (HandleListType*)GlobalHeapAllocate(sizeof(HandleListType)); device->Initialize(possHandle, Z_TYPE); for (int i = 0; i < numHandles; i++) { possHandle = handlesToUseOrRelease[i]; device->setHandle(possHandle); MCL_GetAxisInfo(&axisBitmap, possHandle); // By default use the Z axis. bool validAxis = ((axisBitmap & VALIDZ) == VALIDZ); if (validAxis) { axis_ = ZAXIS; } // Otherwise use the X or Y axis of a single axis system. else if ( (axisBitmap & (VALIDX | VALIDY) ) != (VALIDX | VALIDY) ) { if ( (axisBitmap & AXIS_MASK) == VALIDX ) { axis_ = XAXIS; validAxis = true; } if ( (axisBitmap & AXIS_MASK) == VALIDY ) { axis_ = YAXIS; validAxis = true; } } if ((validAxis) && (!HandleExistsOnLockedList(device)) && (possHandle > 0)) { valid = true; HandleListAddToLockedList(device); MCLhandle_ = possHandle; unsigned short PID; MCL_GetProductID(&PID, MCLhandle_); if(PID == 0x2501) isMD1_ = true; else isMD1_ = false; // release handles not in use. for (int j = i+1; j < numHandles; j++) { possHandle = handlesToUseOrRelease[j]; if (!HandleExistsOnLockedList(possHandle) && possHandle > 0) { MCL_ReleaseHandle(possHandle); } } break; // done, no need to check further } else { if (!HandleExistsOnLockedList(possHandle) && possHandle > 0) { MCL_ReleaseHandle(possHandle); } } } free (handlesToUseOrRelease); if (!valid) { GlobalHeapFree(device); err = MCL_INVALID_HANDLE; goto ZSTAGE_INIT_EXIT; } if(isMD1_) MCL_MD1Information(&encoderResolution_, &stepSize_mm_, &maxVelocity_, &minVelocity_, MCLhandle_); else { double ignore1, ignore2; err = MCL_MicroDriveInformation(&encoderResolution_, &stepSize_mm_, &maxVelocity_, &ignore1, &ignore2, &minVelocity_, MCLhandle_); } ss << "Detected Encoder Resolution: " << encoderResolution_; this->LogMessage(ss.str()); if (err != MCL_SUCCESS) goto ZSTAGE_INIT_EXIT; velocity_ = maxVelocity_; char velErrText[50]; sprintf(velErrText, "Velocity must be between %f and %f", minVelocity_, maxVelocity_); SetErrorText(INVALID_VELOCITY, velErrText); CreateZStageProperties(); err = UpdateStatus(); if (err != DEVICE_OK) goto ZSTAGE_INIT_EXIT; initialized_ = true; ZSTAGE_INIT_EXIT: HandleListUnlock(); return err; }
int MicroDriveXYStage::Initialize() { // BEGIN LOCKING HandleListLock(); int err = DEVICE_OK; std::stringstream ss; bool valid = false; unsigned char axisBitmap; int possHandle = 0; if (initialized_) { err = DEVICE_OK; goto INIT_ERROR; } if(!MCL_CorrectDriverVersion()) { err=MCL_INVALID_DRIVER; goto INIT_ERROR; } int numHandles = MCL_GrabAllHandles(); if (numHandles == 0) { // No handles, i.e. no devices currently attached err = MCL_INVALID_HANDLE; goto INIT_ERROR; } int* handlesToUseOrRelease = NULL; handlesToUseOrRelease = (int*) malloc(sizeof(int*) * numHandles); MCL_GetAllHandles(handlesToUseOrRelease, numHandles); HandleListType* device = (HandleListType*)GlobalHeapAllocate(sizeof(HandleListType)); device->Initialize(possHandle, XY_TYPE); for (int i = 0; i < numHandles; i++) { possHandle = handlesToUseOrRelease[i]; device->setHandle(possHandle); MCL_GetAxisInfo(&axisBitmap, possHandle); // check to see which axes are valid bool validXaxis = ((axisBitmap & VALIDX) == VALIDX); bool validYaxis = ((axisBitmap & VALIDY) == VALIDY); if ( (validXaxis && validYaxis) && (!HandleExistsOnLockedList(device)) && (possHandle > 0) ) { valid = true; HandleListAddToLockedList(device); MCLhandle_ = possHandle; // release handles not in use. for (int j = i+1; j < numHandles; j++) { possHandle = handlesToUseOrRelease[j]; if (!HandleExistsOnLockedList(possHandle) && possHandle > 0) { MCL_ReleaseHandle(possHandle); } } break; // found a valid handle, so no need to check any further } else { if (!HandleExistsOnLockedList(possHandle) && possHandle > 0) { MCL_ReleaseHandle(possHandle); } } } free (handlesToUseOrRelease); if (!valid) { GlobalHeapFree(device); err = MCL_INVALID_HANDLE; goto INIT_ERROR; } err = MCL_MicroDriveInformation(&encoderResolution_, &stepSize_mm_, &maxVelocity_, &maxVelocityTwoAxis_, &maxVelocityThreeAxis_, &minVelocity_, MCLhandle_); ss << "Detected Encoder Resolution: " << encoderResolution_; this->LogMessage(ss.str()); if (err != MCL_SUCCESS) goto INIT_ERROR; velocity_ = maxVelocity_; char velErrText[50]; sprintf(velErrText, "Velocity must be between %f and %f", minVelocity_, maxVelocity_); SetErrorText(INVALID_VELOCITY, velErrText); CreateMicroDriveXYProperties(); err = UpdateStatus(); if (err != DEVICE_OK) goto INIT_ERROR; initialized_ = true; INIT_ERROR: // END LOCKING HandleListUnlock(); return err; }