Decision component for simulation only

Moderator: Benj

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Decision component for simulation only

Post 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.
Martin

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Decision component for simulation only

Post 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.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Decision component for simulation only

Post 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 5118 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Decision component for simulation only

Post by medelec35 »

Thanks Guys,
I have been following this post.
Just thought a more instant solution would be beneficial for all?
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Decision component for simulation only

Post 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 184 times
IsSim.fcpx
(1.37 KiB) Downloaded 195 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 5093 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Decision component for simulation only

Post 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?
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Decision component for simulation only

Post 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 :)

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Decision component for simulation only

Post 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!
Martin

Post Reply