class ARRW60(base.TarableScales): """The ARRW60 model of Adventurer scales.""" ERROR = "error" OK = "ok" def __init__(self, host, port): super(ARRW60, self).__init__() self._connection = SocketConnection(host, port, "\r\n") self._states = self._states.union(set([ARRW60.OK, ARRW60.ERROR])) def _execute(self, cmd): result = self._connection.execute(cmd) if "OK!" not in result: raise ValueError("Bad command or value") def _tare(self): self._execute("T") def _get_weight(self): """ Get weight from the scales. The command does not return until a balanced position is found, thus it can time out. """ res = self._connection.execute("P") if "Err8.4" in res: self._set_state(ARRW60.ERROR) raise WeightError("More than maximum weight loaded") else: if self.state == ARRW60.ERROR or self.state == Device.NA: # Clear the error from before or set OK for the first time self._set_state(ARRW60.OK) # The returned string contains units res = q.Quantity(res).to(q.g) return float(res.magnitude) * q.counts
class LinearMotor(base.LinearMotor): """A linear motor that moves in two directions.""" def __init__(self, host=DEFAULT_CRIO_HOST, port=DEFAULT_CRIO_PORT_LINEAR): super(LinearMotor, self).__init__() self._connection = SocketConnection(host, port, '\r\n') self._position = 0 * q.mm self._to_device_scale = 50000 self['position'].lower = 0 * q.mm self['position'].upper = 2 * q.mm def _get_position(self): return self._position / self._to_device_scale def _set_position(self, position): self._position = position.to(q.mm) * self._to_device_scale self._connection.execute('lin {} 5000'.format(int(self._position))) def _stop(self): self._connection.execute('mod stop')
class RotationMotor(base.ContinuousRotationMotor): """A rotational motor.""" def __init__(self, host=DEFAULT_CRIO_HOST, port=DEFAULT_CRIO_PORT_ROTATIONAL): super(RotationMotor, self).__init__() self._connection = SocketConnection(host, port, '\r\n') self._position = 0 * q.deg self._velocity = 0 * q.deg / q.s self._to_device_scale = 2 def _in_hard_limit(self): return False def _in_velocity_hard_limit(self): return False def _get_position(self): return self._position / self._to_device_scale def _set_position(self, position): self._position = position * self._to_device_scale self._connection.execute('rot {} 500'.format(int(self._position))) def _get_velocity(self): return 0 * q.deg / q.s def _set_velocity(self, velocity): self._velocity = velocity * self._to_device_scale self._connection.execute('mod {}'.format(int(self._velocity))) def _stop(self): self._connection.execute('mod stop')
class ARRW60(base.TarableScales): """The ARRW60 model of Adventurer scales.""" ERROR = "error" OK = "ok" def __init__(self, host, port): super(ARRW60, self).__init__(LinearCalibration(q.counts / q.g, 0 * q.g)) self._connection = SocketConnection(host, port, "\r\n") self._states = self._states.union(set([ARRW60.OK, ARRW60.ERROR])) def _execute(self, cmd): result = self._connection.execute(cmd) if "OK!" not in result: raise ValueError("Bad command or value") def _tare(self): self._execute("T") def _get_weight(self): """ Get weight from the scales. The command does not return until a balanced position is found, thus it can time out. """ res = self._connection.execute("P") if "Err8.4" in res: self._set_state(ARRW60.ERROR) raise WeightError("More than maximum weight loaded") else: if self.state == ARRW60.ERROR or self.state == Device.NA: # Clear the error from before or set OK for the first time self._set_state(ARRW60.OK) # The returned string contains units res = q.Quantity(res).to(q.g) return float(res.magnitude) * q.counts