Skip to content
Merged
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sudo: false
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ send, one can use the following functions to do so:
Python Version Compatibility
----------------------------

At this time, Python 2.7, 3.4, 3.5, 3.6, and 3.7 are supported. Should you encounter
At this time, Python 2.7, 3.5, 3.6, and 3.7 are supported. Should you encounter
any problems with this library that occur in one version or another, please
do not hesitate to let us know.

Expand All @@ -134,7 +134,7 @@ To run the tests against all supported version of Python, you will need to
have the binary for each installed, as well as any requirements needed to
install ``numpy`` under each Python version. On Debian/Ubuntu systems this means
you will need to install the ``python-dev`` package for each version of Python
supported (``python2.7-dev``, ``python3.4-dev``, etc).
supported (``python2.7-dev``, ``python3.7-dev``, etc).

With the required system packages installed, all tests can be run with ``tox``:

Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mock
pytest
pytest-mock
hypothesis
pylint==1.7.1
astroid==1.5.3
28 changes: 28 additions & 0 deletions doc/examples/minghe/ex_minghe_mhs5200.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python
from instruments.minghe import MHS5200
import quantities as pq

mhs = MHS5200.open_serial(vid=6790, pid=29987, baud=57600)
print(mhs.serial_number)
mhs.channel[0].frequency = 3000000*pq.Hz
print(mhs.channel[0].frequency)
mhs.channel[0].function = MHS5200.Function.sawtooth_down
print(mhs.channel[0].function)
mhs.channel[0].amplitude = 9.0*pq.V
print(mhs.channel[0].amplitude)
mhs.channel[0].offset = -0.5
print(mhs.channel[0].offset)
mhs.channel[0].phase = 90
print(mhs.channel[0].phase)

mhs.channel[1].frequency = 2000000*pq.Hz
print(mhs.channel[1].frequency)
mhs.channel[1].function = MHS5200.Function.square
print(mhs.channel[1].function)
mhs.channel[1].amplitude = 2.0*pq.V
print(mhs.channel[1].amplitude)
mhs.channel[1].offset = 0.0
print(mhs.channel[1].offset)
mhs.channel[1].phase = 15
print(mhs.channel[1].phase)

15 changes: 15 additions & 0 deletions doc/source/apiref/minghe.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
..
TODO: put documentation license header here.

.. currentmodule:: instruments.minghe

======
Minghe
======

:class:`MHS5200` Function Generator
===================================

.. autoclass:: MHS5200
:members:
:undoc-members:
1 change: 1 addition & 0 deletions instruments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from . import hp
from . import keithley
from . import lakeshore
from . import minghe
from . import newport
from . import oxford
from . import phasematrix
Expand Down
22 changes: 13 additions & 9 deletions instruments/abstract_instruments/comm/loopback_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,21 @@ def read_raw(self, size=-1):
:rtype: `bytes`
"""
if self._stdin is not None:
if size >= 0:
if size == -1 or size is None:
result = bytes()
if self._terminator:
while result.endswith(self._terminator.encode("utf-8")) is False:
c = self._stdin.read(1)
if c == b'':
break
result += c
return result[:-len(self._terminator)]
return self._stdin.read(-1)

elif size >= 0:
input_var = self._stdin.read(size)
return bytes(input_var)
elif size == -1:
result = bytes()
while result.endswith(self._terminator.encode("utf-8")) is False:
c = self._stdin.read(1)
if c == b'':
break
result += c
return result[:-len(self._terminator)]

else:
raise ValueError("Must read a positive value of characters.")
else:
Expand Down
16 changes: 13 additions & 3 deletions instruments/abstract_instruments/comm/serial_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,23 @@ def read_raw(self, size=-1):
return resp
elif size == -1:
result = bytes()
while result.endswith(self._terminator.encode("utf-8")) is False:
# If the terminator is empty, we can't use endswith, but must
# read as many bytes as are available.
# On the other hand, if terminator is nonempty, we can check
# that the tail end of the buffer matches it.
c = None
term = self._terminator.encode('utf-8') if self._terminator else None
while not (
result.endswith(term)
if term is not None else
c == b''
):
c = self._conn.read(1)
if c == b'':
if c == b'' and term is not None:
raise IOError("Serial connection timed out before reading "
"a termination character.")
result += c
return result[:-len(self._terminator)]
return result[:-len(term)] if term is not None else result
else:
raise ValueError("Must read a positive value of characters.")

Expand Down
Loading