예제 #1
0
from PyDragonfly import copy_from_msg, copy_to_msg, MT_EXIT, MT_KILL
import message_defs as mdefs
import sys

MID_REQUEST = 11

# Note: Request must be started second

if __name__ == "__main__":
    mod = PyDragonfly.Dragonfly_Module(MID_REQUEST, 0)
    mod.ConnectToMMM()
    mod.Subscribe(mdefs.MT_TEST_DATA)
    mod.Subscribe(MT_EXIT)

    print "Request running...\n"

    while (1):
        mod.SendSignal(mdefs.MT_REQUEST_TEST_DATA)
        print("Sent request for data")
        msg = PyDragonfly.CMessage()
        mod.ReadMessage(msg)
        print "Received message", msg.GetHeader().msg_type
        if msg.GetHeader().msg_type == mdefs.MT_TEST_DATA:
            msg_data = mdefs.MDF_TEST_DATA()
            copy_from_msg(msg_data, msg)
            print "Data = [a: %d, b: %d, x: %f]" % (msg_data.a, msg_data.b,
                                                    msg_data.x)
        time.sleep(1)

    mod.DisconnectFromMMM()
예제 #2
0
import PyDragonfly
from PyDragonfly import copy_to_msg
import message_defs as md
import sys

MID_PRODUCER = 10

if __name__ == "__main__":
    mod = PyDragonfly.Dragonfly_Module(MID_PRODUCER, 0)
    mod.ConnectToMMM("localhost:7111")

    print("Producer running...\n")

    a = 0
    run = True
    while run:
        out_msg = PyDragonfly.CMessage(md.MT_TEST_DATA)

        data = md.MDF_TEST_DATA()
        data.a = a
        data.b = -3
        data.x = 1.234
        copy_to_msg(data, out_msg)
        mod.SendMessage(out_msg)

        print("Sent message ", out_msg.GetHeader().msg_type)

        a += 1

        time.sleep(1)