Customization > SySim- SysML model execution > Modeling a SySim model execution > Creating your own SySim control blocks to model controls and behavior (SySim)
  
Creating your own SySim control blocks to model controls and behavior (SySim)
Preparing a SysML model for SySim
Modeling a SySim model execution:
Creating a SySim simulation scenario
Including SysML model blocks in a SySim simulation scenario
Including PTC provided SySim control blocks in a SySim simulation scenario
Creating your own SySim control blocks to model controls and behavior
Including your own SySim control blocks in a SySim simulation scenario
Defining SySim control block and SysML model block interaction
Setting up a model to work with PTC ThingWorx
Generating and building a SySim model execution
Working with a SySim model execution
You can create your own SySim Control Blocks that can be used to generate input or output controls on the generated Visual Basic form. Alternatively, a SySim Control Block can just model behavior.
To create a SySim control block:
1. Right-click the Package that contains the SySim items and diagrams, point to New, point to SysML, point to Structure, and then click Block.
2. Type the name of the SySim Control Block, and then press the Enter key.
3. Right-click the SysML Block, point to Links > Stereotypes, and then click SySim ControlBlock.
4. If you want your SySim Control Block to be based on a PTC provided SySim Control Block:
a. Create a SysML Block Definition Diagram: right-click the Package to own the diagram, point to New, point to Diagram, point to SySim, and then click Block Definition Diagram.
b. Drag the SySim Control Block you created to the Block Definition Diagram.
c. Drag the PTC provided SySim Control Block from which you want to inherit to the Block Definition Diagram.
d. On the Class Diagram toolbar, click the Generalization button, click your SySim Control Block, and then click the PTC provided SySim Control Block.
Note that in the Packages pane, the inherited Full Ports, Proxy Ports and Flow Ports will appear on the SySim Control Block after the SySim Control Block is dragged to a SySim Simulator's Internal Block Diagram.
5. If your SySim Control Block is not based on a PTC provided SySim Control Block and you want the SySim Control Block represented in the SySim model execution through a Visual Basic standard control, such as a text box, follow the appropriate steps that follow.
Note that if your SySim Control Block is not based on a PTC provided SySim Control Block and you do not want the SySim Control Block represented in the SySim model execution, ignore this step and continue to Step 6..
To model a Visual Basic standard control through a SySim VB Base Control that is a stereotyped Block, as are the provided SySim VB Base Control items in the SySim Profile::SySim BaseControls package:
a. Create a SysML Block Definition Diagram: right-click the Package to own the diagram, point to New, point to Diagram, point to SySim, and then click Block Definition Diagram.
b. Drag the SySim Control Block you created to the Block Definition Diagram.
c. Drag the SySim VB Base Control Block whose name matches the Visual Basic standard control you want to use to the Block Definition Diagram.
The PTC provided SySim VB Base Control Blocks reside in the following Package: 'Profiles::SySim Profile::SySim BaseControls'.
If the Visual Basic base class you require is not represented in the model, create a new SySim VB Base Control: Create a Package outside of the SySim Profile package and apply the «SySim Predefined» stereotype to that Package so that SySim does not generate its content. In the Package you created, create a SysML Block and set its name to that of the Visual Basic base class you want to use. Apply the «SySim VBBaseControl» stereotype to that SysML Block.
d. On the Class Diagram toolbar, click the Generalization button, click your SySim Control Block, and then click the SySim VB Base Control Block.
To model a Visual Basic standard control without creating a SySim VB Base Control for the Visual Basic standard control:
a. Open the SySim Control Block's Property Pages, and then click the SySim ControlBlock tab.
b. Set the tagged value of the VBBaseClass tag definition to the name of the Visual Basic base class you want to use.
6. Create the required Full Ports, Proxy Ports and Flow Ports for the SySim Control Block. For each port you want to create:
a. Right-click the SySim Control Block, point to New, point to SysML, and then click Full Port, Proxy Port or Flow Port as required.
b. From the Type Selector dialog, create or select the type that is appropriate for the data that flows through the port, and then click OK.
If the type of the port is a Visual Basic primitive type, select the appropriate Value Type item from the SySim Profile::SySim DataTypes package.
If the type of the port is not a Visual Basic primitive type, create or select the appropriate item. You must apply the «SySim DataType» stereotype to the item you use as a type.
If there is no item in the model for the type you want to use, select No Type. You specify the type to use in step f.
c. From the Value Selector dialog, select the direction of the port, and then click OK.
d. Type the name of the port, and then press the Enter key.
e. Right-click the port, point to Links > Stereotypes, and then click SySim InputPort, SySim OutputPort or SySim InputOutputPort as is appropriate for the direction of the port.
Note that for a Flow Port, the «SySim InputOutputPort» stereotype can be used only when the Flow Port's type is a Flow Specification.
f. If you did not select a type to use in step b: Open the port's Property Pages, click the tab for the Stereotype you applied in the previous step, and then set the tagged value of the SySim PortDataType tag definition to the name of the port's type.
7. Create the required Standard Ports for the SySim Control Block. For each Standard Port you want to create:
a. Right-click the SySim Control Block, point to New, point to SysML, and then click Port.
b. From the Type Selector dialog, create or select the Class that is appropriate for the data that flows through the Standard Port, and then click OK.
c. For information about using a Standard Port with SySim, click here
For more information refer to SySim flow ports
d. Right-click the Class that you used as a type for the Standard Port, point to Links > Stereotypes, and then click SySimPortClass.
e. Right-click the Standard Port you have created, point to Links > Stereotypes, and then click SySim InputPort or SySim OutputPort as appropriate.
8. Define the behavior of the SySim Control Block through Operations, a child State Diagram or a referenced Simulink model.
To model behavior through event handling Operations:
a. Right-click the SySim Control Block, point to New, point to SySim Handle Event, and then click the command for the event that is going to trigger the Operation: Ready To Start,Simulation Start,Input Latch,Time Advance,Output Publish or Simulation End.
Most behavioral Operations will use the Time Advance event. For more information about the triggers that are handled by the preceding events, refer to SySim model execution event handling
b. Type a name for the Operation, and then press the Enter key.
c. In the Operation's Property Pages, click the Body tab.
d. In the Body property define the behavior of the SySim Control Block for the event handler using ASAL (a PTC structured action language) or Visual Basic.
If you want to use ASAL rather than Visual Basic, you must apply the «ACSImplementation» stereotype to the Operation and set the tagged value of the Implementation Language tag definition to ASAL.
To model behavior through a child State Diagram:
a. Right-click the SySim Control Block, point to New, point to SysML, and then click State Machine.
b. Type a name for the State Machine, and then press the Enter key.
c. Right-click the State Machine, point to New, and then click State Diagram.
d. Define the behavior through the State Diagram items.
In State and Transition Event Action Blocks, use ASAL to describe the behavior of the SySim Control Block.
For more information refer to SySim Atego structured action language
To model behavior through a referenced Simulink model:
a. In Simulink, create the Simulink model to model the behavior of the SySim Control Block.
The Simulink model must have a port for each of the SySim Control Block's SySim ports and the names must match in each case.
b. Right-click the SySim Control Block, point to Links > Stereotypes, and then click SySim SimulinkBlock.
c. Open the SySim Control Block's Property Pages.
d. Click the SySim SimulinkBlock tab.
e. Set the tagged value of the SySim SimulinkModelPathName tag definition to the path and name of the Simulink mdl or slx file you want to reference.
After creating your own SySim Control Blocks, you can include them to a SySim Simulation Scenario. Including your own SySim control blocks in a SySim simulation scenario