Skip to content
Open
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
27 changes: 27 additions & 0 deletions lantz/visa.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class MessageVisaDriver(TextualMixin, Driver):
ENCODING = 'ascii'

RECV_CHUNK = -1
# When RECV_CHUNK==-1, read all available data, RECV_BUFFER_SIZE bytes at a
# time.
RECV_BUFFER_SIZE = 1<<8

def __init__(self, resource_name, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -111,6 +114,30 @@ def finalize(self):
def is_open(self):
return self.vi is not None

def raw_recv(self, size):
"""Receive raw bytes to the instrument.

:param size: number of bytes to receive
:return: received bytes
:return type: bytes

If a timeout is set, it may return less bytes than requested.
If size == -1, then the number of available bytes will be read.

"""

if not size or size == -1:
buffers = []
while True:
data = self.visa.read(self.vi, self.RECV_BUFFER_SIZE)
buffers.append(data)
if len(data) < self.RECV_BUFFER_SIZE:
# Timeout or terminator
return b''.join(buffers)
else:
data = self.visa.read(self.vi, size)
return data


class SerialVisaDriver(MessageVisaDriver):
"""Base class for drivers that communicate with instruments
Expand Down