Sometimes delay parameters need to be tweaked for operation on hardware vs. simulation. For example, I have a button that needs to detect a long press vs. a short press. It appears that simulation ignores debounce delays, thus affecting the time spent in loops checking switches.
Is there a technique to make such delays operate in simulation similar to how they operate on the target hardware without having to change a constant before running simulation or programming? Some way that the code can tell if it's running in simulation or on the target hardware, or conversely, some setting in Flowcode to set the simulation performance to match the hardware?
How to tell if simulating or running on hardware?
- 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: How to tell if simulating or running on hardware?
Hello,
I've created a simple example for you using a property named Sim. The property is defaulted to False or No for download. When you simulate I have included event macros that will first set the property value to True or Yes, perform the simulation and then restore the property value ready for the next download.
I've created a simple example for you using a property named Sim. The property is defaulted to False or No for download. When you simulate I have included event macros that will first set the property value to True or Yes, perform the simulation and then restore the property value ready for the next download.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 34
- Joined: Fri Dec 26, 2008 11:30 pm
- Has thanked: 12 times
- Been thanked: 10 times
- Contact:
Re: How to tell if simulating or running on hardware?
Thank, Benj, the test file works as expected. I tested both hardware and simulation and didn't have to change anything to get both to work correctly with your file.
But when I exported the macros and imported them into my own program, it didn't work. I see that your program has a decision that has a property, while the imported version loses that property.
In your program, decision box has a "sim" property: In imported macro, decision has no property: I've never played with the Sim macro stuff before...can you give me a very short explanation of how to make it work in this situation, then point me to the Flowcode documentation that would give me a more thorough overview?
Thanks as always...
But when I exported the macros and imported them into my own program, it didn't work. I see that your program has a decision that has a property, while the imported version loses that property.
In your program, decision box has a "sim" property: In imported macro, decision has no property: I've never played with the Sim macro stuff before...can you give me a very short explanation of how to make it work in this situation, then point me to the Flowcode documentation that would give me a more thorough overview?
Thanks as always...
- 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: How to tell if simulating or running on hardware?
Hello,
Here are some instructions to replicate what I did in the example.
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 unticked Writable to stop the user from manually changing the value but this isn't required.
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 when the sim starts and stops.
In the Ev_Start macro 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 this component, "Sim" is the name of the property in quotes to avoid referring to the property value and the last parameter sets the state of the property.
You can now add the Sim decisions anywhere in your program where Sim and download need to do different things.
Here are some instructions to replicate what I did in the example.
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 unticked Writable to stop the user from manually changing the value but this isn't required.
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 when the sim starts and stops.
In the Ev_Start macro 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 this component, "Sim" is the name of the property in quotes to avoid referring to the property value and the last parameter sets the state of the property.
You can now add the Sim decisions anywhere in your program where Sim and download need to do different things.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 34
- Joined: Fri Dec 26, 2008 11:30 pm
- Has thanked: 12 times
- Been thanked: 10 times
- Contact:
Re: How to tell if simulating or running on hardware?
Very nice explanation, thank you, Benj.
I can now see why simply exporting and importing the macros didn't work, there are a few more steps involved.
I hadn't looked into Flowcode events previously because I didn't really see any apparent benefits to real-world development aside from manipulating simulation graphics etc. But being able to use events to automatically change code, based on whether compiling or simulating, is a time-saving benefit.
I intend to take a closer look at the documentation for events, as well as component development, to see if I can discover additional beneficial usages for my projects. Can you point out any particular uses of events that might be considered beneficial to the development process, if you've already followed that path?
Thanks again....
I can now see why simply exporting and importing the macros didn't work, there are a few more steps involved.
I hadn't looked into Flowcode events previously because I didn't really see any apparent benefits to real-world development aside from manipulating simulation graphics etc. But being able to use events to automatically change code, based on whether compiling or simulating, is a time-saving benefit.
I intend to take a closer look at the documentation for events, as well as component development, to see if I can discover additional beneficial usages for my projects. Can you point out any particular uses of events that might be considered beneficial to the development process, if you've already followed that path?
Thanks again....
- 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: How to tell if simulating or running on hardware?
Hello,
One of the best use of events so far for me is the ability to add dynamic code when compiling. For example you can have an array of pretty much unlimited size for the simulation and change the size of the array when compiling. You can also choose to add variables or not. Mouse events are good for mouse interaction in the simulation. Timer events are good for monitoring or animating, the formula allcode uses timer events to move around the panel. The Connection change events are good for re-working out connections etc.
This might be good to show you some tricks.
https://www.instructables.com/id/Two-Wh ... -Simulate/
One of the best use of events so far for me is the ability to add dynamic code when compiling. For example you can have an array of pretty much unlimited size for the simulation and change the size of the array when compiling. You can also choose to add variables or not. Mouse events are good for mouse interaction in the simulation. Timer events are good for monitoring or animating, the formula allcode uses timer events to move around the panel. The Connection change events are good for re-working out connections etc.
This might be good to show you some tricks.
https://www.instructables.com/id/Two-Wh ... -Simulate/
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel