Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spac3 docstrings #4

Open
wants to merge 4 commits into
base: spAc3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spacq/devices/Scientific_Instruments/model9700.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def _connected(self):
def temperature(self):
"""
The value measured by the device, as a quantity in K.

Returns
-------
float
"""

while True:
Expand All @@ -50,6 +54,10 @@ def temperature(self):
def power(self):
'''
The value of the PID as a percentage.

Returns
-------
float
'''

# Sometimes does not answer the correct query, so need to ask until we get the desired response
Expand Down
116 changes: 97 additions & 19 deletions spacq/devices/abstract_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class DeviceTimeout(Exception):


class SuperDevice(object):
"""
A superclass for all devices.
"""
def _setup(self):
"""
Pre-connection setup.
Expand All @@ -77,6 +80,32 @@ def _connected(self):
class AbstractDevice(SuperDevice):
"""
A class for controlling devices which can be connected to either via Ethernet and (PyVISA or Telnet) or GPIB and Linux GPIB.

Parameters
----------
Ethernet (tcpip::<ip_address>::instr):
ip_address : str, optional
Address on which the device is listening on port 111.

Telnet (<host_address>):
host_address : str, optional
String that list the IP address of the host.
Named this way to avoid issues with ip_address used for ethernet connections

GPIB (gpib[gpib_board]::<gpib_pad>[::<gpib_sad>]::instr):
gpib_board : int, optional
GPIB board index. Defaults to 0.
gpib_pad : int, optional
Primary address of the device.
gpib_sad : int, optional
Secondary address of the device. Defaults to 0.

USB (usb_resource):
usb_resource : str, optional
VISA resource of the form: USB[board]::<vendor>::<product>::<serial>[::<interface>]::RAW

autoconnect : bool, optional

"""

max_timeout = 15 # s
Expand All @@ -93,24 +122,6 @@ def _setup(self):

def __init__(self, ip_address=None, host_address=None, gpib_board=0, gpib_pad=None, gpib_sad=0,
usb_resource=None, autoconnect=True):
"""
Ethernet (tcpip::<ip_address>::instr):
ip_address: Address on which the device is listening on port 111.

Telnet (<host_address>):
host_address: String that list the IP address of the host.
Named this way to avoid issues with ip_address used for ethernet connections

GPIB (gpib[gpib_board]::<gpib_pad>[::<gpib_sad>]::instr):
gpib_board: GPIB board index. Defaults to 0.
gpib_pad: Primary address of the device.
gpib_sad: Secondary address of the device. Defaults to 0.

USB (usb_resource):
usb_resource: VISA resource of the form: USB[board]::<vendor>::<product>::<serial>[::<interface>]::RAW

autoconnect: Connect to the device upon instantiation.
"""

self._setup()

Expand Down Expand Up @@ -170,6 +181,13 @@ def __init__(self, ip_address=None, host_address=None, gpib_board=0, gpib_pad=No
self.connect()

def __repr__(self):
"""
Return a string representation of the device.

Return
------
str
"""
return '<{0}>'.format(self.__class__.__name__)

def connect(self):
Expand Down Expand Up @@ -226,7 +244,10 @@ def multi_command_stop(self):
"""
Stop redirecting to a buffer, and send the buffered commands.

Returns the results of queries if any were expected.
Returns
-------
list of str
the results of queries if any were expected
"""

log.debug(
Expand Down Expand Up @@ -262,6 +283,10 @@ def write(self, message):
Write to the device.

Supports multi-command.

Parameters
----------
message : str
"""

if self.multi_command is not None:
Expand Down Expand Up @@ -299,6 +324,15 @@ def write(self, message):
def read_raw(self, chunk_size=512):
"""
Read everything the device has to say and return it exactly.

Parameters
----------
chunk_size : int, optional
The maximum number of bytes to read at once.

Returns
-------
str
"""

log.debug('Reading from device "{0}".'.format(self.name))
Expand Down Expand Up @@ -327,6 +361,10 @@ def read_raw(self, chunk_size=512):
def read(self):
"""
Read from the device, but strip terminating whitespace.

Returns
-------
str
"""

return self.read_raw().rstrip()
Expand All @@ -335,6 +373,14 @@ def read(self):
def ask_raw(self, message):
"""
Write, then read_raw.

Parameters
----------
message : str

Returns
-------
str
"""

self.write(message)
Expand All @@ -346,6 +392,14 @@ def ask(self, message):
Write, then read.

Supports multi-command.

Parameters
----------
message : str

Returns
-------
str
"""

self.write(message)
Expand All @@ -359,6 +413,14 @@ def ask(self, message):
def query(self, message):
"""
Write then read using PyVisa's query command.

Parameters
----------
message : str

Returns
-------
str
"""
return self.device.query(message)

Expand All @@ -377,6 +439,14 @@ def find_resource(self, path):
Return a Resource given a resource path spec.

eg. ('subdevice A', 'subdevice B', 'resource C') -> Resource

Parameters
----------
path : tuple of str

Returns
-------
Resource
"""

log.debug('Looking for resource {0}.'.format(path))
Expand Down Expand Up @@ -409,6 +479,10 @@ def find_resource(self, path):
def idn(self):
"""
Ask the device for identification.

Returns
-------
str
"""

if self.driver in [drivers.pyvisa]:
Expand Down Expand Up @@ -436,6 +510,10 @@ def opc(self):
class AbstractSubdevice(SuperDevice):
"""
A subdevice (eg. channel) of a hardware device.

Parameters
----------
device : AbstractDevice
"""

def _setup(self):
Expand Down
8 changes: 8 additions & 0 deletions spacq/devices/agilent/dm34401a.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def reset(self):
def integration_time(self):
"""
The integration time of the multimeter in terms of PLC.

Returns
-------
float
"""

return float(self.ask('sense:voltage:dc:nplc?'))
Expand All @@ -76,6 +80,10 @@ def integration_time(self, value):
def auto_zero(self):
"""
The auto zero state.

Returns
-------
str
"""

# result = self.ask('sense:voltage:dc:zero:auto?')
Expand Down
12 changes: 12 additions & 0 deletions spacq/devices/agilent/dm34410a.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def reset(self):
def integration_time(self):
"""
The integration time of the multimeter in terms of PLC.

Returns
-------
float
"""

return float(self.ask('sense:voltage:dc:nplc?'))
Expand All @@ -75,6 +79,10 @@ def integration_time(self, value):
def auto_zero(self):
"""
The auto zero state.

Returns
-------
str
"""

result = self.ask('sense:voltage:dc:zero:auto?')
Expand All @@ -97,6 +105,10 @@ def auto_zero(self, value):
def reading(self):
"""
The value measured by the device, as a quantity in V.

Returns
-------
float
"""

self.status.append('Taking reading')
Expand Down
11 changes: 11 additions & 0 deletions spacq/devices/agilent/mock/mock_dm34401a.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def _reset(self):
self.mock_state['auto_zero'] = 1

def write(self, message, result=None, done=False):
"""
Write a message to the device.

Parameters
----------
message : str
result : str, optional
The response to return.
done : bool, optional
True if this is the last message in a sequence.
"""
if not done:
cmd, args, query = self._split_message(message)

Expand Down
11 changes: 11 additions & 0 deletions spacq/devices/agilent/mock/mock_dm34410a.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def _reset(self):
self.mock_state['auto_zero'] = 1

def write(self, message, result=None, done=False):
"""
Write a message to the device.

Parameters
----------
message : str
result : str, optional
The response to return.
done : bool, optional
True if this is the last message in a sequence.
"""
if not done:
cmd, args, query = self._split_message(message)

Expand Down
16 changes: 16 additions & 0 deletions spacq/devices/agilent/nwa8753et.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def reset(self):
def cwFreq(self):
"""
The frequency of the networkAnalyzer output

Returns
-------
float
"""

return float(self.ask('cwfreq?'))
Expand All @@ -72,6 +76,10 @@ def cwFreq(self, value):
def power(self):
"""
The power (in dB)

Returns
-------
float
"""

return float(self.ask('powe?'))
Expand All @@ -85,6 +93,10 @@ def power(self, value):
def marker(self):
"""
The value measured by the device at marker, as a quantity in dB.

Returns
-------
float
"""

self.status.append('Taking reading')
Expand All @@ -104,6 +116,10 @@ def marker(self):
def markFreq(self):
"""
The frequency of the marker in Hz

Returns
-------
float
"""

return float(self.ask('MARK1?'))
Expand Down
Loading