Skip to content

Commit

Permalink
Merge pull request #106 from Galvant/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes for #104
  • Loading branch information
scasagrande committed Apr 23, 2016
2 parents 61a0da0 + 25a7411 commit c164d0c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, filelike, gpib_address):
if self._version <= 4:
self._eos = 10
else:
self._eos = 2
self._eos = "\n" # pylint: disable=redefined-variable-type

# PROPERTIES #

Expand Down
9 changes: 5 additions & 4 deletions instruments/abstract_instruments/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,17 @@ def binblockread(self, data_width, fmt=None):
default.
"""
# This needs to be a # symbol for valid binary block
symbol = self._file.read(1)
if symbol != "#": # Check to make sure block is valid
symbol = self._file.read_raw(1)
if symbol != b"#": # Check to make sure block is valid
raise IOError("Not a valid binary block start. Binary blocks "
"require the first character to be #.")
"require the first character to be #, instead got "
"{}".format(symbol))
else:
# Read in the num of digits for next part
digits = int(self._file.read_raw(1))

# Read in the num of bytes to be read
num_of_bytes = int(self._file.read(digits))
num_of_bytes = int(self._file.read_raw(digits))

# Make or use the required format string.
if fmt is None:
Expand Down
34 changes: 34 additions & 0 deletions instruments/tests/test_base_instrument.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module containing tests for the base Instrument class
"""

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

from __future__ import absolute_import

from builtins import bytes

# pylint: disable=unused-import
from nose.tools import raises
import quantities as pq

import numpy as np

import instruments as ik
from instruments.tests import expected_protocol

# TESTS ######################################################################


def test_instrument_binblockread():
with expected_protocol(
ik.Instrument,
[],
[
b"#210" + bytes.fromhex("00000001000200030004") + b"0",
],
sep="\n"
) as inst:
np.testing.assert_array_equal(inst.binblockread(2), [0, 1, 2, 3, 4])
21 changes: 21 additions & 0 deletions instruments/tests/test_comm/test_gi_gpibusb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ def test_gpibusbcomm_init():
assert isinstance(comm._file, SerialCommunicator)


def test_gpibusbcomm_init_correct_values_new_firmware():
mock_gpib = mock.MagicMock()
mock_gpib.query.return_value = "5"
comm = GPIBCommunicator(mock_gpib, 1)

eq_(comm._terminator, "\n")
eq_(comm._version, 5)
eq_(comm._eos, "\n")
eq_(comm._eoi, True)
unit_eq(comm._timeout, 1000 * pq.millisecond)


def test_gpibusbcomm_init_correct_values_old_firmware():
# This test just has the differences between the new and old firmware
mock_gpib = mock.MagicMock()
mock_gpib.query.return_value = "4"
comm = GPIBCommunicator(mock_gpib, 1)

eq_(comm._eos, 10)


def test_gpibusbcomm_address():
# Create our communicator
comm = GPIBCommunicator(mock.MagicMock(), 1)
Expand Down

0 comments on commit c164d0c

Please sign in to comment.