tests/win32/test_slave/methods.py
author greg
Mon, 27 Oct 2008 09:35:23 +0100
changeset 266 530118da6c15
permissions -rwxr-xr-x
update test_master and test_slave examples for win32
266
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     1
self.logger.write_error("Welcome to the Beremiz Demo\n\n")            
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     2
self.logger.write("This demo provides a PLC working with the CANopen plugin\n")
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     3
self.logger.write("""Some external programs are also provided:\n
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     4
- a CAN TCP server to simulate the CANopen network
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     5
- a virtual slave node to simulate input block
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     6
- a virtual slave node to simulate output block
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     7
""")
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     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"))
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
     9
#open_pdf(os.path.join(os.path.split(__file__)[0], "doc", "manual_beremiz.pdf"), pagenum=21)
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    10
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    11
if wx.Platform == '__WXMSW__':
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    12
    self.listLaunchProg = [
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    13
        {'name' : 'Can Tcp Server',
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    14
         'command' : 'can_tcp_win32_server.exe',
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    15
         'keyword' : 'Accepts',
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    16
         'pid' : None,
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    17
         'no_gui' : True}
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    18
    ]
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    19
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    20
def my_methods(self): 
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    21
    def _Run():
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    22
        # External programs list 
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    23
        # Launch them and get their pid
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    24
        for prog in self.listLaunchProg:
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    25
            self.logger.write("Starting %s\n" % prog['name'])
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    26
            prog['pid'] = ProcessLogger(self.logger, prog['command'], no_gui=prog['no_gui'])
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    27
            prog['pid'].spin(
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    28
            		 timeout=200,
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    29
                     keyword = prog['keyword'],
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    30
                     kill_it = False)
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    31
        
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    32
        PluginsRoot._Run(self)
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    33
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    34
    def _Debug():
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    35
        # External programs list 
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    36
        # Launch them and get their pid
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    37
        for prog in self.listLaunchProg:
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    38
            self.logger.write("Starting %s\n" % prog['name'])
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    39
            prog['pid'] = ProcessLogger(self.logger, prog['command'], no_gui=prog['no_gui'])
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    40
            prog['pid'].spin(
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    41
                     timeout=200,
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    42
                     keyword = prog['keyword'],
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    43
                     kill_it = False)
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    44
        
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    45
        PluginsRoot._Debug(self)
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    46
        
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    47
    def _Stop():
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    48
        PluginsRoot._Stop(self)
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    49
        for prog in self.listLaunchProg:
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    50
            self.logger.write("Stopping %s\n" % prog['name'])
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    51
            prog['pid'].kill()
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    52
    
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    53
    return _Run, _Stop, _Debug
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    54
   
530118da6c15 update test_master and test_slave examples for win32
greg
parents:
diff changeset
    55
self._Run, self._Stop, self._Debug = my_methods(self)