# 2) Overriding the defaults
# ==================================================================================================

# If needed, you can also configure the settings for each service call, using the **kwargs arguments
# of read/write/call/...

# e.g. set some special session settings for a specific read() call:
mySessionSettings = SessionSettings()
mySessionSettings.connectTimeoutSec = 0.5
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)
예제 #2
0
settings.discoveryUrls.append("opc.tcp://localhost:48010")

# create the client
myClient = Client(settings)



# read the node attributes all at once
print("")
print("First option: use the convenience function read() to read data synchronously")
print("============================================================================")
    
# OPTIONAL: You could also provide a ReadSettings to configure a call timeout, 
#           or maximum age of the values, or ... 
serviceSettings = ReadSettings()
serviceSettings.callTimeoutSec = 0.5
serviceSettings.maxAgeSec = 1.0

# OPTIONAL: And you could also provide a SessionConfig to configure the sessions 
#           (e.g. set the timeout to 600.0 seconds)
#           For more info about SessionConfigs, see the sessionconfig_example
sessionSettings = SessionSettings()
sessionSettings.sessionTimeoutSec = 600.0

try:
    # now read the node attributes
    readResult = myClient.read( addresses     = [someDoubleNode, someUInt32Node, someStringNode, 
                                                 someLocalizedTextNode, someSByteArrayNode],
                                serviceSettings = serviceSettings, # optional argument
                                sessionSettings = sessionSettings) # optional argument
    
# 2) Overriding the defaults
# ==================================================================================================

# If needed, you can also configure the settings for each service call, using the **kwargs arguments
# of read/write/call/...

# e.g. set some special session settings for a specific read() call:
mySessionSettings = SessionSettings()
mySessionSettings.connectTimeoutSec = 0.5
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)
myClientSettings.defaultReadSettings.maxAgeSec      = 10.0
myClientSettings.defaultMethodCallSettings.callTimeoutSec = 2.0
myClientSettings.defaultWriteSettings.callTimeoutSec = 2.0
myClientSettings.defaultBrowseSettings.callTimeoutSec = 2.0
# and so on, and so on ...

# the clientSettings are in use as soon as you provide them again to the Client:
myClient.setClientSettings(myClientSettings)

# In case you want to choose different settings for specific read/write/... calls, then you can
# provide them also:
mySpecialSessionSettings = SessionSettings() 
mySpecialSessionSettings.sessionTimeoutSec = 500.0
mySpecialSessionSettings.connectTimeoutSec = 0.5
mySpecialReadSettings = ReadSettings()
mySpecialReadSettings.callTimeoutSec = 2.0
mySpecialReadSettings.maxAgeSec      = 10.0

result = myClient.read(addresses       = [address_TSetpoint, address_HeaterStatus],
                       attributeId     = pyuaf.util.attributeids.DisplayName,
                       sessionSettings = mySpecialSessionSettings,
                       serviceSettings = mySpecialReadSettings)



print("")
print("################################################################################################################")
print("Step 6: Learn how 'requests' and 'results' actually look like, and how you can configure them even more in detail")
print("################################################################################################################")
print("")
예제 #5
0
myClientSettings.defaultReadSettings.maxAgeSec = 10.0
myClientSettings.defaultMethodCallSettings.callTimeoutSec = 2.0
myClientSettings.defaultWriteSettings.callTimeoutSec = 2.0
myClientSettings.defaultBrowseSettings.callTimeoutSec = 2.0
# and so on, and so on ...

# the clientSettings are in use as soon as you provide them again to the Client:
myClient.setClientSettings(myClientSettings)

# In case you want to choose different settings for specific read/write/... calls, then you can
# provide them also:
mySpecialSessionSettings = SessionSettings()
mySpecialSessionSettings.sessionTimeoutSec = 500.0
mySpecialSessionSettings.connectTimeoutSec = 0.5
mySpecialReadSettings = ReadSettings()
mySpecialReadSettings.callTimeoutSec = 2.0
mySpecialReadSettings.maxAgeSec = 10.0

result = myClient.read(
    addresses=[address_TSetpoint, address_HeaterStatus],
    attributeId=pyuaf.util.attributeids.DisplayName,
    sessionSettings=mySpecialSessionSettings,
    serviceSettings=mySpecialReadSettings,
)


print("")
print(
    "################################################################################################################"
)
print(