コード例 #1
0
ファイル: tests.py プロジェクト: jadro/python-opcua
    def test_events(self):
        msclt = MySubHandler()
        #cond = msclt.setup()
        sub = self.opc.create_subscription(100, msclt)
        handle = sub.subscribe_events()

        ev = Event(self.srv.iserver.isession)
        msg = b"this is my msg "
        ev.Message.Text = msg
        tid = datetime.now()
        ev.Time = tid
        #ev.source_node = self.opc.get_server_node().nodeid
        #ev.source_name = "our server node"
        ev.Severity = 500
        ev.trigger()

        clthandle, ev = msclt.future.result()
        # with cond:
        #ret = cond.wait(50000)
        # if sys.version_info.major>2: self.assertEqual(ret, True) # we went into timeout waiting for subcsription callback
        # else: pass # python2
        self.assertIsNot(ev, None)  # we did not receive event
        self.assertEqual(ev.Message.Text, msg)
        #self.assertEqual(msclt.ev.Time, tid)
        self.assertEqual(ev.Severity, 500)
        self.assertEqual(ev.SourceNode, self.opc.get_server_node().nodeid)

        # time.sleep(0.1)
        sub.unsubscribe(handle)
        sub.delete()
コード例 #2
0
 def get_event_object(self,
                      etype=ObjectIds.BaseEventType,
                      source=ObjectIds.Server):
     """
     Returns an event object using an event type from address space.
     Use this object to fire events
     """
     return Event(self.iserver.isession, etype, source)
コード例 #3
0
    def test_events(self):
        msclt = MySubHandler()
        #cond = msclt.setup()
        sub = self.opc.create_subscription(100, msclt)
        handle = sub.subscribe_events()

        ev = Event(self.srv.iserver.isession)
        msg = b"this is my msg "
        ev.Message.Text = msg
        tid = datetime.now()
        ev.Time = tid
        #ev.source_node = self.opc.get_server_node().nodeid
        #ev.source_name = "our server node"
        ev.Severity = 500
        ev.trigger()

        clthandle, ev = msclt.future.result()
        # with cond:
        #ret = cond.wait(50000)
        # if sys.version_info.major>2: self.assertEqual(ret, True) # we went into timeout waiting for subcsription callback
        # else: pass # python2
        self.assertIsNot(ev, None)  # we did not receive event
        self.assertEqual(ev.Message.Text, msg)
        #self.assertEqual(msclt.ev.Time, tid)
        self.assertEqual(ev.Severity, 500)
        self.assertEqual(ev.SourceNode, self.opc.get_server_node().nodeid)

        # time.sleep(0.1)
        sub.unsubscribe(handle)
        sub.delete()
コード例 #4
0
ファイル: tests_common.py プロジェクト: cszhaoqm/python-opcua
    def test_events(self):
        msclt = MySubHandler()
        sub = self.opc.create_subscription(100, msclt)
        handle = sub.subscribe_events()

        ev = Event(self.srv.iserver.isession)
        msg = b"this is my msg "
        ev.Message.Text = msg
        tid = datetime.utcnow()
        ev.Time = tid
        ev.Severity = 500
        ev.trigger()

        ev = msclt.future.result()
        self.assertIsNot(ev, None)  # we did not receive event
        self.assertEqual(ev.Message.Text, msg)
        #self.assertEqual(msclt.ev.Time, tid)
        self.assertEqual(ev.Severity, 500)
        self.assertEqual(ev.SourceNode, self.opc.get_server_node().nodeid)

        # time.sleep(0.1)
        sub.unsubscribe(handle)
        sub.delete()
コード例 #5
0
    def test_events(self):
        msclt = MySubHandler()
        sub = self.opc.create_subscription(100, msclt)
        handle = sub.subscribe_events()

        ev = Event(self.srv.iserver.isession)
        msg = b"this is my msg "
        ev.Message.Text = msg
        tid = datetime.now()
        ev.Time = tid
        ev.Severity = 500
        ev.trigger()

        ev = msclt.future.result()
        self.assertIsNot(ev, None)  # we did not receive event
        self.assertEqual(ev.Message.Text, msg)
        #self.assertEqual(msclt.ev.Time, tid)
        self.assertEqual(ev.Severity, 500)
        self.assertEqual(ev.SourceNode, self.opc.get_server_node().nodeid)

        # time.sleep(0.1)
        sub.unsubscribe(handle)
        sub.delete()