Exemplo n.º 1
0
 def do_test_client_Client_kwargs_subscriptionSettings(self, service):
     subscriptionSettings = SubscriptionSettings()
     subscriptionSettings.maxNotificationsPerPublish = 111
     result = self.doService(service, subscriptionSettings=subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 1)
     self.assertEqual(allSubscriptionInfos[0].subscriptionSettings, subscriptionSettings)
     # check if the following subscription is reused
     result = self.doService(service, subscriptionSettings=subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 1)
     self.assertEqual(allSubscriptionInfos[0].subscriptionSettings, subscriptionSettings)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 0)
     # check if the following subscription is not reused
     subscriptionSettings2 = SubscriptionSettings()
     subscriptionSettings2.connectTimeoutSec = 6.0
     result = self.doService(service, subscriptionSettings=subscriptionSettings2)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 2)
     self.assertEqual(allSubscriptionInfos[1].subscriptionSettings, subscriptionSettings2)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 1)
     # check if the following subscription is not reused
     subscriptionSettings.unique = True
     result = self.doService(service, subscriptionSettings=subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 3)
     self.assertEqual(allSubscriptionInfos[2].subscriptionSettings, subscriptionSettings)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 2)
     # check if the following subscription is not reused
     result = self.doService(service, subscriptionSettings=subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 4)
     self.assertEqual(allSubscriptionInfos[3].subscriptionSettings, subscriptionSettings)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 3)
     # check if a specific clientSubscriptionHandle may be reused:
     result = self.doService(service, clientSubscriptionHandle=3)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 4)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 3)
Exemplo n.º 2
0
 def do_test_client_Client_kwargs_subscriptionSettings(self, service):
     subscriptionSettings = SubscriptionSettings()
     subscriptionSettings.maxNotificationsPerPublish = 111
     result = self.doService(service, subscriptionSettings = subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 1)
     self.assertEqual(allSubscriptionInfos[0].subscriptionSettings, subscriptionSettings)
     # check if the following subscription is reused
     result = self.doService(service, subscriptionSettings = subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 1)
     self.assertEqual(allSubscriptionInfos[0].subscriptionSettings, subscriptionSettings)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 0)
     # check if the following subscription is not reused
     subscriptionSettings2 = SubscriptionSettings()
     subscriptionSettings2.connectTimeoutSec = 6.0
     result = self.doService(service, subscriptionSettings = subscriptionSettings2)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 2)
     self.assertEqual(allSubscriptionInfos[1].subscriptionSettings, subscriptionSettings2)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 1)
     # check if the following subscription is not reused
     subscriptionSettings.unique = True
     result = self.doService(service, subscriptionSettings = subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 3)
     self.assertEqual(allSubscriptionInfos[2].subscriptionSettings, subscriptionSettings)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 2)
     # check if the following subscription is not reused
     result = self.doService(service, subscriptionSettings = subscriptionSettings)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 4)
     self.assertEqual(allSubscriptionInfos[3].subscriptionSettings, subscriptionSettings)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 3)
     # check if a specific clientSubscriptionHandle may be reused:
     result = self.doService(service, clientSubscriptionHandle = 3)
     self.assertTrue(result.overallStatus.isGood())
     allSubscriptionInfos = self.client.allSubscriptionInformations()
     self.assertEqual(len(allSubscriptionInfos), 4)
     self.assertEqual(result.targets[0].clientSubscriptionHandle, 3)
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()
tab1SubscriptionSettings.unique = True
tab1SubscriptionSettings.publishingIntervalSec = 2.0
# tab 2:
tab2SubscriptionSettings = SubscriptionSettings()
tab2SubscriptionSettings.unique = True
tab2SubscriptionSettings.publishingIntervalSec = 2.0
# create the subscriptions and monitored items:
tab1Result = myClient.createMonitoredData( [address0] , subscriptionSettings = tab1SubscriptionSettings )
tab2Result = myClient.createMonitoredData( [address0] , subscriptionSettings = tab2SubscriptionSettings )
# disable the subscription for tab 2:
myClient.setPublishingMode(clientSubscriptionHandle = tab2Result.targets[0].clientSubscriptionHandle, 
                           publishingEnabled        = False)


# ==================================================================================================
# Keeping full control over the sessions and subscriptions
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()
tab1SubscriptionSettings.unique = True
tab1SubscriptionSettings.publishingIntervalSec = 2.0
# tab 2:
tab2SubscriptionSettings = SubscriptionSettings()
tab2SubscriptionSettings.unique = True
tab2SubscriptionSettings.publishingIntervalSec = 2.0
# create the subscriptions and monitored items:
tab1Result = myClient.createMonitoredData(
    [address0], subscriptionSettings=tab1SubscriptionSettings)
tab2Result = myClient.createMonitoredData(
    [address0], subscriptionSettings=tab2SubscriptionSettings)
# disable the subscription for tab 2:
myClient.setPublishingMode(
    clientSubscriptionHandle=tab2Result.targets[0].clientSubscriptionHandle,
    publishingEnabled=False)