diff --git a/lewis_emulators/ag33220a/__init__.py b/lewis_emulators/ag33220a/__init__.py deleted file mode 100644 index 847b7d31..00000000 --- a/lewis_emulators/ag33220a/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .device import SimulatedAG33220A -from ..lewis_versions import LEWIS_LATEST - -framework_version = LEWIS_LATEST -__all__ = ['SimulatedAG33220A'] diff --git a/lewis_emulators/ag33220a/device.py b/lewis_emulators/ag33220a/device.py deleted file mode 100644 index 356a9344..00000000 --- a/lewis_emulators/ag33220a/device.py +++ /dev/null @@ -1,157 +0,0 @@ -from lewis.devices import Device - - -class SimulatedAG33220A(Device): - """ - Simulated AG33220A - """ - connected = True - - # Constants - AMP_MIN = 0.01 - AMP_MAX = 10 - OFF_MAX = 4.995 - VOLT_MAX = 5 - VOLT_MIN = -5 - VOLT_LOW_MAX = 4.99 - VOLT_HIGH_MIN = -4.99 - VOLT_PRECISION = 0.01 - FREQ_MINS = {"SIN": 10 ** -6, "SQU": 10 ** -6, "RAMP": 10 ** -6, "PULS": 5 * 10 ** -4, - "NOIS": 10 ** -6, "USER": 10 ** -6} - FREQ_MAXS = {"SIN": 2 * 10 ** 7, "SQU": 2 * 10 ** 7, "RAMP": 2 * 10 ** 5, "PULS": 5 * 10 ** 6, - "NOIS": 2 * 10 ** 7, "USER": 6 * 10 ** 6} - - # Device variables - idn = "Agilent Technologies,33220A-MY44033103,2.02-2.02-22-2" - amplitude = 0.1 - frequency = 1000 - offset = 0 - units = "VPP" - function = "SIN" - output = "ON" - voltage_high = 0.05 - voltage_low = -0.05 - range_auto = "OFF" - - def limit(self, value, minimum, maximum): - """ - Limits an input number between two given numbers or sets the value to the maximum or minimum. - - :param value: the value to be limited - :param minimum: the smallest that the value can be - :param maximum: the largest that the value can be - - :return: the value after it has been limited - """ - if type(value) is str: - try: - value = float(value) - except ValueError: - return {"MIN": minimum, "MAX": maximum}[value] - - return max(min(value, maximum), minimum) - - def set_new_amplitude(self, new_amplitude): - """ - Changing the amplitude to the new amplitude whilst also changing the offset if voltage high or low is - outside the boundary. The volt high and low are then updated. - - :param new_amplitude: the amplitude to set the devices amplitude to - """ - new_amplitude = self.limit(new_amplitude, self.AMP_MIN, self.AMP_MAX) - - peak_amp = 0.5 * new_amplitude - if self.offset + peak_amp > self.VOLT_MAX: - self.offset = self.VOLT_MAX - peak_amp - elif self.offset - peak_amp < self.VOLT_MIN: - self.offset = self.VOLT_MIN + peak_amp - - self.amplitude = new_amplitude - - self._update_volt_high_and_low(self.amplitude, self.offset) - - def set_new_frequency(self, new_frequency): - """ - Sets the frequency within limits between upper and lower bound (depends on the function). - - :param new_frequency: the frequency to set to - """ - self.frequency = self.limit(new_frequency, self.FREQ_MINS[self.function], self.FREQ_MAXS[self.function]) - - def set_new_voltage_high(self, new_voltage_high): - """ - Sets a new voltage high which then changes the voltage low to keep it lower. - The voltage offset and amplitude are then updated. - - :param new_voltage_high: the value of voltage high to set to - """ - new_voltage_high = self.limit(new_voltage_high, self.VOLT_HIGH_MIN, self.VOLT_MAX) - if new_voltage_high <= self.voltage_low: - self.voltage_low = self.limit(new_voltage_high - self.VOLT_PRECISION, self.VOLT_MIN, new_voltage_high) - self._update_volt_and_offs(self.voltage_low, new_voltage_high) - - def set_new_voltage_low(self, new_voltage_low): - """ - Sets a new voltage high which then changes the voltage low to keep it higher. - The voltage offset and amplitude are then updated. - - :param new_voltage_low: the value of voltage low which is to be set - """ - new_voltage_low = self.limit(new_voltage_low, self.VOLT_MIN, self.VOLT_LOW_MAX) - if new_voltage_low >= self.voltage_high: - self.voltage_high = self.limit(new_voltage_low + self.VOLT_PRECISION, new_voltage_low, self.VOLT_MAX) - self._update_volt_and_offs(new_voltage_low, self.voltage_high) - - def _update_volt_and_offs(self, new_low, new_high): - """ - Updates the value of amplitude and offset if there is a change in voltage low or voltage high. - - :param new_low: the value of voltage low - :param new_high: the value of voltage high - """ - self.voltage_high = new_high - self.voltage_low = new_low - self.amplitude = self.voltage_high - self.voltage_low - self.offset = (self.voltage_high + self.voltage_low)/2 - - def set_offs_and_update_voltage(self, new_offset): - """ - Sets the value of offset and updates the amplitude, voltage low and voltage high for a new value of the offset. - - :param new_offset: the new offset to be set - """ - new_offset = self.limit(new_offset, -self.OFF_MAX, self.OFF_MAX) - if new_offset + self.voltage_high > self.VOLT_MAX: - self.amplitude = 2*(self.VOLT_MAX-new_offset) - self.voltage_high = self.VOLT_MAX - self.voltage_low = self.VOLT_MAX - self.amplitude - elif new_offset + self.voltage_low < self.VOLT_MIN: - self.amplitude = 2*(self.VOLT_MIN-new_offset) - self.voltage_low = self.VOLT_MIN - self.voltage_high = self.VOLT_MIN + self.amplitude - else: - self._update_volt_high_and_low(self.amplitude, new_offset) - self.offset = new_offset - - def _update_volt_high_and_low(self, new_volt, new_offs): - """ - Updates the value of voltage high and low for a given value of amplitude and offset. - - :param new_volt: the value of the amplitude - :param new_offs: the value of the offset - """ - self.offset = new_offs - self.amplitude = new_volt - self.voltage_high = new_offs + new_volt / 2 - self.voltage_low = new_offs - new_volt / 2 - - def get_output(self): - return ["OFF", "ON"].index(self.output) - - def get_range_auto(self): - possible_ranges = ["OFF", "ON", "ONCE"] - return possible_ranges.index(self.range_auto) - - def set_function(self, new_function): - self.function = new_function - self.frequency = self.limit(self.frequency, self.FREQ_MINS[new_function], self.FREQ_MAXS[new_function]) diff --git a/lewis_emulators/ag33220a/interfaces/__init__.py b/lewis_emulators/ag33220a/interfaces/__init__.py deleted file mode 100644 index e84bb41d..00000000 --- a/lewis_emulators/ag33220a/interfaces/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .stream_interface import AG33220AStreamInterface - -__all__ = ['AG33220AStreamInterface'] \ No newline at end of file diff --git a/lewis_emulators/ag33220a/interfaces/stream_interface.py b/lewis_emulators/ag33220a/interfaces/stream_interface.py deleted file mode 100644 index 8b9c67d9..00000000 --- a/lewis_emulators/ag33220a/interfaces/stream_interface.py +++ /dev/null @@ -1,120 +0,0 @@ -from lewis.adapters.stream import StreamInterface, Cmd -from lewis.utils.command_builder import string_arg -from lewis.utils.replies import conditional_reply -import traceback - -NUM_MIN_MAX = "([\-0-9.]+|MAX|MIN)" - -if_connected = conditional_reply("connected") - - -class AG33220AStreamInterface(StreamInterface): - - commands = { - Cmd("get_amplitude", "^VOLT\?$"), - Cmd("set_amplitude", "^VOLT " + NUM_MIN_MAX, argument_mappings=[string_arg]), - Cmd("get_frequency", "^FREQ\?$"), - Cmd("set_frequency", "^FREQ " + NUM_MIN_MAX, argument_mappings=[string_arg]), - Cmd("get_offset", "^VOLT:OFFS\?$"), - Cmd("set_offset", "^VOLT:OFFS " + NUM_MIN_MAX, argument_mappings=[string_arg]), - Cmd("get_units", "^VOLT:UNIT\?$"), - Cmd("set_units", "^VOLT:UNIT (VPP|VRMS|DBM)$", argument_mappings=[string_arg]), - Cmd("get_function", "^FUNC\?$"), - Cmd("set_function", "^FUNC (SIN|SQU|RAMP|PULS|NOIS|DC|USER)$", argument_mappings=[string_arg]), - Cmd("get_output", "^OUTP\?$"), - Cmd("set_output", "^OUTP (ON|OFF)$", argument_mappings=[string_arg]), - Cmd("get_idn", "^\*IDN\?$"), - Cmd("get_voltage_high", "^VOLT:HIGH\?$"), - Cmd("set_voltage_high", "^VOLT:HIGH " + NUM_MIN_MAX, argument_mappings=[string_arg]), - Cmd("get_voltage_low", "^VOLT:LOW\?$"), - Cmd("set_voltage_low", "^VOLT:LOW " + NUM_MIN_MAX, argument_mappings=[string_arg]), - Cmd("get_voltage_range_auto", "^VOLT:RANG:AUTO\?$"), - Cmd("set_voltage_range_auto", "^VOLT:RANG:AUTO (OFF|ON|ONCE)$", argument_mappings=[string_arg]), - } - - in_terminator = "\n" - out_terminator = "\n" - - # Takes in a value and returns a value in the form of x.xxx0000000000Eyy - def float_output(self, value): - value = float('%s' % float('%.4g' % float(value))) - return "{:+.13E}".format(value) - - @if_connected - def get_amplitude(self): - return self.float_output(self._device.amplitude) - - @if_connected - def set_amplitude(self, new_amplitude): - self._device.set_new_amplitude(new_amplitude) - - @if_connected - def get_frequency(self): - return self.float_output(self._device.frequency) - - @if_connected - def set_frequency(self, new_frequency): - self._device.set_new_frequency(new_frequency) - - @if_connected - def get_offset(self): - return self.float_output(self._device.offset) - - @if_connected - def set_offset(self, new_offset): - self._device.set_offs_and_update_voltage(new_offset) - - @if_connected - def get_units(self): - return self._device.units - - @if_connected - def set_units(self, new_units): - self._device.units = new_units - - @if_connected - def get_function(self): - return self._device.function - - @if_connected - def set_function(self, new_function): - self._device.set_function(new_function) - - @if_connected - def get_output(self): - return self._device.get_output() - - @if_connected - def set_output(self, new_output): - self._device.output = new_output - - @if_connected - def get_idn(self): - return self._device.idn - - @if_connected - def get_voltage_high(self): - return self.float_output(self._device.voltage_high) - - @if_connected - def set_voltage_high(self, new_voltage_high): - self._device.set_new_voltage_high(new_voltage_high) - - @if_connected - def get_voltage_low(self): - return self.float_output(self._device.voltage_low) - - @if_connected - def set_voltage_low(self, new_voltage_low): - self._device.set_new_voltage_low(new_voltage_low) - - @if_connected - def get_voltage_range_auto(self): - return self._device.get_range_auto() - - @if_connected - def set_voltage_range_auto(self, range_auto): - self._device.range_auto = range_auto - - def handle_error(self, request, error): - print(traceback.format_exc())