Skip to content

Commit

Permalink
Merge 760feec into bb4ab21
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Mendes committed Jun 14, 2018
2 parents bb4ab21 + 760feec commit bc0787a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -10,6 +10,10 @@ Thumbs.db
## Build directories ##
doc/_build

## Venv
.venv/


## setup.py generated files ##
MANIFEST

Expand All @@ -20,6 +24,7 @@ MANIFEST
*.so

# Packages
.egg/
*.egg
*.egg-info
dist
Expand Down
10 changes: 9 additions & 1 deletion instruments/abstract_instruments/comm/abstract_comm.py
Expand Up @@ -12,6 +12,7 @@

import abc
import logging
import struct

from future.utils import with_metaclass

Expand Down Expand Up @@ -202,7 +203,14 @@ def read(self, size=-1, encoding="utf-8"):
:return: The read string from the connection
:rtype: `str`
"""
return self.read_raw(size).decode(encoding)
if encoding == 'utf-8':
return self.read_raw(size).decode(encoding)

elif encoding == 'IEEE-754/64':
return struct.unpack('>d', self.read_raw(size))[0]

else:
raise NotImplementedError

def sendcmd(self, msg):
"""
Expand Down
9 changes: 3 additions & 6 deletions instruments/abstract_instruments/comm/visa_communicator.py
Expand Up @@ -124,14 +124,11 @@ def read_raw(self, size=-1):
:rtype: `bytes`
"""
if size >= 0:
while len(self._buf) < size:
data = self._conn.read()
if data == "":
break
self._buf += data
self._buf += self._conn.read_bytes(size)
msg = self._buf[:size]
# Remove the front of the buffer.
del self._buf[:size]

elif size == -1:
# Read the whole contents, appending the buffer we've already read.
msg = self._buf + self._conn.read()
Expand Down Expand Up @@ -193,4 +190,4 @@ def _query(self, msg, size=-1):
:rtype: `str`
"""
msg += self._terminator
return self._conn.ask(msg)
return self._conn.query(msg)
4 changes: 2 additions & 2 deletions instruments/abstract_instruments/instrument.py
Expand Up @@ -151,7 +151,7 @@ def query(self, cmd, size=-1):
)
return value

def read(self, size=-1):
def read(self, size=-1, encoding="utf-8"):
"""
Read the last line.
Expand All @@ -161,7 +161,7 @@ def read(self, size=-1):
connected instrument.
:rtype: `str`
"""
return self._file.read(size)
return self._file.read(size, encoding)

# PROPERTIES #

Expand Down
4 changes: 2 additions & 2 deletions instruments/tests/test_base_instrument.py
Expand Up @@ -710,13 +710,13 @@ def test_instrument_read():
inst._file.read.return_value = "foobar"

assert inst.read() == "foobar"
inst._file.read.assert_called_with(-1)
inst._file.read.assert_called_with(-1, 'utf-8')

inst._file = mock.MagicMock()
inst._file.read.return_value = "foobar"

assert inst.read(6) == "foobar"
inst._file.read.assert_called_with(6)
inst._file.read.assert_called_with(6, 'utf-8')


def test_instrument_write():
Expand Down
2 changes: 1 addition & 1 deletion instruments/thorlabs/pm100usb.py
Expand Up @@ -222,7 +222,7 @@ def averaging_count(self, newval):

})

def read(self, size=-1):
def read(self, size=-1, encoding='utf-8'):
"""
Reads a measurement from this instrument, according to its current
configuration mode.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,5 +1,6 @@
numpy
pyserial
pyvisa==1.9.0
quantities>=0.12.1
future>=0.15
enum34
Expand Down
36 changes: 20 additions & 16 deletions setup.py
Expand Up @@ -37,6 +37,7 @@
INSTALL_REQUIRES = [
"numpy",
"pyserial>=3.3",
'pyvisa>=1.9.0,<1.10.0'
"quantities",
"enum34",
"future",
Expand All @@ -45,9 +46,7 @@
"pyusb",
"ruamel.yaml"
]
EXTRAS_REQUIRE = {
'VISA': ["pyvisa"]
}


# HELPER FUNCTONS ############################################################

Expand All @@ -62,6 +61,7 @@ def read(*parts):
with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f:
return f.read()


META_FILE = read(META_PATH)


Expand All @@ -77,18 +77,22 @@ def find_meta(meta):
return meta_match.group(1)
raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta))


# MAIN #######################################################################

if __name__ == "__main__":
setup(
name=find_meta("title"),
version=find_meta("version"),
url=find_meta("uri"),
author=find_meta("author"),
author_email=find_meta("email"),
packages=PACKAGES,
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRE,
description=find_meta("description"),
classifiers=CLASSIFIERS
)

setup(
name=find_meta("title"),
version=find_meta("version"),
url=find_meta("uri"),
author=find_meta("author"),
author_email=find_meta("email"),
packages=PACKAGES,
install_requires=INSTALL_REQUIRES,
tests_require=[
'pytest >= 2.9.1',
'hypothesis'
],
description=find_meta("description"),
classifiers=CLASSIFIERS
)

0 comments on commit bc0787a

Please sign in to comment.