Methods have program code that only runs when you call the method. It is like a function in PROCESS-PASCAL, that can have parameters and a result.
Program code in a method has direct access to parameters, local variables, component variables, and constants. However, methods differ from functions, as you can call them via P-NET.
You can mark a method as internal (I), external (E) or both (I+E).
You can call external methods from other components in the same device or via P-NET. External methods can’t call methods in other components.
You can’t call internal methods from other components, but they can call methods in other components.
A method can call itself asynchronously (async).
The system only allows async calls, if the method you call has no parameters or result.
The system will interrupt the execution of an internal method in a component if an external method is called in the same component. Internal methods such as timers do not interrupt the execution of an already running internal method.
TIP: When you work with data that external methods can change, we suggest that you create a local variable as a copy of the data. You can then use this local variable in your method. Note that “set” on a register is an external method call.
We have made diagrams that show the communication between methods:
|Each method category can call a method of its own category in the same component both direct and async.||The different ways that each method category can call each other inside the same component.||Each method category can call itself async inside a component.||Only an internal method can call methods in another component through external connections.|
I=Internal, E=External, I+E=Both, C=component, M=method, and A=Asynch call.
A mutex makes sure that calls within a component to the same method are handled in sequence. Further, there is an external mutex that handles external calls to a method. There is no mutex for both internal and external calls, so be very aware when you use IE methods as conflicts in execution may arise.