Description
In this example, there are three modules: 1, 2 and 3. Module 1 is always active, but modules 2 and 3 are not. Module 1 triggers one scan of modules 2 and 3 when required.
This is set up in the matplc.conf file and in the code of module 1. Modules 2 and 3 are written as normal - MatPLC will suspend them at the beginning of the scan until module 1 triggers them.
In the matplc.conf file:
[PLC] # We need two places... # (places hold tokens) place P_module2 place P_module3 # ... and three transitions. # (when fired, transitions remove and insert tokens from/into places) transition T_module2_beg transition T_module3_beg transition T_launch_modules # Remove a token from P_module2 when firing the T_module2_beg transition... arc P_module2 -> T_module2_beg # Remove a token from P_module3 when firing the T_module3_beg transition... arc P_module3 -> T_module3_beg # Insert a token into P_module2, # and another into P_module3 # when firing the T_launch_modules transition... arc T_launch_modules -> P_module2 arc T_launch_modules -> P_module3 # The only thing left is to tell each module what transitions to use for # the beginning and of the scan. module2: scan_beg = T_module2_beg module3: scan_beg = T_module3_beg
In the C source code of module1:
In the initialisation:
/* initialise handle to the synchronisation point... */ /* Don't forget to add code to check for errors when calling the * following functions: * - If the transition doesn't exist, INVALID_TRANSITION will be returned. * - In case of errors when creating the synchpt, an * INVALID_SYNCHPT will be returned. */ plc_transition_t transition = plc_transition_by_name("T_launch_modules"); plc_synchpt_t synchpt = plc_synchpt_new(transition, 0, plc_synchpt_blocking);
In the body of the scan (or as appropriate):
/* If condition occurs, fire the T_launch_modules transition */ if (???????) plc_synch(synchpt);
$Date: 2005/12/08 09:13:44 $