AzeoTech Posted July 26, 2008 Share Posted July 26, 2008 In a previous post I talked about how to do one of the two main types of "recipes". In that case a recipe was a set of preset values that would be sent to a device. This might be used, for example, when mixing paints. A recipe would be the amount of the primary colors to make the final result. In this post I'd like to show you how to do the other type of recipe. In this case, a recipe is really just a high level set of steps to perform. Truthfully, DAQFactory scripting is just low level, highly flexible, recipe system of this sort, but with power comes some learning, and you may only want to give you end users a few choices. My description is a little detailed, but the sample is pretty easy to expand on without completely understanding it all, and truthfully, the sample shows some good ways to make many tasks easier, so is worth figuring out if you are going to do any advanced DAQFactory scripting. In the attached sample (requires 5.78+), I have created a simple heater / temperature simulation that can be controlled from a simple, user definable recipe. The user can create up to five steps in their recipe and they have a few choices for what they can do in each step, mainly, turn the heater on, turn the heater off, wait for the temperature to reach a certain point, and do a pause. The user can specify the recipe by selecting from these options in combo boxes, with edit boxes that appear when a parameter is required. As usual, I designed this sample so you can easily build on it. The possible recipe steps are stored in three arrays, one for the name of the step, one for the action and one for a flag that marks if there is a parameter for the action. These are all defined in StartUp. To add more steps possibilities, just add on to the array in StartUp. Note that the StepAction is a string that contains a DAQFactory script line. It is injected with a value using format() which is what allows a parameter to be set. Just use %f in the line wherever you want the parameter. The recipe itself is stored in two arrays, one for the step index, and one for the parameter (if any for that step). At the end of startup, I filled all the combos with the choices. I only made 5 combos, but you could easily make the recipes longer by adding more combos and edit boxes. Just change MAXSTEPS and add the new screen components, remembering to edit the parameters for each. Speaking of the screen components, the recipe gets specified by the user using a set of combo's and edit boxes. The edit boxes appear and disappear depending on whether the selected step has a parameter to specify. This is done in the OnPaint event of the edit box (you have to View - Events to see it). Yes, I know I've previously lectured on why you shouldn't use edit boxes on main screens, but presumably you would NOT put a recipe specification on a main screen, and instead would create a popup or secondary screen that has to be acknowledged. Finally, the actual recipe gets run in the RunRecipe sequence, which really just loops through each step and calls execute() on it. Notice how, instead of using delay() for the pause step, I created a sequence function. This allows the recipe to be stopped midway in a controlled manner. This is better than simply stopping the RunRecipe sequence because if we do endseq() on a sequence, we don't know where it ended. So, to try it, I recommend creating a recipe something like this: Heater On WaitForTemperature xx.xxx Heater Off where xx.xxx is some temperature that is about 0.5 higher than the current displayed temperature. Then run the recipe. Feel free to post with questions. Again, this sample requires DAQFactory 5.78 or later. recipesample2.ctl Link to comment Share on other sites More sharing options...
This topic is now archived and is closed to further replies.