Model review and simulation > SySim- SysML model execution > Concepts and Reference > Defining behavior through Visual Basic code (SySim)
Defining behavior through Visual Basic code (SySim)
When defining behavior of a SySim Control Block, you can use event handling Operations.
To create an event handling Operation from a SySim Control Block: right-click the SySim Control Block, point to New, point to SySim Handle Event, and then click the command for the appropriate event. Typically, you will want to define behavior for the Time Advance event of the model execution loop.
In addition to event handling Operations, you can define your own Operations on the SySim Control Blocks: right-click the SySim Control Block, point to New, point to SysML, and then click Operation. These Operations can be called from the body code of other Operations and from the Action field of Event Action Blocks on State Machines.
In the Body property of the Operation, you can use Visual Basic to define that behavior. This is the only place that Visual Basic can be used to define behavior for a SySim model execution.
Note that you can also use ASAL (a PTC structured action language) to define behavior in the Body property of an Operation by applying the «ACSImplementation» stereotype to the Operation and setting the tagged value of the Implementation Language tag definition to ASAL.
When SySim generates Visual Basic code from the Body property of an event handling Operation, SySim generates the code as is between two markers in the code file. For example:
//## Operation [babfba4b-6c05-466b-be77-034d99bbd453]
//## Operation End

If in a code file you change the text between these code markers, SySim will reverse engineer those changes to the model.
When using Visual Basic, you use the GetLatchedValue and SetValue functions of the SySim .NET Framework library to get and set the value of a port:
The GetLatchedValue function reads the value of a port. In this example, the InValue variable is set to the value of the InputPort port:
Dim InValue As Single = InputPort.GetLatchedValue()
In this example, the code is for an event handling Operation on a SySim Control Block whose base type is TextBox. The code makes the text box display the text that appears on its Inp port.
Me.Text = Inp.GetLatchedValue()
The SetValue function sets the value of a port. In this example, the value of the OutSpeed port is set to the value of the CurrSpeed variable:
OutSpeed.SetValue(CurrSpeed)
The SendEvent function sends an event through a port. In this example, the EvOne event is sent through the OutSpeed port:
OutSpeed.SendEvent(New EvOne(MyParamOne, MyParamTwo))
Was this helpful?