What we want to build - logic:
A house control where two rooms have a temperature regulator in them.
What we want to build - visual:
a view showing a floor plan of a house, with a temperature regulator placed in two of the rooms. The actual temperature should be visible in the overview picture. When we press on the temperature regulator icon, a window opens, showing the set point (editable) and the actual temperature (read only). We will also show the name of the (instance of the) assembly.
This will be the window that opens, so all we need to build is the "button" that opens this window.
The below illustration shows what you will build in this tutorial. The red dots indicate tutorial steps.
Before we start building, here are a few important facts about how to work with views.
- Views can be created for data types (which we will see examples of in tutorial 7), devices (which we will do in tutorial 6), components (as we did in tutorial 1), for assemblies (as we did in tutorial 4) and for main assemblies (which we will do later in this tutorial. You cannot create views for projects.
- You can design as many views as you want for a given component or assembly.
- The elements that you can visualise are registers and (results of) Get/Set-methods (which will typically return one or more values).
- You can add drawings (in SVG-format) as we will do later in this tutorial
- You can also add labels - that can be used to show a "fixed text" information.
- And finally you can add existing views, so your view can be composed of a mix of exising views and your own additions.
You can only visualise what the component/assembly has access to, so as a rule of thumb:
- Create Main Assembly views to visualise your total project functionality.
- Create Assemby views to demonstrate the functionality of a component that connect to other components (as e.g the visualisation we created in tutorial 4).
- Create component views if your component contains all the information inside itself - possibly by reading the information from others into registers (as we did in tutorial 1)
- Create device views to visualise any device related information (serial numbers, wiring info, temperature of the module etc.)
- Create data type views to visualise data such as e.g. an enumerated types, registers etc.
Step 1: Creating the button
Open the assembly.
Set view region - bottom right to y=50[mm] and x=50[mm]
Right click on view list and add drawing PD_17418- Temperature_Regulator
Right click on view list and the name of the (instance of the) assembly. Right click on view list and select "add"- "view for control instance" Double click on "XX_temperature_regulator_notification". Select PD_2292 - Name.
This is because your drawing is a bit bigger than the view area defined, so we need to scale it.
Click in the black part of the view - this will select the drawing in the editor. Switch to the editor and set scale factor 0.4
Now move your visualisation elements around, so they look something like this:
Now you need to indicate which window to open when the button is pressed. And here we will reuse the visualisation we made in tutorial 4.
Right click on the Open Info, press "view to open" -> "Select" -> view for control instance, double click on the assembly"XX_Temperature_Regulator_notification_assembly" select "Window_for_XX_Temperature_Regulator_notification_assembly".
The last thing you need to do is to make sure that the window opens, no matter where the user clicks on the button.
What your code should look like:
Now all mouse clicks or screen taps will go to the "open view in new window".
According to the specifications, we need two instances of the temperature regulator, and we want to display their names, so a few updates are needed in the existing main assembly.
Open your main assembly from tutorial 4, ie. XX_Temperature_regulator_notification_main.
Add a new instance of assembly "XX_temperature_regulator_notification_assembly". Rename it to "Dining room". Locate the new control components on PD 850. On your testbed, connect a temperature regulator to 11/31 and a DC output to 2/22.
Here we see one of the very powerful features in VIGO6. Having built a complex functionality (the temperature regulator assembly) once, we can reuse instances of it easily, simply by adding a new instance to our assembly (and eventually wiring up any I/O of course).
Step 3: Building the main view.
We are now ready to build our main view using the building blocks we just created.
Right click and select "Create new view for this type based on" and select "PD_13556 Asm_view". Rename to "XX_Main_view_with_house_and_regulators". Set view region bottom right y=200[mm] and x= 300[mm]
Right click on view list and add:
- Drawing: PD_17425 Plan_Drawing_Tutorial. Set the scale factor to 1.8
- view for control instance: find and double click on assembly "Bathroom" and select the view "button_for_XX_Temperature_regulator_notification_assembly". Set the scale factor to 0.9.
- view for control instance: find and double click on assebly "Dining room" and select the view "button_for_XX_Temperature_regulator_notification_assembly". Set the scale factor to 0.9.
Save the view and launch the graphical editor. Now drag the elements around to find suitable rooms for your icons/buttons.
Your visualisation should look something like this:
Step 4: Build and run your project.
Now open your project "XX_Temperature_regulator_notification_project", find the "COPP PC with display". Open the guest view - delete the existing view and add your view "XX_Main_view_with_house_and_regulators".
Save, build and run your project on the test bed.
Make sure to click on the regulator buttons to see your windows open and test your two regulator instances via the test bed.