SimTree - Guide
What is SimTree? 2
System requirements 2
The Application 2
Getting started 2
Help 5
The Code 6
Creating the “SimTreeExamplesProject” 6
The inner structure of SimTree 7
S*I*M*A*T*I*C – Comment 7
Regions 7
WrapperCls 7
TagObj 7
DialogCls 7
Example: RenameObj 7
WaitCursor 8
HelpNumberCls 8
The Context-Menu-Strips 8
The Properties-Dialogs 9
Add an unspecified User-H-Connection 10
SimTree is an example-application to show what can be done with the command-interface of Step7. It includes (nearly) every function of the command-interface, links to the command-interface-help and the SimTree-source-code itself. It should be possible to find examples to all functions within the code.
To use the application, STEP 7 must be installed (it was tested with Version 5.5) and you need at least .NET Framework 4.0. You can find the application in SimTree2010\SimTree2010\bin\Release. The code was written with Visual Studio 2010, so if you want to open the whole Solution (what is recommended) you should use Visual Studio 2010 or newer.
Start the application SimTree.exe
The SimTree-window is divided into two areas. On the left side there is the dynamic part of the application. Here you can load Simatic-projects and edit them. On the right side of the window you can see the object-structure of the command-interface. This “tree” contains links to the help topics specified by the object. When a project is loaded, the tree highlights objects, corresponding to the selected item on the left side. Thus you can comprehend how the command-interface is structured.
To get familiar with the handling of SimTree, we will start with an example-project. Press the button “Create Example-Project”. A second window pops up.
You can choose which components of the example should be created. For the beginning the “300 Station” is enough. Uncheck all Create-options except 300 Station and click “Create”. Now the Application creates a new project called “SimTreeExampleProject” and adds the Station “Station300”. It also adds some modules and subnets with slaves. After the program finished, close the window and load the project in SimTree. To do so, press FILEàOpen Project on the top-menu. The Open-Project-Dialog will appear.
Select “SimTreeExampleProject” and press “Load”. The project will load and SimTree will show it on the left side of the window.
Now you can go through the project. The project-tree is structured like the command-interface and the names of the objects are the texts of the nodes. You can get to the command-interface-help by pressing “F1”. The help will open the page that belongs to the current selected object. To see the properties of a specific object, right-click on it and choose “Properties…” in the context-menu. Every object-type has its own properties-dialog, because the properties and functions of an object differ, too. Here you can see the module-properties-dialog of a module.
In this dialogs you can edit the properties of an object. Some of the properties cannot be edited, because they are read only. To edit an attribute, double-click on the attribute-name and insert a new value. When you changed a value of an attribute or a parameter, it will be saved immediately. Closing the Module-Dialog by pressing “Cancel” will not undo the changing! For more detailed information about the object-parameters, press help.
As you might have already noticed, there are various items in each context-menu. They are different for every object and they even depend on the location of the object. For example, a module in a slave has other context-menu-items than a module in a rack. That’s because there are some functions especially for one type of module. Not every module-function can be used on every module!
Now you have the basic knowledge to work with SimTree. The next step is to understand, how the program works, to enable you to work with the command-interface yourself. Please consider that SimTree is just an example for the usage of the command-interface. It was not the demand to give you a program with an optimized performance, but to show you how to work with the command-interface. Therefore, the code is structured to be readable not to have an optimized performance.
You can get to the help from nearly every dialog by pressing “F1” or the “Help”-button. The help will open on the page that belongs to the object you are currently working at. You can also get to the help by clicking on an object-node on the right side of the application.
The Application is written in C#. To understand the code, you should have a basic knowledge of this language.
The easiest way to get familiar with the command-interface is to see, how a project is created. Therefore the SimTreeExamplesProject is a good example. Firstly you’ll need a Simatic-object. This is created in WrapperCls of SimTree.
public static SimaticLib.ISimatic4 sim = new SimaticLib.Simatic();
From now on, we will stay in CreateExampleDlg. Secondly we open the project or create it, if it doesn’t exist.
try
{
// Try to open SimTreeExampleProject
project = WrapperCls.sim.Projects["SimTreeExampleProject"];
}
catch
// Create SimTreeExampleProject
project = WrapperCls.sim.Projects.Add("SimTreeExampleProject");
Now we can create a new station and add objects.
S7HCOM_XLib.IS7Station5 station;
// Add station
station = (S7HCOM_XLib.IS7Station5)project.Stations.Add("Station300", SimaticLib.S7StationType.S7300Station);
S7HCOM_XLib.IS7Rack rack;
// Add rack
rack = station.Racks.Add("UR", "6ES7 390-1???0-0AA0", "", 0);
S7HCOM_XLib.IS7Module6 cpu;
// Add power-supply
rack.Modules.Add("PS 307 10A", "6ES7 307-1KA00-0AA0", "", 1);
// Add cpu
cpu = (S7HCOM_XLib.IS7Module6)rack.Modules.Add("CPU 319-3 PN/DP", "6ES7 318-3EL01-0AB0", "", 2);
// Add more modules
rack.Modules.Add("SIFLOW FC070", "7ME4 120-2DH20-0EA0", "", 4);
rack.Modules.Add("FM 355 C PID Control", "6ES7 355-0VH10-0AE0", "", 5);
…
The whole code can be found in CreateExampleDlg.
To make it easier to find functions that deal with the command-interface, every command-interface-function has the comment ----------*S*I*M*A*T*I*C*----------. You don’t have to read the whole function to find the one line that is important for you.
Sometimes there is the comment “not important for Simatic” at the beginning of a function. That means, this is a function you don’t need to understand, because there is just something program-internal.
The two classes MainFrame and WrapperCls are separated into regions. The main regions are structured like the SimTree-window. The region “ContextMenuStrips” has regions itself, which are structured like the command-interface-objects.
Every request to the command-interface, made in MainFrame, is stored in WrapperCls. Thus, if you are searching for a specific command-interface-function, search for it in this class. When a function is not in WrapperCls, look for it in the properties-dialogs. To communicate with MainFrame, the program uses an object called TagObj.
When a project is loaded, it is saved in a treeView-object. The COM-objects are saved as SimObj in the tags of the nodes. To specify the type of the object, there is the enumerator SimObjType. The numbers of this enumerator have a second meaning. They are also the IDs for the command-interface-help (the IDs are stored in helpNumberCls). Another object called concreteType includes more details about the object-type. All information is collected in the class TagObj.
All functions in this class open extern dialogs to get input from the user. Normally the dialog returns the input value. If the dialog was quitted with the “Cancel”-button, the function throws an exception. The internal structure of DialogCls is not important for the usage of the command-interface.
When the “Rename…”-item is pressed in a context-menu, the MainFrame takes the TagObj from the selected node and assigns it to the WrapperCls-function RenameObj. The new name is the return value of a DialogCls-function:
// Get selected node in treeProject
TreeNode node = treeProject.SelectedNode;
if (node == null)
MessageBox.Show("Select an object to rename it");
return;
String newName;
// Get new name
newName = DialogCls.InputStringDlg("Insert new name", "New Name:", node.Name);
// Rename object
WrapperCls.RenameObj((TagObj)node.Tag...
Buziol_1969