Exemplo n.º 1
0
    def setUp(self):
        self.dt0 = pyuaf.util.DateTime()

        self.now = time.time()
        self.dt1 = DateTime(self.now)
        self.dt1_ = DateTime(self.dt1)
        self.dt2 = DateTime(self.now + 3.0)  # 3 seconds later
        self.dt3 = DateTime(self.now + 60 * 60 * 24 * 3)  # 3 days later
Exemplo n.º 2
0
 def test_client_Client_historyReadRaw(self):
  
     result = self.client.historyReadRaw([self.address_byte, self.address_double], # addresses
                                         DateTime(time.time() - 1.0),              # startTime
                                         DateTime(time.time()))                    # endTime
      
     self.assertTrue( result.overallStatus.isGood() )
     self.assertGreater( result.targets[0].dataValues , 0 )
     self.assertGreater( result.targets[1].dataValues , 0 )
Exemplo n.º 3
0
 def test_client_Client_processRequest_some_historyReadRawModifiedRequest(self):
      
     request = HistoryReadRawModifiedRequest(2) 
      
     request.targets[0].address = self.address_byte
     request.targets[1].address = self.address_double
     request.serviceSettingsGiven = True
     serviceSettings = pyuaf.client.settings.HistoryReadRawModifiedSettings()
     serviceSettings.startTime = DateTime(time.time() - 1.0)
     serviceSettings.endTime   = DateTime(time.time())
     request.serviceSettings = serviceSettings
     result = self.client.processRequest(request)
      
     self.assertTrue( result.overallStatus.isGood() )
     self.assertGreater( result.targets[0].dataValues , 0 )
     self.assertGreater( result.targets[1].dataValues , 0 )
    def test_client_Client_processRequest_some_historyReadRawModifiedRequest_with_automatic_continuation(
            self):

        request = HistoryReadRawModifiedRequest(2)

        request.targets[0].address = self.address_byte
        request.targets[1].address = self.address_double
        request.serviceConfig.serviceSettings.startTime = DateTime(
            self.startTime)
        request.serviceConfig.serviceSettings.endTime = DateTime(time.time())
        request.serviceConfig.serviceSettings.maxAutoReadMore = 20
        request.serviceConfig.serviceSettings.numValuesPerNode = 1  # ridiculously low, to force automatic calls

        result = self.client.processRequest(request)

        self.assertTrue(result.overallStatus.isGood())
        self.assertGreater(result.targets[0].dataValues, 0)
        self.assertGreater(result.targets[1].dataValues, 0)
        self.assertGreater(result.targets[0].autoReadMore, 0)
        self.assertGreater(result.targets[1].autoReadMore, 0)
Exemplo n.º 5
0
 def test_client_Client_processRequest_some_historyReadRawModifiedRequest_with_manual_continuation(self):
     
     request = HistoryReadRawModifiedRequest(1) 
     
     request.targets[0].address = self.address_byte
     serviceSettings = pyuaf.client.settings.HistoryReadRawModifiedSettings()
     serviceSettings.startTime        = DateTime(self.startTime)
     serviceSettings.endTime          = DateTime(time.time())
     serviceSettings.maxAutoReadMore  = 0   # force no automatic calls by the UAF
     serviceSettings.numValuesPerNode = 1   # ridiculously low, to force automatic calls
     
     request.serviceSettingsGiven = True
     request.serviceSettings = serviceSettings
     
     noOfManualBrowseNext = 0
     allData = pyuaf.util.DataValueVector()
     
     result = self.client.processRequest(request)
     
     while len(result.targets[0].continuationPoint) > 0 and noOfManualBrowseNext < 50:
         
         request.targets[0].continuationPoint = result.targets[0].continuationPoint
          
         result = self.client.processRequest(request)
          
         for i in xrange(len(result.targets[0].dataValues)):
             # IMPORTANT: use     <DataValueVector>.allData.append(result.targets[0].dataValues[i])
             #            or      <Python list>.append(DataValue(result.targets[0].dataValues[i]))
             #            but NOT <Python list>.append(result.targets[0].dataValues[i]))
             #            
             #            because <Python list>.append() will NOT COPY THE DATA! It will only 
             #            store the the pointer that was returned by (...).dataValues[i]! 
             allData.append(result.targets[0].dataValues[i])
          
         noOfManualBrowseNext += 1
     
     self.assertTrue( result.overallStatus.isGood() )
     self.assertGreater( len(allData) , 2 )
     self.assertGreater( noOfManualBrowseNext , 0 )
 print("======================================================================================")
 
 print("")
 print("First example:")
 print("-------------")
 
 # Read the raw historical data 
 #   - that is provided by the double node,
 #   - that was recorded during the past second
 #   - with a maximum of a 100 returned values 
 #     (we expect around 10 values, so 100 is a very safe margin) 
 #   - and let the UAF invoke at most 10 "continuation calls"
 #     (we expect that all data can be returned by a single call, so a maximum of 10 
 #      additional calls is again a very safe margin)
 result = myClient.historyReadRaw(addresses          = [doubleAddress],
                                  startTime          = DateTime(time.time() - 1.5),
                                  endTime            = DateTime(time.time()),
                                  numValuesPerNode   = 100, 
                                  maxAutoReadMore    = 10)
 
 # print the result:
 print(str(result))
 
 # do some processing on the result
 if result.targets[0].status.isNotGood():
     print("Could not read historical data from the double: %s" %str(result.targets[0].status))
 else:
     if len(result.targets[0].dataValues) == 0:
         # Strange, we didn't receive any historical data.
         # Check if this is expected behavior:
         if result.targets[0].opcUaStatusCode == opcuastatuscodes.OpcUa_GoodNoData:
Exemplo n.º 7
0
# Now read the historical data.
# Notice the 'maxAutoReadMore' argument: it says that *if* the historical data was split up into
# several chunks, then the UAF may automatically fetch the remaining data by sending additional
# requests for 10 times in a row.
# The reason is that a server (or a client) can choose to receive a large number of historical
# data in chunks, instead of all at once. Normally, as a client, you need to check the result
# of the HistoryRead request to see if all historical data is received (by checking the
# "continuationPoint"). If there is still historical data left on the server, you would have to
# fetch the remaining data manually by invoking more HistoryRead requests.
# Luckily, the UAF implements this behavior for you: you just have to specify the maximum number of
# requests that the UAF may automatically invoke for you.

now = time.time()
result = myClient.historyReadRaw(
    addresses=[address_ByteWithHistory, address_DoubleWithHistory],
    startTime=DateTime(now - 5.0),
    endTime=DateTime(now),
    maxAutoReadMore=10)

print("Result of the historical read:")
print(result)

# delete the client and create a new instance, so we can proceed cleanly with the next step of the tutorial
del myClient
myClient = Client(settings)

# =====================================================================================================================
print("")
print("Asynchronous calling methods")
print("============================")
print("")
Exemplo n.º 8
0
 def test_util_DateTime_addMilliSecs(self):
     dt = DateTime(self.dt1)
     dt.addMilliSecs(3000)
     self.assertEqual(dt, self.dt2)
Exemplo n.º 9
0
 def test_util_DateTime_setCtime(self):
     dt = DateTime()
     dt.setCtime(self.now)
     # check if the difference is smaller than 1 msec
     self.assertTrue(self.now - dt.ctime() <= 0.001)