mySessionSettings.sessionTimeoutSec = 100.0 # simply mention 'sessionSettings = ...' to use these settings as a **kwarg: myClient.read( [address0, address1], sessionSettings = mySessionSettings ) # e.g. set some special service settings for a specific read() call: myReadSettings = ReadSettings() myReadSettings.callTimeoutSec = 0.5 myReadSettings.maxAgeSec = 1.0 # simply mention 'serviceSettings = ...' to use these settings as a **kwarg: myClient.read( [address0, address1], serviceSettings = myReadSettings ) # or combine them: myClient.read( [address0, address1], serviceSettings = myReadSettings, sessionSettings = mySessionSettings ) # e.g. set some special subscription settings for a specific createMonitoredData() call: mySubscriptionSettings = SubscriptionSettings() mySubscriptionSettings.publishingIntervalSec = 2.0 mySubscriptionSettings.priority = 20 myClient.createMonitoredData( [address0, address1], subscriptionSettings = mySubscriptionSettings ) # Both the SessionSettings and SubscriptionSettings have a special 'unique' attribute, which # can be True or False. # By default it is False, which tells the PyUAF Client that it may re-use a session (or subscription) # if there exists one with the same SessionSettings (or SubscriptionSettings). # However, if you set the unique attribute to True, then the PyUAF Client will ignore any existing # sessions (or subscriptions) and create a new unique one. # This is useful, e.g. if your HMI (Human Machine Interface) has several tabs, then you can create # a subscription for each tab (to hold all monitored items for that specific tab). Using the # setPublishingMode() service, you can then temporarily enable the subscription for a visible # tab, and temporarily disable the subscription for a hidden one. Like this: # tab 1: tab1SubscriptionSettings = SubscriptionSettings()
# define the namespace URI and server URI of the UaServerCPP demo server demoServerUri = "urn:UnifiedAutomation:UaServerCpp" demoNamespaceUri = "http://www.unifiedautomation.com/DemoServer/" # define the ClientSettings: settings = ClientSettings() settings.applicationName = "MyClient" settings.discoveryUrls.append("opc.tcp://localhost:48010") # create the client myClient = Client(settings) # 1) optionally: configure the subscription # ------------------------------------------ subSettings = SubscriptionSettings() subSettings.publishingIntervalSec = 1.0 subSettings.maxKeepAliveCount = 5 # Explanation: # - The subscription will send at most one bunch of changed data samples per second, due to the # publishing interval of 1 second. # - If the sampled data does not change, then the server does not have to send notifications to # the client. However, when the sampled data does not change for 5 seconds in a row # (5 seconds = maxKeepAliveCount * publishingIntervalSec), then the server # will send a KeepAlive notification to the client, as a kind of "heartbeat". # 2) configure the monitored items # -------------------------------- target0 = CreateMonitoredDataRequestTarget() target0.address = Address( NodeId("Demo.Dynamic.Scalar.Float", demoNamespaceUri), demoServerUri)
demoServerUri = "urn:UnifiedAutomation:UaServerCpp" demoNamespaceUri = "http://www.unifiedautomation.com/DemoServer/" # define the ClientSettings: settings = ClientSettings() settings.applicationName = "MyClient" settings.discoveryUrls.append("opc.tcp://localhost:48010") # create the client myClient = Client(settings) # 1) optionally: configure the subscription # ------------------------------------------ subSettings = SubscriptionSettings() subSettings.publishingIntervalSec = 1.0 subSettings.maxKeepAliveCount = 5 # Explanation: # - The subscription will send at most one bunch of changed data samples per second, due to the # publishing interval of 1 second. # - If the sampled data does not change, then the server does not have to send notifications to # the client. However, when the sampled data does not change for 5 seconds in a row # (5 seconds = maxKeepAliveCount * publishingIntervalSec), then the server # will send a KeepAlive notification to the client, as a kind of "heartbeat". # 2) configure the monitored items # -------------------------------- target0 = CreateMonitoredDataRequestTarget() target0.address = Address( NodeId("Demo.Dynamic.Scalar.Float", demoNamespaceUri), demoServerUri )
myClient.read([address0, address1], sessionSettings=mySessionSettings) # e.g. set some special service settings for a specific read() call: myReadSettings = ReadSettings() myReadSettings.callTimeoutSec = 0.5 myReadSettings.maxAgeSec = 1.0 # simply mention 'serviceSettings = ...' to use these settings as a **kwarg: myClient.read([address0, address1], serviceSettings=myReadSettings) # or combine them: myClient.read([address0, address1], serviceSettings=myReadSettings, sessionSettings=mySessionSettings) # e.g. set some special subscription settings for a specific createMonitoredData() call: mySubscriptionSettings = SubscriptionSettings() mySubscriptionSettings.publishingIntervalSec = 2.0 mySubscriptionSettings.priority = 20 myClient.createMonitoredData([address0, address1], subscriptionSettings=mySubscriptionSettings) # Both the SessionSettings and SubscriptionSettings have a special 'unique' attribute, which # can be True or False. # By default it is False, which tells the PyUAF Client that it may re-use a session (or subscription) # if there exists one with the same SessionSettings (or SubscriptionSettings). # However, if you set the unique attribute to True, then the PyUAF Client will ignore any existing # sessions (or subscriptions) and create a new unique one. # This is useful, e.g. if your HMI (Human Machine Interface) has several tabs, then you can create # a subscription for each tab (to hold all monitored items for that specific tab). Using the # setPublishingMode() service, you can then temporarily enable the subscription for a visible # tab, and temporarily disable the subscription for a hidden one. Like this: # tab 1: