def _connect(self): try: DeviceManagerCLI.BuildDeviceList() serial_number_list = DeviceManagerCLI.GetDeviceList( self.Servo.DevicePrefix) except (Exception): print("Exception raised by BuildDeviceList") if not (str(self.settings['serial_number']) in serial_number_list): print( str(self.settings['serial_number']) + " is not a valid serial number") raise ValueError self.device = self.Servo.CreateTCubeDCServo( str(self.settings['serial_number'])) if self.device is None: error_msg = self.settings[ 'serial_number'] + " is not a TCubeDCServo" raise AttributeError(error_msg) try: self.device.Connect(str(self.settings['serial_number'])) except Exception: print('Failed to open device ' + str(self.settings['serial_number'])) # raise if not self.device.IsSettingsInitialized(): try: self.device.WaitForSettingsInitialized(5000) except Exception: print("Settings failed to initialize") raise self.device.StartPolling(250) motorSettings = self.device.GetMotorConfiguration( str(self.settings['serial_number'])) currentDeviceSettings = self.device.MotorDeviceSettings
def __init__(self, deviceID, axis_chan_mapping={'x': 1, 'y': 2, 'z': 3}): """ Method creating a BPC303 instance and setting up the connection to the device with device ID. Also creates the attributes self.deviceID, self.isconnected and self.axis_chan_mapping """ DeviceManagerCLI.BuildDeviceList() self.deviceID = deviceID self.isconnected = False self.axis_chan_mapping = axis_chan_mapping if (self.deviceID in DeviceManagerCLI.GetDeviceList().ToArray()): self.controller = BenchtopPiezo.CreateBenchtopPiezo(self.deviceID) else: raise DeviceNotReadyException for attrname in ("xchannel", "ychannel", "zchannel"): setattr(self, attrname, None)
def _build_device(self, serial): if isinstance(serial, str) and serial[:2] == '28': DeviceManagerCLI.BuildDeviceList() device_list = DeviceManagerCLI.GetDeviceList() if serial in device_list: device = KCubeBrushlessMotor.CreateKCubeBrushlessMotor(serial) return device else: print('Check in the intended serial number is listed below:') print(device_list) return None else: print( 'Check if the intended serial number is a string that begins with "28".' ) return None
def __init__(self, name=None, settings=None): super(KDC101, self).__init__(name, settings) try: DeviceManagerCLI.BuildDeviceList() serial_number_list = DeviceManagerCLI.GetDeviceList( KCubeDCServo.DevicePrefix) except (Exception): print("Exception raised by BuildDeviceList") if not (str(self.settings['serial_number']) in serial_number_list): print( str(self.settings['serial_number']) + " is not a valid serial number") raise self.device = KCubeDCServo.CreateKCubeDCServo( str(self.settings['serial_number'])) if (self.device == None): print(self.settings['serial_number'] + " is not a KCubeDCServo") raise try: self.device.Connect(str(self.settings['serial_number'])) except Exception: print('Failed to open device ' + str(self.settings['serial_number'])) raise if not self.device.IsSettingsInitialized(): try: self.device.WaitForSettingsInitialized(5000) except Exception: print("Settings failed to initialize") raise self.device.StartPolling(250) motorSettings = self.device.GetMotorConfiguration( str(self.settings['serial_number'])) currentDeviceSettings = self.device.MotorDeviceSettings self.startup_magnet_azimuth = self._get_position() print('magnet azimuthal startup angle = ' + str(self.startup_magnet_azimuth) + "deg")
def connect(self, timeout=5): start = time.time() DeviceManagerCLI.Initialize() while True: if (time.time() - start) > timeout: raise RuntimeError("Timeout during device discovery.") return None DeviceManagerCLI.BuildDeviceList() if len(DeviceManagerCLI.GetDeviceList()): break ser_num = DeviceManagerCLI.GetDeviceList()[0] self.ser_num = ser_num while True: if (time.time() - start) > timeout: raise RuntimeError("Timeout during connection to device.") return None try: self.device = KCubeDCServoCLI.CreateKCubeDCServo(ser_num) self.device.Connect(ser_num) except Exception as e: continue break while True: if (time.time() - start) > timeout: raise RuntimeError("Timeout during device initilization.") return None try: init = self.device.IsSettingsInitialized() except BaseException as e: raise e return None if init: break self.device.StartPolling(self.polling_rate) time.sleep(0.5) self.device.EnableDevice() time.sleep(0.5) self.device.LoadMotorConfiguration(ser_num, DeviceConfiguration.DeviceSettingsUseOptionType.UseFileSettings) return self
def __init__(self, serial_number = 83832028): ''' Initializes connection to :param serial_number: serial number of device as written on physical device. Defaults to 83832028 of TDC001 :PostState: Initializes device ''' try: DeviceManagerCLI.BuildDeviceList() serial_number_list = DeviceManagerCLI.GetDeviceList(TCubeDCServo.DevicePrefix) except (Exception): print("Exception raised by BuildDeviceList") if not (str(serial_number) in serial_number_list): print(str(serial_number) + " is not a valid serial number") raise self.device = TCubeDCServo.CreateTCubeDCServo(str(serial_number)) if(self.device == None): print(serial_number + " is not a TCubeDCServo") raise try: self.device.Connect(str(serial_number)) except Exception: print('Failed to open device ' + str(serial_number)) raise if not self.device.IsSettingsInitialized(): try: self.device.WaitForSettingsInitialized(5000) except Exception: print("Settings failed to initialize") raise self.device.StartPolling(250) motorSettings = self.device.GetMotorConfiguration(str(serial_number)) currentDeviceSettings = self.device.MotorDeviceSettings
def __init__(self, name, parameters=[]): super(TDC001, self).__init__(name, parameters) self._is_connected = False try: DeviceManagerCLI.BuildDeviceList() serial_number_list = DeviceManagerCLI.GetDeviceList( TCubeDCServo.DevicePrefix) except (Exception): print("Exception raised by BuildDeviceList") if not (str(self.serial_number) in serial_number_list): print(str(self.serial_number) + " is not a valid serial number") raise self.device = TCubeDCServo.CreateTCubeDCServo(str(self.serial_number)) if (self.device == None): print(self.serial_number + " is not a TCubeDCServo") raise try: self.device.Connect(str(self.serial_number)) except Exception: print('Failed to open device ' + str(self.serial_number)) raise if not self.device.IsSettingsInitialized(): try: self.device.WaitForSettingsInitialized(5000) except Exception: print("Settings failed to initialize") raise self.device.StartPolling(250) self._is_connected = True motorSettings = self.device.GetMotorConfiguration( str(self.serial_number)) currentDeviceSettings = self.device.MotorDeviceSettings
def device_search(self): # Ask the device manager to get the list of all devices connected # to the computer try: DeviceManagerCLI.BuildDeviceList() connected = True except Exception as e: print('Exception raised by BuildDeviceList \n', e) print('Tholabs stage not found') connected = False if connected: # Get a c# list with all the connected kinesis serial numbers self.serial_numbers = DeviceManagerCLI.GetDeviceList() self.num_of_devices = self.serial_numbers.Count if self.num_of_devices != 0: for i in range(self.num_of_devices): print(self.serial_numbers[i]) else: print('No stages found') connected = False self.device_connencted = connected return connected
def _open_connection(self): _SN = HW_conf.kinesis_cube_serial # Instructs the DeviceManager to build and maintain the list of # devices connected. DeviceManagerCLI.BuildDeviceList() kCubeDCServoMotor = KCubeDCServo.CreateKCubeDCServo(_SN) # Establish a connection with the device. try_connect(lambda: kCubeDCServoMotor.Connect(_SN), DeviceNotReadyException) # Wait for the device settings to initialize. We ask the device to # throw an exception if this takes more than 5000ms (5s) to complete. kCubeDCServoMotor.WaitForSettingsInitialized(5000) # Initialize the DeviceUnitConverter object required for real world # unit parameters. kCubeDCServoMotor.GetMotorConfiguration(_SN) # This starts polling the device at intervals of 250ms (0.25s). kCubeDCServoMotor.StartPolling(20) # We are now able to enable the device for commands. kCubeDCServoMotor.EnableDevice() if not (kCubeDCServoMotor.IsActuatorDefined): raise HardwareError("Actuator not defined") print("Zstage Connected") velocity_parameters = kCubeDCServoMotor.GetVelocityParams() velocity_parameters.MaxVelocity = Decimal(1) kCubeDCServoMotor.SetVelocityParams(velocity_parameters) if not kCubeDCServoMotor.Status.IsHomed: kCubeDCServoMotor.Home(0) return kCubeDCServoMotor
def is_connected(self): DeviceManagerCLI.BuildDeviceList() return (str(self.settings['serial_number']) in DeviceManagerCLI.GetDeviceList(TCubeDCServo.DevicePrefix))