Customization > SySim- SysML model execution > Working with a SySim model execution > Concepts and Reference > ASAL structured action language (SySim)
  
ASAL structured action language (SySim)
ASAL is a PTC UML Action Language that is suitable for specifying executable algorithms in a target language independent way. ASAL is similar to the Basic language.
In SysML models that use State Diagrams, the Event Action Blocks on those State Diagrams must use ASAL in order for SySim to interact with them.
If you create State Diagrams to model the behavior of any SySim Control Blocks, you must also use ASAL in the Event Action Blocks on those State Diagrams.
SySim Control Block owned Operations can use ASAL or Visual Basic in their Body property. If you want to use ASAL in the Body property of an Operation, apply the «ACSImplementation» stereotype to the Operation and set the tagged value of the Implementation Language tag definition to ASAL. The «ACSImplementation» stereotype is part of the ACS Profile.
When ASAL code is generated to your Visual Studio project, ASAL code that is interpreted appears as commented out code. For example:
This topic provides information about the basic ASAL statements and an example program using ASAL.
Reading the value of a port
There are two ways of reading the value of a port:
Using the name of the port on its own.
The syntax is as follows:
<port>
Using the GetLatchedValue function.
The syntax is as follows:
<port>.GetLatchedValue()
Where:
<port>- specifies the port whose value is being read. Use a model object reference in your code (drag the port item to the code in Modeler).
When only the port name is used, the ASAL translator generates the appropriate extra code to the target language.
Examples:
A := MyPort.GetLatchedValue();A := MyPort;
Setting the value of a port
There are two ways of setting the value of a port:
Using the name of the port on its own.
The syntax is as follows:
<port> := <value>;
Using the SetValue function.
The syntax is as follows:
<port>.SetValue(<value>);
Where:
<port>- specifies the port whose value is being set. Use a model object reference in your code (drag the port item to the code in Modeler).
<value>- specifies the value that is being set for the port.
When only the port name is used, the ASAL translator generates the appropriate extra code to the target language.
Examples:
MyPort:= bOnMyPort.SetValue(bOn);
Sending an event through a port
There are two ways of sending an Event though a port:
Using ASAL send…to construct.
The syntax is as follows:
send <event>[(<event parameters>)] to <port>;
Using the SendEvent function.
The syntax is as follows:
<port>.SendEvent(New <event[(<event parameters>)]) ;
Where:
<port> - specifies the port through which the Event is sent. Use a model object reference in your code (drag the port item to the code in Modeler).
event- specifies the Event that is being sent through the port. Use a model object reference in your code (drag the Event item to the code in Modeler).
If the Event is not visible to the port in the model, prefix the name of the Event with its Package hierarchy using periods as delimiters.
<event parameters>- optionally specifies parameters for sending the Event. Use model object references in your code (drag each Parameter item to the code in Modeler).
The ASAL translator generates the send…to construct with the appropriate target language instructions.
Examples:
Send MyEvent to MyPort;MyPort.SendEvent(New MyEvent);Send MyEventWithParams(1, "text") to MyPort;MyPort.SendEvent(New MyEventWithParams(1, "text"));Send MyOtherPackage.MyOtherEvent(1) to MyPort;MyPort.SendEvent(MyOtherPackage.MyOtherEvent(1))
Calling an operation
To call an Operation item in ASAL, reference the Operation with an optional prefix that qualifies the object that the Operation is called against (the default is 'This'). You must use parentheses for the operation, even if there are no parameters to pass.
The syntax is as follows:
<operation ([<parameters>])
Where:
<operation>- specifies the operation that is being called. Use a model object reference in your code (drag the Operation item to the code in Modeler).
By default, the Operation is called against 'This'. You can prefix the Operation with the object that the Operation is called against.
<parameters>- specifies any parameter values that are passed to the operation that is being called. Use a model object reference in your code (drag the Parameter item to the code in Modeler)
Examples:
MyOperation(True);This.MyOperation(True);ReferenceObject.ItsOperation(False); OperationWithNoParameters();
Declaring variables
The Declare statement declares local variables.
The syntax is as follows:
declare <variable list> : <type> ;
Where:
<variable list>- specifies a list of variables that are being declared. For each variable an optional initial value can be set through the ':-' assignment operator.
<type> - specifies the type of the variables that are being declared.
Example:
declare A : Boolean;declare B := False : Boolean;declare C, D := 0 : Integer;
Assigning values to variables
Values can be assigned to variables.
The syntax is as follows:
<variable:= <expression> ;
Where:
<variable>- specifies the variable that is being assigned.
<expression>- specifies the value that is being assigned, which can be defined through an expression.
Example:
ped_wait := False;
Conditional execution of code
The if, then, else statements provide a mechanism for conditional execution of code.
The syntax is as follows:
if <condition> then... //code to executeelseif <condition> then... //code to executeelse... //code to executeend if
Where:
<condition>- specifies the condition that is being tested.
Example:if A < 100 thenA := A + 1;elseif B < 100 thenB := B + 1;ElseNowStop := True;end if
While loops
The while loop provides a mechanism for executing code while a condition is true.
The syntax is as follows:
while <condition>... //code to executeend while
Where:
<condition>- specifies the condition that is being tested.
Example:
while A < 100A := A + 1;end while
Case selection
The case selection provides a mechanism for executing code when a case is true.
The syntax is as follows (note that there can be many cases):
select case <condition>case <condition>:... //code to executecase else:... //code to executeend select
Where:
<condition>- specifies the condition that is being tested.
Example:select case A + Bcase 200:ResultIs200 := True;case else:ResultIs200 := False;end select
Return statement
The Return statement can return the result of an expression.
The syntax is as follows:
return <expression> ;
Where:
<expression>- specifies the expression that returns the result.
Example:
return A + B;
Comments
The Comment statement specifies text that is ignored by the target language.
The syntax is as follows for single line comments:
// <text>
The syntax is as follows for multiline comments:
/* <text> */
Where:
<text>- specifies the text that is generated as a comment.
Example:
// return the sum of A + B/* This text is translated into a target language comment */
Example program written in ASAL
declare A := 0, B: Integer; /* Former declared variable initialized, latter is not. Both share the same type */declare GoOn := True : Boolean;declare NowStop := False : Boolean;B := 0; /* Assignment */NowStop := not B = 0 and (GoOn or NowStop); /* Assignment (it's False) using a logical expression */while GoOn and not NowStop do /* While loop */ if A < 100 then /* Condition … if */ A := A + 1;elseif B < 100 then /* Condition, elseif ("elsif" will also work) */ B := B + 1; else /* Condition, else */NowStop := True;end if /* end of condition. "endif" will also work */ end while /* “endwhile” will also work */ declare TestOk : Boolean;select case A + B /* Selection statement. It's similar to C/C++ switch (but no “break”, only one case is executed at most) */ case 199 + (A + B) / (A + B): /* Case expression, equates to 200 */TestOk := True;case else: /* Default case */TestOk := False;end selectreturn A + B; /* Return statement */
Concepts and Reference