[Twisted-Python] UDP some Q's
Background; working on a two node simulation system using X3D (www.h3d.org ) and simulink (www.mathworks.org) also CarSim (www.carsim.com) using simulink in the future. Made a first code suggestion on transmit / recive UDP. Se attached file trancive_UDP.py Used time. to restrict the transmit rate. Doesn't matter if I lose some state update, 50 updates / second are enough for perception of a smooth motion. Have to work on events from mouse click to togle them on for 0.2 second. Don't know how to access objects from the main module in the classes in the lib module. The tricky part as I see it are ( part of from transive_UDP.py ): # ------------------------------------------------------------------ def datagramRecived(self, data): count = 0 data_str = string.split(data) for recive_items in data_str: __main__.recived_data[ count ] = float( recive_items ) count = count +1 __main__.update_on_recive() #----------------------------------------------------------------- The problems are that I need to update __main__.recive.dada before calling __main__.updat_on_recive(). Second how to access the .send_UDP from the __main__ module. /Sven-Erik Tiberg
On 08:42 am, sven-erik.tiberg@ltu.se wrote:
Don't know how to access objects from the main module in the classes in the lib module. The tricky part as I see it are ( part of from transive_UDP.py ): # ------------------------------------------------------------------ def datagramRecived(self, data): count = 0 data_str = string.split(data) for recive_items in data_str: __main__.recived_data[ count ] = float( recive_items ) count = count +1 __main__.update_on_recive()
#----------------------------------------------------------------- The problems are that I need to update __main__.recive.dada before calling __main__.updat_on_recive().
There is no Twisted API or special technique that you need to use. Just create your objects with references to all the objects they need to manipulate. For example, in main.py, instead of: reactor.listenUDP(self.port, transive_udp('...',2345, 0.05 )) just do: reactor.listenUDP(self.port, transive_udp('...', 2345, 0.05, recive_data)) and then add an argument to transive_udp's constructor to refer to the data.
Second how to access the .send_UDP from the __main__ module.
Similarly, you can keep a reference to transive_udp object in the main module. I might be able to comment more except the attached example is full of errors and will not even import.
Thanks working on it. found some fault and learned a lot. /BG Sven-Erik ________________________________ From: twisted-python-bounces@twistedmatrix.com on behalf of glyph@divmod.com Sent: Thu 5/3/2007 11:16 AM To: Twisted general discussion Subject: Re: [Twisted-Python] UDP some Q's On 08:42 am, sven-erik.tiberg@ltu.se wrote:
Don't know how to access objects from the main module in the classes in the lib module. The tricky part as I see it are ( part of from transive_UDP.py ): # ------------------------------------------------------------------ def datagramRecived(self, data): count = 0 data_str = string.split(data) for recive_items in data_str: __main__.recived_data[ count ] = float( recive_items ) count = count +1 __main__.update_on_recive()
#----------------------------------------------------------------- The problems are that I need to update __main__.recive.dada before calling __main__.updat_on_recive().
There is no Twisted API or special technique that you need to use. Just create your objects with references to all the objects they need to manipulate. For example, in main.py, instead of: reactor.listenUDP(self.port, transive_udp('...',2345, 0.05 )) just do: reactor.listenUDP(self.port, transive_udp('...', 2345, 0.05, recive_data)) and then add an argument to transive_udp's constructor to refer to the data.
Second how to access the .send_UDP from the __main__ module.
Similarly, you can keep a reference to transive_udp object in the main module. I might be able to comment more except the attached example is full of errors and will not even import.
participants (2)
-
glyph@divmod.com -
Sven-Erik Tiberg