I am trying to write a DDE server in python which needs to send a continuously changing string to a program which is connected as a DDE client.
The program which connects to a DDE server uses the following DDE settings to connect [Service: Orbitron, Topic: Tracking, Item: Tracking]. The program has to receive information that is sent by the DDE server in the following string format: "UP0 DN145000001 UMusb DMfm AZ040 EL005 SNNO SATELLITE".
The content of this string changes approximately every second and I want the DDE server to send the new string to the connected DDE client, for example every second.
I am currently using the code below, which is a slightly modified version of the original ddeserver.py file, see here.
import win32ui
from pywin.mfc import object
import dde
class MySystemTopic(object.Object):
def __init__(self):
object.Object.__init__(self, dde.CreateServerSystemTopic())
def Exec(self, cmd):
print "System Topic asked to exec", cmd
class MyOtherTopic(object.Object):
def __init__(self, topicName):
object.Object.__init__(self, dde.CreateTopic(topicName))
def Exec(self, cmd):
print "Other Topic asked to exec", cmd
class MyRequestTopic(object.Object):
def __init__(self, topicName):
topic = dde.CreateTopic(topicName)
topic.AddItem(dde.CreateStringItem(""))
object.Object.__init__(self, topic)
def Request(self, aString):
print "Request Topic sent: ", aString
a="UP0 DN145800001 UMusb DMfm AZ040 EL005 SNNO SATELLITE"
print a
return(a)
server = dde.CreateServer()
server.AddTopic(MyRequestTopic("Tracking"))
server.Create('Orbitron')
while 1:
win32ui.PumpWaitingMessages(0, -1)
When I run the code I can successfully connect with the program and the string (as provided in the code) is received one time. I tried a few different things but I can not think of a way yet how to change to python code in order to have the DDE server continuously resend the string in a loop or similar.
Any suggestions would be very welcome.
P.S. I am relatively new to python, DDE and this forum, my apologies if something is unclear. Just let me know.