Difference between revisions of "DifferentCodeSimAndDownload"
Line 1: | Line 1: | ||
+ | <sidebar>Sidebar: Flowcode Help Overview:Simulation</sidebar> | ||
==Introduction== | ==Introduction== | ||
Revision as of 10:26, 1 August 2018
<sidebar>Sidebar: Flowcode Help Overview:Simulation</sidebar>
Contents
Introduction
In some cases it is necessary to use different code for simulation and for download.
Simulation icons automatically get ignored for compilation but often to drive the simulation macros you need additional code such as calculations and variables.
It can therefore be useful to separate out the simulation side code so that it does not consume resources for the embedded target.
Setup
Creating Sim Property
On the properties window, ensure that Panel is selected on the drop down list at the top of the window.
Click the drop down next to properties and select Add new.
Change cosmetic name to Sim, Property type to True or False, Property Variable to Sim.
Click OK and ensure the property value is set to No.
I also went back into the property edit dialogue after setting the value and unticked Writable to stop the user from manually changing the value but this isn't required. Simply double click the property to open the edit dialogue again.
Creating Event Macros
On the project explorer window click on the Events tab.
Scroll down to the Simulation -> Start.
Double click the Start item, double click <Add New> and click OK twice.
Repeat for the Simulation -> Stop item.
This should create you two new macros named EV_Start and Ev_Stop which are automatically called by Flowcode whenever the simulation starts and stops.
On the project explorer window click on the Macros tab.
Double Click the Ev_Start macro to open the macro Flowchart.
In the Ev_Start macro Flowchart add a simulation macro icon.
In the icon properties choose the Functions tab and then choose Component -> Property -> SetValue.
Use the parameters this, "Sim", True.
Do the same in the Ev_Stop macro, this time with the parameters this, "Sim", False.
this refers to a property in "this project" or "this component".
"Sim" is the name of the property in quotes to avoid referring to the property value.
The last parameter sets the state of the property.
Decisions
You can now add the Sim decisions anywhere in your program where Sim and download need to do different things.
Example File
Here is a Flowcode example file showing the completed functionality.