tests/win32/test_slave/methods.py
changeset 411 8261c8f1e365
parent 410 092e33606e51
child 412 2b9bc5ee30c0
equal deleted inserted replaced
410:092e33606e51 411:8261c8f1e365
     1 self.logger.write_error("Welcome to the Beremiz Demo\n\n")            
       
     2 self.logger.write("This demo provides a PLC working with the CANopen plugin\n")
       
     3 self.logger.write("""Some external programs are also provided:\n
       
     4 - a CAN TCP server to simulate the CANopen network
       
     5 - a virtual slave node to simulate input block
       
     6 - a virtual slave node to simulate output block
       
     7 """)
       
     8 self.logger.write("\nInfo: For this demo, %s plugin has some special methods to run external programs.\nThese methods are defined in methods.py\n" % (PlugName or "Root"))
       
     9 #open_pdf(os.path.join(os.path.split(__file__)[0], "doc", "manual_beremiz.pdf"), pagenum=21)
       
    10 
       
    11 if wx.Platform == '__WXMSW__':
       
    12     self.listLaunchProg = [
       
    13         {'name' : 'Can Tcp Server',
       
    14          'command' : 'can_tcp_win32_server.exe',
       
    15          'keyword' : 'Accepts',
       
    16          'pid' : None,
       
    17          'no_gui' : True}
       
    18     ]
       
    19 
       
    20 def my_methods(self): 
       
    21     def _Run():
       
    22         # External programs list 
       
    23         # Launch them and get their pid
       
    24         for prog in self.listLaunchProg:
       
    25             self.logger.write("Starting %s\n" % prog['name'])
       
    26             prog['pid'] = ProcessLogger(self.logger, prog['command'], no_gui=prog['no_gui'])
       
    27             prog['pid'].spin(
       
    28             		 timeout=200,
       
    29                      keyword = prog['keyword'],
       
    30                      kill_it = False)
       
    31         
       
    32         PluginsRoot._Run(self)
       
    33 
       
    34     def _Debug():
       
    35         # External programs list 
       
    36         # Launch them and get their pid
       
    37         for prog in self.listLaunchProg:
       
    38             self.logger.write("Starting %s\n" % prog['name'])
       
    39             prog['pid'] = ProcessLogger(self.logger, prog['command'], no_gui=prog['no_gui'])
       
    40             prog['pid'].spin(
       
    41                      timeout=200,
       
    42                      keyword = prog['keyword'],
       
    43                      kill_it = False)
       
    44         
       
    45         PluginsRoot._Debug(self)
       
    46         
       
    47     def _Stop():
       
    48         PluginsRoot._Stop(self)
       
    49         for prog in self.listLaunchProg:
       
    50             self.logger.write("Stopping %s\n" % prog['name'])
       
    51             prog['pid'].kill()
       
    52     
       
    53     return _Run, _Stop, _Debug
       
    54    
       
    55 self._Run, self._Stop, self._Debug = my_methods(self)