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 SmartComponent project. An active station for this example.
The steps that will be performed in this topic are:
Define the properties and signals in the SmartComponent's XML file.
Add the properties and signal's descriptions in the resource file.
Define the properties and signals in the SmartComponent's XML file.
The topic considers that a SmartComponent project created from Visual Studio exists. Refer to topic Creating a SmartComponent on how to run it.
Note
The code in this topic can be tested using the default RobotStudio Smart Component template.
Solution
Open
SmartComponent1.xml
file. Add the following code in Library XML which defines the signals to be used. Set the CanBeSimulated property to true.<lc:Library fileName="SimulationExample.rslib"> <SmartComponent icon="SimulationExample.png" codeBehind="SimulationExample.SimulationExample" canBeSimulated="true"> <Signals> <IOSignal name="SimulationStarted" autoReset="true" signalType="DigitalOutput"/> <IOSignal name="SimulationStopped" autoReset="true" signalType="DigitalOutput"/> </Signals> </SmartComponent> </lc:Library>
Open
SmartComponent1Resource.xml
file. Add the following code in Library Resource XML which describes the signals.<SmartComponent name="SimulationExample" 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 "CodeBehind.cs" file and add the following code as events.When Simulation Starts, "SimulationStarted" signal is Pulsed and when Simulation Stops, "SimulationStopped" signal is pulsed. Following are the steps to be followed to achieve the above mentioned task:
Get the signal "SimulationStarted" and pulse the signal on SimulationStart.
component.IOSignals["SimulationStarted"].Pulse();
Get the signal "SimulationStopped" and pulse the signal on SimulationStop.
component.IOSignals["SimulationStopped"].Pulse();
Example
public override void OnSimulationStart(SmartComponent component)
{
component.IOSignals["SimulationStarted"].Pulse();
}
public override void OnSimulationStop(SmartComponent component)
{
component.IOSignals["SimulationStopped"].Pulse();
}
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.Robotics.RobotStudio.Stations