Skip to content

Commit

Permalink
Merge pull request #70 from Galvant/lint_generic_scpi
Browse files Browse the repository at this point in the history
Lint generic scpi
  • Loading branch information
scasagrande committed Jan 30, 2016
2 parents 575bf3a + 6de6b8b commit 0a2c618
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 276 deletions.
2 changes: 1 addition & 1 deletion instruments/instruments/agilent/agilent33220a.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Provides the support for the Agilent 33220a function generator.
Provides support for the Agilent 33220a function generator.
"""

# IMPORTS #####################################################################
Expand Down
2 changes: 1 addition & 1 deletion instruments/instruments/agilent/agilent34410a.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Provides the support for the Agilent 34410a digital multimeter.
Provides support for the Agilent 34410a digital multimeter.
"""

# IMPORTS #####################################################################
Expand Down
9 changes: 6 additions & 3 deletions instruments/instruments/generic_scpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module containing generic SCPI instruments
"""

from __future__ import absolute_import

from instruments.generic_scpi.scpi_instrument import SCPIInstrument
from instruments.generic_scpi.scpi_multimeter import SCPIMultimeter
from instruments.generic_scpi.scpi_function_generator import SCPIFunctionGenerator
from .scpi_instrument import SCPIInstrument
from .scpi_multimeter import SCPIMultimeter
from .scpi_function_generator import SCPIFunctionGenerator
113 changes: 58 additions & 55 deletions instruments/instruments/generic_scpi/scpi_function_generator.py
Original file line number Diff line number Diff line change
@@ -1,118 +1,121 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# scpimultimeter.py: Python class for SCPI complient multimeters
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
##
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##

## IMPORTS #####################################################################
"""
Provides support for SCPI compliant function generators
"""

# IMPORTS #####################################################################

from __future__ import absolute_import
from __future__ import division

from enum import Enum

import quantities as pq
import numpy as np

from instruments.abstract_instruments import FunctionGenerator
from instruments.generic_scpi import SCPIInstrument
from instruments.util_fns import assume_units, enum_property, unitful_property
from instruments.util_fns import enum_property, unitful_property

from instruments.units import dBm
# CLASSES #####################################################################

## CLASSES #####################################################################

class SCPIFunctionGenerator(FunctionGenerator, SCPIInstrument):

## CONSTANTS ##

# TODO: document these.

"""
This class is used for communicating with generic SCPI-compliant
function generators.
Example usage:
>>> import instruments as ik
>>> import quantities as pq
>>> inst = ik.generic_scpi.SCPIFunctionGenerator.open_tcpip("192.168.1.1")
>>> inst.frequency = 1 * pq.kHz
"""

def __init__(self, filelike):
super(SCPIFunctionGenerator, self).__init__(filelike)

# CONSTANTS #

_UNIT_MNEMONICS = {
FunctionGenerator.VoltageMode.peak_to_peak: "VPP",
FunctionGenerator.VoltageMode.rms: "VRMS",
FunctionGenerator.VoltageMode.dBm: "DBM",
}

_MNEMONIC_UNITS = dict((mnem, unit) for unit, mnem in _UNIT_MNEMONICS.items())

## FunctionGenerator CONTRACT ##


_MNEMONIC_UNITS = dict((mnem, unit)
for unit, mnem in _UNIT_MNEMONICS.items())

# FunctionGenerator CONTRACT #

def _get_amplitude_(self):
"""
Gets the amplitude for a generic SCPI function generator
:type: `tuple` containing `float` for value, and
`FunctionGenerator.VoltageMode` for the type of measurement
(eg VPP, VRMS, DBM).
"""
units = self.query("VOLT:UNIT?").strip()

return (
float(self.query("VOLT?").strip()),
self._MNEMONIC_UNITS[units]
)

def _set_amplitude_(self, magnitude, units):
"""
Sets the amplitude for a generic SCPI function generator
:param magnitude: Desired amplitude magnitude
:type magnitude: `float`
:param units: The type of voltage measurements units
:type units: `FunctionGenerator.VoltageMode`
"""
self.sendcmd("VOLT:UNIT {}".format(self._UNIT_MNEMONICS[units]))
self.sendcmd("VOLT {}".format(magnitude))
## PROPERTIES ##

# PROPERTIES #

frequency = unitful_property(
name="FREQ",
units=pq.Hz,
doc="""
Gets/sets the output frequency.
:units: As specified, or assumed to be :math:`\\text{Hz}` otherwise.
:type: `float` or `~quantities.quantity.Quantity`
"""
)

function = enum_property(
name="FUNC",
enum = lambda: self.Function,
enum=lambda: Function, # pylint: disable=undefined-variable
doc="""
Gets/sets the output function of the function generator
:type: `SCPIFunctionGenerator.Function`
"""
)

offset = unitful_property(
name="VOLT:OFFS",
units=pq.volt,
doc="""
Gets/sets the offset voltage of the function generator.
Set value should be within correct bounds of instrument.
:units: As specified (if a `~quntities.quantity.Quantity`) or assumed
:units: As specified (if a `~quntities.quantity.Quantity`) or assumed
to be of units volts.
:type: `~quantities.quantity.Quantity` with units volts.
"""
)

@property
def phase(self):
raise NotImplementedError

@phase.setter
def phase(self, newval):
raise NotImplementedError

0 comments on commit 0a2c618

Please sign in to comment.