Pulse a Signal when a Simulation starts
This example provides information on how to pulse a signal during Simulation Start and Simulation Stop. The example provides snippets of XML and
C# that could be used within the Smart
The steps that will be performed in this topic are:
Add the signals to the SmartComponent's XML file.
Add the signal's descriptions to the XML resource file.
Modify the code in the CodeBehind.cs file.
The topic considers that a SmartComponent project created from Visual Studio exists.
Refer to topic Creating a Smart
Note
The code in this topic can be tested using the default RobotStudio Smart Component template.
Solution
Open the
SmartComponent1.xml
file. Set the CanBe property to true.Simulated <SmartComponent name="SmartComponent1" icon="SmartComponent1.png" codeBehind="SmartComponent1.CodeBehind,SmartComponent1.dll" canBeSimulated="true">
Add the following signals in the Library XML.
<Signals> <IOSignal name="SimulationStarted" autoReset="true" signalType="DigitalOutput"/> <IOSignal name="SimulationStopped" autoReset="true" signalType="DigitalOutput"/> </Signals>
Open
SmartComponent1.en.xml
file. Provide descriptions for the component and the signals.<SmartComponent name="SmartComponent1" description="Pulses signals when the simulation starts and stops"> <IOSignal name="SimulationStarted" description="Pulsed when the simulation starts"/> <IOSignal name="SimulationStopped" description="Pulsed when the simulation stops"/> </SmartComponent>
Open the CodeBehind.cs file and add the two overriding methods OnSimulationStart and OnSimulationStop. When Simulation Starts, SimulationStarted signal is Pulsed and when Simulation Stops, SimulationStopped signal is pulsed. Here are the steps to be followed to achieve the above mentioned task:
Get the signal SimulationStarted and pulse the signal on when simulation starts.
public override void OnSimulationStart(SmartComponent component) { component.IOSignals["SimulationStarted"].Pulse(); base.OnSimulationStart(component); }
Get the signal SimulationStopped and pulse the signal when simulation stops.
public override void OnSimulationStop(SmartComponent component) { component.IOSignals["SimulationStopped"].Pulse(); base.OnSimulationStop(component); }
Compiling the Code
Note
In order for the Library Compiler to find the code behind assembly asset it needs to be located in the same directory as the Library XML file. The template project contains the following Post-Build Event, that copies the assembly to the right place.
copy /y "$(TargetPath)" "$(ProjectDir)"
The LibraryCompiler.exe
is executed as a Post-Build Event, which means it is executed after the C# project has been built, and the code behind asset has been created.
"%ProgramFiles(X86)%\ABB\RobotStudio {version}\bin\LibraryCompiler.exe" "$(ProjectDir)\SmartComponent1.xml" "$(ProjectDir)\"
Required Namespaces
ABB.