Page 1 of 1

Decision component for simulation only

Posted: Wed Feb 13, 2019 4:22 pm
by medelec35
Is it possible to have a dragable decision component that the true branch is accessed during simulation only?
The false branch is for when running of hardware.
I have set up a few flowcharts that work like this but there are a fair few steps involved.
Would be nice to drag a single decision branch instead.

Re: Decision component for simulation only

Posted: Thu Feb 14, 2019 9:57 am
by Steve
Hi Martin,

That's a good idea. I'm sure Ben and Leigh know a few tricks, but in the meantime, here's a possible workaround...

1) Create a variable and set it to zero ("IsSimulating = 0").
2) Use a simulation event (e.g. Time::GetMillisecs) to set it to a value
3) Use an "if (IsSimulating <> 0)" decision to determine if you are simulating or not

I've not tested this, but it should work because step 2 will be ignored in the microcontroller code and so "IsSimulating" will remain zero when running on a device but will be set to a non-zero value when simulating.

Regards,
Steve.

Re: Decision component for simulation only

Posted: Thu Feb 14, 2019 10:31 am
by LeighM
Thanks Steve, and for reminding me to comment
I've done this with a "Simulating" property (value 0 or 1)
Set the property value in a Ev event Simulation Start,
and clear the property value in a Ev event Simulation Stop.
I think this idea came from Ben, so he probably does similar.
Leigh
sim.jpg
sim.jpg (97.34 KiB) Viewed 5831 times

Re: Decision component for simulation only

Posted: Thu Feb 14, 2019 10:56 am
by medelec35
Thanks Guys,
I have been following this post.
Just thought a more instant solution would be beneficial for all?

Re: Decision component for simulation only

Posted: Thu Feb 14, 2019 2:38 pm
by Benj
Hello,

Yes a great idea Martin,

Here's a quick go at a simple component complete with source.
IsSim.fcfx
(9.86 KiB) Downloaded 241 times
IsSim.fcpx
(1.37 KiB) Downloaded 261 times
I'll add an icon and a simple GUI and add it to the v8 release.

Inside the decision icon just add this code.

Code: Select all

IsSim1::Check()
No = MCU, Yes = Sim Runtime
SimCheck.jpg
SimCheck.jpg (8.47 KiB) Viewed 5806 times

Re: Decision component for simulation only

Posted: Thu Feb 14, 2019 7:08 pm
by medelec35
Hi Ben,
Just looked into this.
Do you have to add to flowchart

Code: Select all

Ev_Initialise
,

Code: Select all

Ev_Comp_Start
,

Code: Select all

Ev_Start
,

Code: Select all

Ev_Stop
&

Code: Select all

.Return = Sim
if using component?
If so, do you believe its easier than this?

Re: Decision component for simulation only

Posted: Fri Feb 15, 2019 1:44 pm
by Benj
Hi Martin,

You shouldn't have to add any of that.

It should be a case of add the component, Add the code to the decision icon. Job done :)

Re: Decision component for simulation only

Posted: Fri Feb 15, 2019 2:43 pm
by medelec35
Thanks Ben,
Benj wrote:You shouldn't have to add any of that.
Woops Sorry, I did not see the words source, so thought Flowchart posted was an example.

Tested on hardware and working better than expected as did not need to add

Code: Select all

IsSim1::Check()
, So no need to memorise!
It works buy just using the the component:
IsSim Test1.png
(47.37 KiB) Downloaded 2337 times
I will be adding Is Sim component to every flowchart that uses RX interrupt!