Skip to content

When read() or query() is called, do not always send ++read #6

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

Open
wants to merge 3 commits into
base: master
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
4 changes: 4 additions & 0 deletions plx_gpib_ethernet/plx_gpib_ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def query(self, cmd, buffer_size=1024*1024):
self.write(cmd)
return self.read(buffer_size)

def query_controller(self, cmd, buffer_size=1024*1024):
self._send(cmd)
return self._recv(buffer_size)

def _send(self, value):
encoded_value = ('%s\n' % value).encode('ascii')
self.socket.send(encoded_value)
Expand Down
23 changes: 23 additions & 0 deletions tests/plx_gpib_ethernet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,26 @@ def test_it_reads_gpib_query_response(plx_with_mock_socket):
result = plx.query('*IDN?')

assert result == response


# .query_controller
def test_it_sends_controller_query(plx_with_mock_socket):
plx, mock_socket = plx_with_mock_socket
plx.connect()

mock_socket.in_buffer.append('\n')
plx.query_controller('++addr')

expected_commands = ['++addr\n']
assert mock_socket.out_buffer[-1:] == expected_commands


def test_it_reads_controller_query_response(plx_with_mock_socket):
plx, mock_socket = plx_with_mock_socket
plx.connect()

response = '2\n'
mock_socket.in_buffer.append(response)
result = plx.query_controller('++addr')

assert result == response