Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init(self):
"""Singleton class constructor.
See vpp43.Singleton for details.
"""
ResourceTemplate.__init__(self)
# I have "session" as an alias because the specification calls the "vi"
# handle "session" for the resource manager.
self.session = self.vi = vpp43.open_default_resource_manager()
self.resource_name)
return interface_type
def close(self):
"""Closes the VISA session and marks the handle as invalid.
This method can be called to ensure that all resources are freed.
Finishing the object by __del__ seems to work safely enough though.
"""
if self.vi is not None:
vpp43.close(self.vi)
self.vi = None
class ResourceManager(vpp43.Singleton, ResourceTemplate):
"""Singleton class for the default resource manager."""
def init(self):
"""Singleton class constructor.
See vpp43.Singleton for details.
"""
ResourceTemplate.__init__(self)
# I have "session" as an alias because the specification calls the "vi"
# handle "session" for the resource manager.
self.session = self.vi = vpp43.open_default_resource_manager()
def __repr__(self):
return "ResourceManager()"
def read_raw(self):
"""Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are checked or
stripped. You get the pristine message.
"""
warnings.filterwarnings("ignore", "VI_SUCCESS_MAX_CNT")
try:
buffer = b""
chunk = vpp43.read(self.vi, self.chunk_size)
buffer += chunk
while vpp43.get_status() == VI_SUCCESS_MAX_CNT:
chunk = vpp43.read(self.vi, self.chunk_size)
buffer += chunk
finally:
_removefilter("ignore", "VI_SUCCESS_MAX_CNT")
return buffer
def send_ifc(self):
"""Send "interface clear" signal to the GPIB."""
vpp43.gpib_send_ifc(self.vi)
def read_raw(self):
"""Read the unmodified string sent from the instrument to the computer.
In contrast to read(), no termination characters are checked or
stripped. You get the pristine message.
"""
warnings.filterwarnings("ignore", "VI_SUCCESS_MAX_CNT")
try:
buffer = b""
chunk = vpp43.read(self.vi, self.chunk_size)
buffer += chunk
while vpp43.get_status() == VI_SUCCESS_MAX_CNT:
chunk = vpp43.read(self.vi, self.chunk_size)
buffer += chunk
finally:
_removefilter("ignore", "VI_SUCCESS_MAX_CNT")
return buffer
def write(self, message):
"""Write a string message to the device.
The term_chars are appended to it, unless they are already.
:param message: the string message to be sent.
"""
if self.__term_chars and not message.endswith(self.__term_chars):
message += self.__term_chars
elif self.__term_chars is None and not message.endswith(CR + LF):
message += CR + LF
vpp43.write(self.vi, message)
if self.delay > 0.0:
time.sleep(self.delay)
def __init__(self, resource_name=None, **keyw):
_warn_for_invalid_keyword_arguments(keyw, ("lock", "timeout"))
if self.__class__ is ResourceTemplate:
raise TypeError("trying to instantiate an abstract class")
if resource_name is None: # is none for the resource manager
return
warnings.filterwarnings("ignore", "VI_SUCCESS_DEV_NPRESENT")
self.vi = vpp43.open(resource_manager.session, resource_name,
keyw.get("lock", VI_NO_LOCK))
if vpp43.get_status() == VI_SUCCESS_DEV_NPRESENT:
# okay, the device was not ready when we opened the session.
# Now it gets five seconds more to become ready. Every 0.1
# seconds we probe it with viClear.
passed_time = 0 # in seconds
while passed_time < 5.0:
time.sleep(0.1)
passed_time += 0.1
try:
vpp43.clear(self.vi)
except VisaIOError as error:
if error.error_code != VI_ERROR_NLISTENERS:
raise
break
def close(self):
"""Closes the VISA session and marks the handle as invalid.
This method can be called to ensure that all resources are freed.
Finishing the object by __del__ seems to work safely enough though.
"""
if self.vi is not None:
vpp43.close(self.vi)
self.vi = None
def clear(self):
"""Resets the device. This operation is highly bus-dependent."""
vpp43.clear(self.vi)
def trigger(self):
"""Sends a software trigger to the device."""
vpp43.set_attribute(self.vi, VI_ATTR_TRIG_ID, VI_TRIG_SW)
vpp43.assert_trigger(self.vi, VI_TRIG_PROT_DEFAULT)