Skip to content

Commit

Permalink
Merge pull request #48 from Galvant/card_1
Browse files Browse the repository at this point in the history
Rename all Wrappers->Communicators
  • Loading branch information
scasagrande committed Oct 26, 2015
2 parents 90d4339 + 3d0e77e commit a51e220
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 99 deletions.
14 changes: 7 additions & 7 deletions instruments/instruments/abstract_instruments/comm/__init__.py
@@ -1,10 +1,10 @@
from instruments.abstract_instruments.comm.abstract_comm import AbstractCommunicator

from instruments.abstract_instruments.comm.socketwrapper import SocketWrapper
from instruments.abstract_instruments.comm.usbwrapper import USBWrapper
from instruments.abstract_instruments.comm.serialwrapper import SerialWrapper
from instruments.abstract_instruments.comm.visawrapper import VisaWrapper
from instruments.abstract_instruments.comm.loopback_wrapper import LoopbackWrapper
from instruments.abstract_instruments.comm.gi_gpib import GPIBWrapper
from instruments.abstract_instruments.comm.socket_communicator import SocketCommunicator
from instruments.abstract_instruments.comm.usb_communicator import USBCommunicator
from instruments.abstract_instruments.comm.serial_communicator import SerialCommunicator
from instruments.abstract_instruments.comm.visa_communicator import VisaCommunicator
from instruments.abstract_instruments.comm.loopback_communicator import LoopbackCommunicator
from instruments.abstract_instruments.comm.gi_gpib_communicator import GPIBCommunicator
from instruments.abstract_instruments.comm.file_communicator import FileCommunicator
from instruments.abstract_instruments.comm.usbtmc_comm import USBTMCCommunicator
from instruments.abstract_instruments.comm.usbtmc_communicator import USBTMCCommunicator
@@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# wrapperabc.py: Python ABC for file-like wrappers
# abstract_comm.py: Python ABC for file-like communicators
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down Expand Up @@ -139,7 +139,7 @@ def sendcmd(self, msg):
but appends any other commands or termination characters required
by the communication.
This differs from the wrapper .write method which directly exposes
This differs from the communicator .write method which directly exposes
the communication channel without appending other data.
'''
if self.debug:
Expand Down Expand Up @@ -167,8 +167,8 @@ def query(self, msg, size=-1):
@abc.abstractmethod
def flush_input(self):
'''
Instruct the wrapper to flush the input buffer, discarding the entirety
of its contents.
Instruct the communicator to flush the input buffer, discarding the
entirety of its contents.
'''
raise NotImplementedError

Expand Up @@ -4,7 +4,7 @@
# file_communicator.py: Treats a file on the filesystem as a communicator
# (aka wrapper).
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down
@@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# gi_gpib.py: Wrapper for Galvant Industries GPIB adapters.
# gi_gpib_communicator.py: Communication layer for Galvant Industries GPIB adapters.
##
# © 2013-2014 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down Expand Up @@ -31,18 +31,18 @@
import numpy as np
import quantities as pq

from instruments.abstract_instruments.comm import serialManager, AbstractCommunicator
from instruments.abstract_instruments.comm import serial_manager, AbstractCommunicator
from instruments.util_fns import assume_units

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

class GPIBWrapper(io.IOBase, AbstractCommunicator):
class GPIBCommunicator(io.IOBase, AbstractCommunicator):
'''
Wraps a SocketWrapper or PySerial.Serial connection for use with
Galvant Industries GPIBUSB or GPIBETHERNET adapters.
Communicates with a SocketCommunicator or SerialCommunicator object for
use with Galvant Industries GPIBUSB or GPIBETHERNET adapters.
This wrapper is designed to wrap the SocketWrapper and SerialWrapper
classes.
It essentially wraps those physical communication layers with the extra
overhead required by the Galvant GPIB adapters.
'''
def __init__(self, filelike, gpib_address):
AbstractCommunicator.__init__(self)
Expand Down Expand Up @@ -73,7 +73,7 @@ def address(self, newval):
Example: [<int>gpib_address, downstream_address]
Where downstream_address needs to be formatted as appropriate for the
connection (eg SerialWrapper, SocketWrapper, etc).
connection (eg SerialCommunicator, SocketCommunicator, etc).
'''
if isinstance(newval, int):
if (newval < 1) or (newval > 30):
Expand Down Expand Up @@ -189,8 +189,8 @@ def close(self):

def read(self, size):
'''
Read characters from wrapped class (ie SocketWrapper or
PySerial.Serial).
Read characters from wrapped class (ie SocketCommunicator or
SerialCommunicator).
If size = -1, characters will be read until termination character
is found.
Expand All @@ -216,8 +216,8 @@ def write(self, msg):

def flush_input(self):
'''
Instruct the wrapper to flush the input buffer, discarding the entirety
of its contents.
Instruct the communicator to flush the input buffer, discarding the
entirety of its contents.
'''
self._file.flush_input()

Expand Down
@@ -1,10 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# loopback_wrappper.py: Loopback wrapper, just prints what it receives or
# queries return empty string
# loopback_communicator.py: Loopback communicator, just prints what it receives
# or queries return empty string
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down Expand Up @@ -32,7 +32,7 @@

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

class LoopbackWrapper(io.IOBase, AbstractCommunicator):
class LoopbackCommunicator(io.IOBase, AbstractCommunicator):
"""
Used for testing various controllers
"""
Expand Down Expand Up @@ -61,7 +61,7 @@ def terminator(self, newval):
raise TypeError('Terminator must be specified '
'as a single character string.')
if len(newval) > 1:
raise ValueError('Terminator for LoopbackWrapper must only be 1 '
raise ValueError('Terminator for LoopbackCommunicator must only be 1 '
'character long.')
self._terminator = newval

Expand Down
@@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# socketwrapper.py: Wraps sockets into a filelike object.
# serial_communicator.py: Wraps PySerial.Serial objects into a filelike object.
##
# © 2013-2014 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down Expand Up @@ -35,7 +35,7 @@

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

class SerialWrapper(io.IOBase, AbstractCommunicator):
class SerialCommunicator(io.IOBase, AbstractCommunicator):
"""
Wraps a pyserial Serial object to add a few properties as well as
handling of termination characters.
Expand All @@ -50,7 +50,7 @@ def __init__(self, conn):
self._debug = False
self._capture = False
else:
raise TypeError('SerialWrapper must wrap a serial.Serial object.')
raise TypeError('SerialCommunicator must wrap a serial.Serial object.')

## PROPERTIES ##

Expand All @@ -70,10 +70,10 @@ def terminator(self):
@terminator.setter
def terminator(self, newval):
if not isinstance(newval, str):
raise TypeError('Terminator for SerialWrapper must be specified '
'as a single character string.')
raise TypeError('Terminator for SerialCommunicator must be '
'specified as a single character string.')
if len(newval) > 1:
raise ValueError('Terminator for SerialWrapper must only be 1 '
raise ValueError('Terminator for SerialCommunicator must only be 1 '
'character long.')
self._terminator = newval

Expand Down Expand Up @@ -131,7 +131,7 @@ def tell(self):

def flush_input(self):
'''
Instruct the wrapper to flush the input buffer, discarding the entirety
Instruct the communicator to flush the input buffer, discarding the entirety
of its contents.
Calls the pyserial flushInput() method.
Expand Down
@@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# serialManager.py: Manages open serial connections.
# serial_manager.py: Manages open serial connections.
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down Expand Up @@ -36,7 +36,7 @@

import serial

from instruments.abstract_instruments.comm import SerialWrapper
from instruments.abstract_instruments.comm import SerialCommunicator

# We want to only *weakly* hold references to serial ports, to allow for them
# to be deleted and reopened as need be.
Expand All @@ -53,12 +53,12 @@

## METHODS #####################################################################

def newSerialConnection(port, baud=460800, timeout=3, writeTimeout=3):
def new_serial_connection(port, baud=460800, timeout=3, write_timeout=3):
if not isinstance(port,str):
raise TypeError('Serial port must be specified as a string.')

if port not in serialObjDict or serialObjDict[port] is None:
conn = SerialWrapper(serial.Serial(
conn = SerialCommunicator(serial.Serial(
port,
baudrate=baud,
timeout=timeout,
Expand Down
@@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# socketwrapper.py: Wraps sockets into a filelike object.
# socket_communicator.py: Encapsulates a socket into a filelike object.
##
# © 2013-2014 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
# Chris Granade (cgranade@cgranade.com).
#
# This file is a part of the InstrumentKit project.
Expand Down Expand Up @@ -36,12 +36,12 @@

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

class SocketWrapper(io.IOBase, AbstractCommunicator):
class SocketCommunicator(io.IOBase, AbstractCommunicator):
"""
Wraps a socket to make it look like a `file`. Note that this is used instead
of `socket.makefile`, as that method does not support timeouts. We do not
support all features of `file`-like objects here, but enough to make
`~instrument.Instrument` happy.
Communicates with a socket and makes it look like a `file`. Note that this
is used instead of `socket.makefile`, as that method does not support
timeouts. We do not support all features of `file`-like objects here, but
enough to make `~instrument.Instrument` happy.
"""

def __init__(self, conn):
Expand All @@ -50,7 +50,7 @@ def __init__(self, conn):
self._conn = conn
self._terminator = '\n'
else:
raise TypeError('SocketWrapper must wrap a socket.socket object.')
raise TypeError('SocketCommunicator must wrap a socket.socket object.')

## PROPERTIES ##

Expand All @@ -70,10 +70,10 @@ def terminator(self):
@terminator.setter
def terminator(self, newval):
if not isinstance(newval, str):
raise TypeError('Terminator for SocketWrapper must be specified '
'as a single character string.')
raise TypeError('Terminator for SocketCommunicator must be '
'specified as a single character string.')
if len(newval) > 1:
raise ValueError('Terminator for SocketWrapper must only be 1 '
raise ValueError('Terminator for SocketCommunicator must only be 1 '
'character long.')
self._terminator = newval

Expand Down Expand Up @@ -117,8 +117,8 @@ def tell(self):

def flush_input(self):
'''
Instruct the wrapper to flush the input buffer, discarding the entirety
of its contents.
Instruct the communicator to flush the input buffer, discarding the
entirety of its contents.
'''
_ = self.read(-1) # Read in everything in the buffer and trash it

Expand Down
@@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# usbwrapper.py: Wraps USB connections into a filelike object.
# usb_communicator.py: Wraps USB connections into a filelike object.
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down Expand Up @@ -32,7 +32,7 @@

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

class USBWrapper(io.IOBase, AbstractCommunicator):
class USBCommunicator(io.IOBase, AbstractCommunicator):
'''
'''
Expand Down Expand Up @@ -60,10 +60,10 @@ def terminator(self):
@terminator.setter
def terminator(self, newval):
if not isinstance(newval, str):
raise TypeError('Terminator for USBWrapper must be specified '
raise TypeError('Terminator for USBCommunicator must be specified '
'as a single character string.')
if len(newval) > 1:
raise ValueError('Terminator for USBWrapper must only be 1 '
raise ValueError('Terminator for USBCommunicator must only be 1 '
'character long.')
self._terminator = newval

Expand Down Expand Up @@ -96,8 +96,8 @@ def tell(self):

def flush_input(self):
'''
Instruct the wrapper to flush the input buffer, discarding the entirety
of its contents.
Instruct the communicator to flush the input buffer, discarding the
entirety of its contents.
'''
raise NotImplementedError

Expand Down
@@ -1,10 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# usbtmc.py: Communicator that uses Python-USBTMC to communicate with TMC
# devices.
# usbtmc_communicator.py: Communicator that uses Python-USBTMC to interface
# with TMC devices.
##
# © 2013 Steven Casagrande (scasagrande@galvant.ca).
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
Expand Down

0 comments on commit a51e220

Please sign in to comment.