DifferentCodeSimAndDownload

From Flowcode Help
Revision as of 08:38, 2 July 2019 by DavidA (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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.


Sim1.jpg


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.


Sim2.jpg


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.


Sim3.jpg


this refers to a property in "this project" or "this component" if the project is being exported as a 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.

Sim4.jpg


As the decision is referring to a property the generated C code is fixed and so the decision code gets optimised out when downloading to a microcontroller.


Example File

Here is a Flowcode example file showing the completed functionality.

FC6 Icon.png Sim Demo