Esempio n. 1
0
async def main():
    client = Client("opc.tcp://localhost:53530/OPCUA/SimulationServer/")
    client.set_security_string(
        "Basic256Sha256,Sign,certificate-example.der,private-key-example.pem")
    client.session_timeout = 2000
    async with client:
        root = client.nodes.root
        objects = client.nodes.objects
        while True:
            print("childs og objects are: ", await objects.get_children())
            await asyncio.sleep(1)
Esempio n. 2
0
async def test_subscription_keepalive_count(mocker):
    """
    Check the subscription parameter MaxKeepAliveCount value
    with various publishInterval and session_timeout values.
    """

    mock_subscription = mocker.patch(
        "asyncua.common.subscription.Subscription.init", new=CoroutineMock())
    c = Client("opc.tcp://fake")
    # session timeout < publish_interval
    c.session_timeout = 30000  # ms
    publish_interval = 1000  # ms
    handler = 123
    sub = await c.create_subscription(publish_interval, handler)
    assert sub.parameters.RequestedMaxKeepAliveCount == 22
    # session_timeout > publish_interval
    c.session_timeout = 30000
    publish_interval = 75000
    sub = await c.create_subscription(publish_interval, handler)
    assert sub.parameters.RequestedMaxKeepAliveCount == 0
Esempio n. 3
0
def test_get_keepalive_count(mocker):
    """
    Check the subscription parameter MaxKeepAliveCount value
    with various publishInterval and session_timeout values.
    """

    c = Client("opc.tcp://fake")
    # session timeout < publish_interval
    publish_interval = 1000 # ms
    c.session_timeout = 30000 # ms
    keepalive_count = c.get_keepalive_count(publish_interval)
    assert keepalive_count == 22
    # session_timeout > publish_interval
    publish_interval = 75000
    c.session_timeout = 30000
    keepalive_count = c.get_keepalive_count(publish_interval)
    assert keepalive_count == 0
    # RequestedPublishingInterval == 0
    publish_interval = 0
    keepalive_count = c.get_keepalive_count(publish_interval)
    assert keepalive_count == 22
Esempio n. 4
0
    def __init__(self,
                 config: HaConfig,
                 security: Optional[HaSecurityConfig] = None,
                 loop=None) -> None:
        self._config: HaConfig = config
        self._keepalive_task: Dict[KeepAlive, asyncio.Task] = {}
        self._manager_task: Dict[HaManager, asyncio.Task] = {}
        self._reconciliator_task: Dict[Reconciliator, asyncio.Task] = {}
        self._gen_sub: Generator[str, None, None] = self.generate_sub_name()

        self.loop: asyncio.unix_events._UnixSelectorEventLoop = (
            loop or asyncio.get_event_loop())
        self._url_to_reset_lock = asyncio.Lock(loop=self.loop)
        self._ideal_map_lock: asyncio.Lock = asyncio.Lock(loop=self.loop)
        self._client_lock: asyncio.Lock = asyncio.Lock(loop=self.loop)

        self.clients: Dict[Client, ServerInfo] = {}
        self.active_client: Optional[Client] = None
        # full type: Dict[str, SortedDict[str, VirtualSubscription]]
        self.ideal_map: Dict[str, SortedDict] = {}
        self.sub_names: Set[str] = set()
        self.url_to_reset: Set[str] = set()
        self.is_running = False

        if config.ha_mode != HaMode.WARM:
            # TODO
            # Check if transparent redundancy support exist for the server (nodeid=2035)
            # and prevent using HaClient with such servers.
            raise NotImplementedError(
                f"{config.ha_mode} not currently supported by HaClient")

        for url in self.urls:
            c = Client(url,
                       timeout=self._config.request_timeout,
                       loop=self.loop)
            # timeouts for the session and secure channel are in ms
            c.session_timeout = self._config.session_timeout * 1000
            c.secure_channel_timeout = self._config.secure_channel_timeout * 1000
            c.description = self._config.session_name
            server_info = ServerInfo(url)
            self.clients[c] = server_info
            self.ideal_map[url] = SortedDict()

        # security can also be set via the set_security method
        self.security_config: HaSecurityConfig = (security if security else
                                                  HaSecurityConfig())
        self.manager = HaManager(self, self._config.manager_timer)
        self.reconciliator = Reconciliator(self._config.reconciliator_timer,
                                           self)