本文整理汇总了Python中mi.core.instrument.instrument_driver.SingleConnectionInstrumentDriver类的典型用法代码示例。如果您正苦于以下问题:Python SingleConnectionInstrumentDriver类的具体用法?Python SingleConnectionInstrumentDriver怎么用?Python SingleConnectionInstrumentDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SingleConnectionInstrumentDriver类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, evt_callback):
"""
Driver constructor.
@param evt_callback Driver process event callback.
"""
#Construct superclass.
SingleConnectionInstrumentDriver.__init__(self, evt_callback)
示例2: __init__
def __init__(self, evt_callback, refdes=None):
"""
Driver constructor.
@param evt_callback Driver process event callback.
"""
#Construct superclass.
SingleConnectionInstrumentDriver.__init__(self, evt_callback, refdes)
self._slave_protocols = {}
示例3: __init__
def __init__(self, evt_callback):
"""
InstrumentDriver constructor.
@param evt_callback Driver process event callback.
"""
SingleConnectionInstrumentDriver.__init__(self, evt_callback)
# multiple portAgentClient
self._connection = {}
示例4: __init__
def __init__(self, evt_callback):
"""
Driver constructor.
@param evt_callback Driver process event callback.
"""
#Construct superclass.
SingleConnectionInstrumentDriver.__init__(self, evt_callback)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED,
DriverEvent.DISCOVER,
self._handler_connected_discover)
示例5: __init__
def __init__(self, evt_callback):
"""
Driver constructor.
@param evt_callback Driver process event callback.
"""
#Construct superclass.
SingleConnectionInstrumentDriver.__init__(self, evt_callback)
# replace the driver's discover handler with one that applies the startup values after discovery
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED,
DriverEvent.DISCOVER,
self._handler_connected_discover)
示例6: _handler_connected_discover
def _handler_connected_discover(self, event, *args, **kwargs):
# Redefine discover handler so that we can apply startup params
# when we discover. Gotta get into command mode first though.
log.debug("in _handler_connected_discover")
result = SingleConnectionInstrumentDriver._handler_connected_protocol_event(self, event, *args, **kwargs)
self.apply_startup_params()
return result
示例7: TestUnitInstrumentDriver
class TestUnitInstrumentDriver(IonUnitTestCase):
"""
Test cases for instrument driver class. Functions in this class provide
instrument driver unit tests and provide a tutorial on use of
the driver interface.
"""
def setUp(self):
self.mock = DotDict()
self.mock.port_agent = Mock(name='port_agent_client')
self.mock.callback = Mock(name='callback')
self.driver = SingleConnectionInstrumentDriver(self.mock.callback)
def test_test_mode(self):
"""
Test driver test mode.
Ensure driver test mode attribute is set properly and verify
exceptions are thrown when not in test mode.
"""
# Ensure that we default to test mode off
self.assertFalse(self.driver._test_mode)
exception = False
try:
self.driver.set_test_mode(False)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertTrue(exception)
# Now set test mode and try to run again.
exception = False
try:
self.driver.set_test_mode(True)
self.assertTrue(self.driver._test_mode)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertFalse(exception)
示例8: setUp
def setUp(self):
self.mock = DotDict()
self.mock.port_agent = Mock(name='port_agent_client')
self.mock.callback = Mock(name='callback')
def mock_set(values, startup=True):
assert isinstance(values, dict)
return_string = ""
for key in values.keys():
return_string += "%s=%s" % (key, values[key]) # inefficient, I know
return return_string
self.driver = SingleConnectionInstrumentDriver(self.mock.callback)
# set some values
self.driver._protocol = InstrumentProtocol(self.mock.callback)
self.driver.set_resource = mock_set
self.driver._protocol._param_dict.add("foo", r'foo=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
startup_param=True,
default_value=10)
self.driver._protocol._param_dict.set_default("foo")
self.driver._protocol._param_dict.add("bar", r'bar=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=False,
startup_param=True,
default_value=15)
self.driver._protocol._param_dict.set_default("bar")
self.driver._protocol._param_dict.add("baz", r'baz=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
default_value=30)
self.driver._protocol._param_dict.set_default("baz")
self.driver._protocol._param_dict.add("bat", r'bat=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
startup_param=False,
default_value=40)
self.driver._protocol._param_dict.set_default("bat")
self.driver._protocol._cmd_dict.add("cmd1")
self.driver._protocol._cmd_dict.add("cmd2")
self.driver._protocol._driver_dict.add(DriverDictKey.VENDOR_SW_COMPATIBLE,
True)
示例9: TestUnitInstrumentDriver
class TestUnitInstrumentDriver(MiUnitTestCase):
"""
Test cases for instrument driver class. Functions in this class provide
instrument driver unit tests and provide a tutorial on use of
the driver interface.
"""
def setUp(self):
self.mock = DotDict()
self.mock.port_agent = Mock(name='port_agent_client')
self.mock.callback = Mock(name='callback')
def mock_set(values):
assert isinstance(values, dict)
return_string = ""
for key in values.keys():
return_string += "%s=%s" % (key, values[key]) # inefficient, I know
return return_string
self.driver = SingleConnectionInstrumentDriver(self.mock.callback)
# set some values
self.driver._protocol = InstrumentProtocol(self.mock.callback)
self.driver.set_resource = mock_set
self.driver._protocol._param_dict.add("foo", r'foo=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
startup_param=True,
default_value=10)
self.driver._protocol._param_dict.set_default("foo")
self.driver._protocol._param_dict.add("bar", r'bar=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=False,
startup_param=True,
default_value=15)
self.driver._protocol._param_dict.set_default("bar")
self.driver._protocol._param_dict.add("baz", r'baz=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
default_value=30)
self.driver._protocol._param_dict.set_default("baz")
self.driver._protocol._param_dict.add("bat", r'bat=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
startup_param=False,
default_value=40)
self.driver._protocol._param_dict.set_default("bat")
def test_test_mode(self):
"""
Test driver test mode.
Ensure driver test mode attribute is set properly and verify
exceptions are thrown when not in test mode.
"""
# Ensure that we default to test mode off
self.assertFalse(self.driver._test_mode)
exception = False
try:
self.driver.set_test_mode(False)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertTrue(exception)
# Now set test mode and try to run again.
exception = False
try:
self.driver.set_test_mode(True)
self.assertTrue(self.driver._test_mode)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertFalse(exception)
def test_direct_access_params(self):
"""
Tests to see how direct access parameters are setup and that they are
working properly.
"""
self.assertTrue(self.driver._protocol._param_dict.get("foo"), 10)
self.assertTrue(self.driver._protocol._param_dict.get("bar"), 15)
# use real driver sets here, the direct poke of the param dict is just
#.........这里部分代码省略.........
示例10: __init__
def __init__(self, evt_callback):
"""Instrument-specific enums
@param evt_callback The callback function to use for events
"""
SingleConnectionInstrumentDriver.__init__(self, evt_callback)
示例11: __init__
def __init__(self, evt_callback):
SingleConnectionInstrumentDriver.__init__(self, evt_callback)
示例12: _handler_connected_discover
def _handler_connected_discover(self, event, *args, **kwargs):
# Redefine discover handler so that we can apply startup params after we discover.
# For this instrument the driver puts the instrument into command mode during discover.
result = SingleConnectionInstrumentDriver._handler_connected_protocol_event(self, event, *args, **kwargs)
self.apply_startup_params()
return result
示例13: setUp
def setUp(self):
self.mock = DotDict()
self.mock.port_agent = Mock(name='port_agent_client')
self.mock.callback = Mock(name='callback')
self.driver = SingleConnectionInstrumentDriver(self.mock.callback)