Beispiel #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
Beispiel #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 )
Beispiel #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 )
Beispiel #4
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
    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)
Beispiel #6
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 )
Beispiel #7
0
def test(args):
    
    print("util.datetime")
    
    print(" - testing pyuaf.util.DateTime()")
    
    dt0 = pyuaf.util.DateTime()
    
    now  = time.time()
    dt1  = DateTime(now)
    dt1_ = DateTime(dt1)
    dt2  = DateTime(now + 3.0) # 3 seconds later
    dt3  = DateTime(now + 60*60*24*3) # 3 days later
    
    print(" - testing pyuaf.util.DateTime().isNull()")
    assert dt0.isNull() == True
    assert dt1.isNull() == False
    
    print(" - testing pyuaf.util.DateTime().ctime()")
    # check if the difference is smaller than 1 msec    
    assert now - dt1.ctime() <= 0.001
    
    print(" - testing pyuaf.util.DateTime().setCtime()")
    dt = DateTime()
    dt.setCtime(now) 
    assert now - dt.ctime() <= 0.001
    
    print(" - testing pyuaf.util.DateTime().toTime_t()")
    assert long(now) == dt1.toTime_t()
    
    print(" - testing pyuaf.util.DateTime().msec()")
    assert (now % 1) * 1000 - dt1.msec() <= 1
    
    print(" - testing pyuaf.util.DateTime().daysTo()")
    assert dt1.daysTo(dt3) == 3
    
    print(" - testing pyuaf.util.DateTime().secsTo()")
    assert dt1.secsTo(dt2) == 3
    
    print(" - testing pyuaf.util.DateTime().msecsTo()")
    assert dt1.msecsTo(dt2) == 3000
    
    print(" - testing pyuaf.util.DateTime().addSecs()")
    dt = DateTime(dt1)
    dt.addSecs(3)
    assert dt == dt2
    
    print(" - testing pyuaf.util.DateTime().addMilliSecs()")
    dt = DateTime(dt1)
    dt.addMilliSecs(3000)
    assert dt == dt2
    
    print(" - testing pyuaf.util.DateTime().__eq__()")
    assert dt1 == dt1_
    assert not (dt1 == dt2)
    
    print(" - testing pyuaf.util.DateTime().__ne__()")
    assert dt1 != dt2
    assert not (dt1 != dt1_)
    
    print(" - testing pyuaf.util.DateTime().__lt__()")
    assert dt1 < dt2
    
    print(" - testing pyuaf.util.DateTime().__gt__()")
    assert dt3 > dt2
 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:
Beispiel #9
0
 def test_util_DateTime_addMilliSecs(self):
     dt = DateTime(self.dt1)
     dt.addMilliSecs(3000)
     self.assertEqual(dt, self.dt2)
Beispiel #10
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)
Beispiel #11
0
class DateTimeTest(unittest.TestCase):
    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

    def test_util_DateTime_isNull(self):
        self.assertEqual(self.dt0.isNull(), True)
        self.assertEqual(self.dt1.isNull(), False)

    def test_util_DateTime_ctime(self):
        # check if the difference is smaller than 1 msec
        self.assertTrue(self.now - self.dt1.ctime() <= 0.001)

    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)

    def test_util_DateTime_toTime_t(self):
        self.assertEqual(long(self.now), self.dt1.toTime_t())

    def test_util_DateTime_msec(self):
        self.assertLessEqual((self.now % 1) * 1000 - self.dt1.msec(), 1)

    def test_util_DateTime_daysTo(self):
        self.assertEqual(self.dt1.daysTo(self.dt3), 3)

    def test_util_DateTime_secsTo(self):
        self.assertEqual(self.dt1.secsTo(self.dt2), 3)

    def test_util_DateTime_msecsTo(self):
        self.assertEqual(self.dt1.msecsTo(self.dt2), 3000)

    def test_util_DateTime_addSecs(self):
        dt = DateTime(self.dt1)
        dt.addSecs(3)
        self.assertEqual(dt, self.dt2)

    def test_util_DateTime_addMilliSecs(self):
        dt = DateTime(self.dt1)
        dt.addMilliSecs(3000)
        self.assertEqual(dt, self.dt2)

    def test_util_DateTime___eq__(self):
        self.assertTrue(self.dt1 == self.dt1_)
        self.assertFalse(self.dt1 == self.dt2)

    def test_util_DateTime___ne__(self):
        self.assertTrue(self.dt1 != self.dt2)
        self.assertFalse(self.dt1 != self.dt1_)

    def test_util_DateTime___lt__(self):
        self.assertTrue(self.dt1 < self.dt2)

    def test_util_DateTime___gt__(self):
        self.assertTrue(self.dt3 > self.dt2)

    def test_util_DateTimeVector(self):
        testVector(self, pyuaf.util.DateTimeVector, [self.dt0, self.dt1, self.dt2, self.dt3])
# 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("")
Beispiel #13
0
 def test_util_DateTime_addMilliSecs(self):
     dt = DateTime(self.dt1)
     dt.addMilliSecs(3000)
     self.assertEqual(dt, self.dt2)
Beispiel #14
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)
Beispiel #15
0
class DateTimeTest(unittest.TestCase):
    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

    def test_util_DateTime_isNull(self):
        self.assertEqual(self.dt0.isNull(), True)
        self.assertEqual(self.dt1.isNull(), False)

    def test_util_DateTime_ctime(self):
        # check if the difference is smaller than 1 msec
        self.assertTrue(self.now - self.dt1.ctime() <= 0.001)

    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)

    def test_util_DateTime_toTime_t(self):
        self.assertEqual(long(self.now), self.dt1.toTime_t())

    def test_util_DateTime_msec(self):
        self.assertLessEqual((self.now % 1) * 1000 - self.dt1.msec(), 1)

    def test_util_DateTime_daysTo(self):
        self.assertEqual(self.dt1.daysTo(self.dt3), 3)

    def test_util_DateTime_secsTo(self):
        self.assertEqual(self.dt1.secsTo(self.dt2), 3)

    def test_util_DateTime_msecsTo(self):
        self.assertEqual(self.dt1.msecsTo(self.dt2), 3000)

    def test_util_DateTime_addSecs(self):
        dt = DateTime(self.dt1)
        dt.addSecs(3)
        self.assertEqual(dt, self.dt2)

    def test_util_DateTime_addMilliSecs(self):
        dt = DateTime(self.dt1)
        dt.addMilliSecs(3000)
        self.assertEqual(dt, self.dt2)

    def test_util_DateTime___eq__(self):
        self.assertTrue(self.dt1 == self.dt1_)
        self.assertFalse(self.dt1 == self.dt2)

    def test_util_DateTime___ne__(self):
        self.assertTrue(self.dt1 != self.dt2)
        self.assertFalse(self.dt1 != self.dt1_)

    def test_util_DateTime___lt__(self):
        self.assertTrue(self.dt1 < self.dt2)

    def test_util_DateTime___gt__(self):
        self.assertTrue(self.dt3 > self.dt2)

    def test_util_DateTimeVector(self):
        testVector(self, pyuaf.util.DateTimeVector,
                   [self.dt0, self.dt1, self.dt2, self.dt3])