def move_axis(self, pos, axis, relative=False): """Move one axis (currently in volts)""" chan = self.select_axis(self.channels, axis) if relative: # emulate relative moves pos += Decimal.ToDouble(chan.GetOutputVoltage()) chan.SetOutputVoltage(Decimal(pos))
def connect(self): """Initialise communications, populate channel list, etc.""" self.device.Connect(self._serial_number) self.connected = True assert len( self.channels ) == 0, "Error connecting: we've already initialised channels!" for i in range(self.device.ChannelCount): chan = self.device.GetChannel( i + 1) # Kinesis channels are one-indexed chan.WaitForSettingsInitialized(5000) chan.StartPolling( 250) # getting the voltage only works if you poll! time.sleep(0.5) # ThorLabs have this in their example... chan.EnableDevice() # I don't know if the lines below are necessary or not - but removing them # may or may not work... time.sleep(0.5) config = chan.GetPiezoConfiguration(chan.DeviceID) info = chan.GetDeviceInfo() max_v = Decimal.ToDouble(chan.GetMaxOutputVoltage()) self.channels.append(chan) self.axis_names = tuple("channel_{}".format(i) for i in range(self.device.ChannelCount))
def get_position(self, axis=None): if axis is None: return [self.get_position(ax) for ax in self.axis_names] else: chan = self.select_axis(self.channels, axis) return Decimal.ToDouble(chan.GetOutputVoltage())
def get_output_voltages(self): """Retrieve the output voltages as a list of floating-point numbers""" return [ Decimal.ToDouble(chan.GetOutputVoltage()) for chan in self.channels ]
if data: return datatype(data) if datatype in [bool, int, float] and data == 0: return datatype(data) return None adomd_type_map: Dict[str, Type_code] = { 'System.Boolean': Type_code(partial(_option_type, bool), bool.__name__), 'System.DateTime': Type_code( lambda x: datetime(x.Year, x.Month, x.Day, x.Hour, x.Minute, x.Second) if x else None, datetime.__name__), 'System.Decimal': Type_code(lambda x: Decimal.ToDouble(x) if x else None, float.__name__), 'System.Double': Type_code(partial(_option_type, float), float.__name__), 'System.Single': Type_code(partial(_option_type, float), float.__name__), 'System.String': Type_code(partial(_option_type, str), str.__name__), 'System.Guid': Type_code(partial(_option_type, str), str.__name__), 'System.UInt16': Type_code(partial(_option_type, int), int.__name__), 'System.UInt32': Type_code(partial(_option_type, int), int.__name__), 'System.UInt64': Type_code(partial(_option_type, int), int.__name__), 'System.Int16':
def get_value(self): if self.is_closed_loop(): value = Decimal.ToDouble(self.device.GetPercentageTravel()) else: value = Decimal.ToDouble(self.device.GetOutputVoltage()) return value
def get_pos(self): current_pos = Decimal.ToDouble(self.device.Status.get_Reading()) return current_pos