High level client to connect to an OPC-UA server. This class makes it easy to connect and browse address space. It attempts to expose as much functionality as possible but if you want more flexibility it is possible and advised to use the UaClient object, available as self.uacl
| 79 | |
| 80 | |
| 81 | class Client(object): |
| 82 | """ |
| 83 | High level client to connect to an OPC-UA server. |
| 84 | |
| 85 | This class makes it easy to connect and browse address space. |
| 86 | It attempts to expose as much functionality as possible |
| 87 | but if you want more flexibility it is possible and advised to |
| 88 | use the UaClient object, available as self.uaclient, which offers |
| 89 | the raw OPC-UA services interface. |
| 90 | """ |
| 91 | |
| 92 | if use_crypto is False: |
| 93 | logging.getLogger(__name__).warning("cryptography is not installed, use of crypto disabled") |
| 94 | |
| 95 | def __init__(self, url, timeout=4): |
| 96 | """ |
| 97 | |
| 98 | :param url: url of the server. |
| 99 | if you are unsure of url, write at least hostname |
| 100 | and port and call get_endpoints |
| 101 | |
| 102 | :param timeout: |
| 103 | Each request sent to the server expects an answer within this |
| 104 | time. The timeout is specified in seconds. |
| 105 | |
| 106 | Some other client parameters can be changed by setting |
| 107 | attributes on the constructed object: |
| 108 | |
| 109 | secure_channel_timeout |
| 110 | Timeout for the secure channel, specified in milliseconds. |
| 111 | |
| 112 | session_timeout |
| 113 | Timeout for the session, specified in milliseconds. |
| 114 | |
| 115 | See the source code for the exhaustive list. |
| 116 | """ |
| 117 | _logger = logging.getLogger(__name__) |
| 118 | self.server_url = urlparse(url) |
| 119 | # take initial username and password from the url |
| 120 | self._username = self.server_url.username |
| 121 | self._password = self.server_url.password |
| 122 | self.name = "Pure Python Client" |
| 123 | self.description = self.name |
| 124 | self.application_uri = "urn:freeopcua:client" |
| 125 | self.product_uri = "urn:freeopcua.github.io:client" |
| 126 | self.security_policy = ua.SecurityPolicy() |
| 127 | self.secure_channel_id = None |
| 128 | self.secure_channel_timeout = 3600000 # 1 hour |
| 129 | self.session_timeout = 3600000 # 1 hour |
| 130 | self._policy_ids = [] |
| 131 | self.uaclient = UaClient(timeout) |
| 132 | self.user_certificate = None |
| 133 | self.user_private_key = None |
| 134 | self._server_nonce = None |
| 135 | self._session_counter = 1 |
| 136 | self.keepalive = None |
| 137 | self.nodes = Shortcuts(self.uaclient) |
| 138 | self.max_messagesize = 0 # No limits |
no outgoing calls