//Called once in dllmain process attach. bool HandleListCreate() { //Create a mutex variable to control access to the HandleList ::gHandleListMutex = CreateMutex(NULL, FALSE, NULL); if(::gHandleListMutex == 0) return false; ::gHandleList = (DeviceList<HandleListType>*)GlobalHeapAllocate(sizeof(DeviceList<HandleListType>)); if(::gHandleList == 0) { ReleaseMutex(::gHandleListMutex); CloseHandle(::gHandleListMutex); return false; } ::gHandleList->Init(GlobalHeapGetHandle()); //Release the lock on the mutex we created ReleaseMutex(::gHandleListMutex); return true; }
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; }