0% found this document useful (0 votes)
117 views

SimTree - Guide

SimTree is an application that demonstrates how to use the Step7 command interface. It loads an example project called SimTreeExampleProject that contains a station and modules. Users can view object properties, context menus, and help links to understand how the command interface works. The code is organized into regions corresponding to the application interface and command interface objects. Key classes include WrapperCls for communicating with the command interface, TagObj for managing object tags and types, and DialogCls for displaying property dialogs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

SimTree - Guide

SimTree is an application that demonstrates how to use the Step7 command interface. It loads an example project called SimTreeExampleProject that contains a station and modules. Users can view object properties, context menus, and help links to understand how the command interface works. The code is organized into regions corresponding to the application interface and command interface objects. Key classes include WrapperCls for communicating with the command interface, TagObj for managing object tags and types, and DialogCls for displaying property dialogs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

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
What is SimTree?
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.

System requirements
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.

The Application

Getting started
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.

Help
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 Code
The Application is written in C#. To understand the code, you should have a basic knowledge of
this language.

Creating the “SimTreeExamplesProject”


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.


The inner structure of SimTree

S*I*M*A*T*I*C – Comment
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.

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

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

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.

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

Example: RenameObj
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:

MainFrame:

// Get selected node in treeProject


TreeNode node = treeProject.SelectedNode;
if (node == null)
{
MessageBox.Show("Select an object to rename it");
return;
}

String newName;
try
{
// Get new name
newName = DialogCls.InputStringDlg("Insert new name", "New Name:", node.Name);
// Rename object
WrapperCls.RenameObj((TagObj)node.Tag, newName);
}
catch
{
return;
}

WrapperCls:

public static void RenameObj(TagObj tag, String newName)


{
switch (tag.SimObjType)
{
case SimObjType.Project:
SimaticLib.IS7Project3 proj = (SimaticLib.IS7Project3)tag.SimObj;
proj.Name = newName;
break;
case SimObjType.Station:
S7HCOM_XLib.IS7Station5 stat = (S7HCOM_XLib.IS7Station5)tag.SimObj;
stat.Name = newName;
break;
case SimObjType.Rack:
S7HCOM_XLib.IS7Rack rack = (S7HCOM_XLib.IS7Rack)tag.SimObj;
rack.Name = newName;
break;

}
}

WaitCursor
WaitCursor turns the cursor into the Windows-wait-cursor and back to the default-cursor.

HelpNumberCls
HelpNumberCls includes all help-IDs used in the program as constant unsigned integers.

The Context-Menu-Strips
The context-menu-strips include most of the command-interface-functions. Every object-type
has its own context-menu. You can find the command-interface-functions to the menus in the
region “ContextMenuStrip” in WrapperCls. Consider that some functions are disabled in a
context-menu-strip, because they are not available for an object, but not all non-disabled-
functions are available. For example, some functions of the module-object are especially for
CPUs. You can select them from other modules than CPUs, too, but then they will throw an
error. Furthermore, you can always see online functions, but they are only operating when you
have an online-connection.

The Properties-Dialogs
Every object-type has its own properties-dialog. Every dialog consists out of properties and
functions, specific for this type. Sometimes not all properties or functions are available, because
they just exist for some objects of this type. In this case the buttons or textboxes are disabled.
Some command-interface-functions are implemented in the properties -dialogs and cannot be
found in WrapperCls! If you can’t find a function in WrapperCls look at the corresponding
properties -dialog.

Example: Link a module to a subnet


You are searching for how to link a module to a subnet and you know the function is

module.LinkSubnet(subnet);

You won’t find a function “LinkSubnet” in WrapperCls, because it’s implemented in


ModuleSubnetProperties. Here you will find it within the method “btnLink_Subnet_Click”.
Add an unspecified User-H-Connection
A User-H-Connection can be created in the Dialog AddHConnDlg. To start this Dialog, go to
the top-menu of MainFrame and click on PROJECTAdd H-Connection.

On the right side you can find a short guide that tells you how to use this dialog. The most part
of the dialog shows a split-container. Both panels of the container have the same structure.
Before you can create a new connection, you have to select the modules that are used for
connection the two stations. Therefore, load both, the local and the remote project. They will
appear as trees.

Now register all needed modules. You can do this by selecting the module-type in the list and
then selecting the corresponding module in the tree.
When all modules were chosen, the “Add Connection”-Button will be enabled. By pressing this
button, the add-process will start. The add-process itself happens in another method called
AddHConn2Way/AddHConn4Way.

public static void AddHConn2Way(S7HCOM_XLib.IS7Module6 locCpu, S7HCOM_XLib.IS7Module6


locCp1, S7HCOM_XLib.IS7Module6 locCpI1,
S7HCOM_XLib.IS7Module6 locCp2, S7HCOM_XLib.IS7Module6 locCpI2,
S7HCOM_XLib.IS7Module6 remCpu, S7HCOM_XLib.IS7Module6 remCp1,
S7HCOM_XLib.IS7Module6 remCpI1, S7HCOM_XLib.IS7Module6 remCp2,
S7HCOM_XLib.IS7Module6 remCpI2, S7HCOM_XLib.IS7Rack remRack, bool active)
{
S7HCOM_XLib.IS7Conns2 conns;
S7NCIE_XLib.S7NHC2Way hConn;
try
{
conns = (S7HCOM_XLib.IS7Conns2)locCpu.Conns;
hConn = new S7NCIE_XLib.S7NHC2Way();

// Get all parameter


hConn.NUMBER_OF_WAYS = 2;

hConn.LOCAL_INTERFACE_MODULE_WAY1 = locCp1.Name;
hConn.LOCAL_INTERFACE_ADDRESS1 = locCpI1.MACAddress;
hConn.LOCAL_INTERFACE_MODULE_WAY2 = locCp2.Name;
hConn.LOCAL_INTERFACE_ADDRESS2 = locCpI2.MACAddress;

// Remote partner from another project


hConn.REDUNDAND_REMOTE_RACK = remRack.Index;
hConn.REDUNDAND_REMOTE_SLOT = remCpu.Index;
hConn.REMOTE_INTERFACE_MODULE_WAY1 = remCp1.Name;
hConn.REMOTE_INTERFACE_ADDRESS1 = remCpI1.MACAddress;
hConn.REMOTE_INTERFACE_MODULE_WAY2 = remCp2.Name;
hConn.REMOTE_INTERFACE_ADDRESS2 = remCpI2.MACAddress;

// Create connection
S7HCOM_XLib.S7Conn s7NewConn =
conns.AddUserHConn2Way((S7HCOM_XLib.IS7Module)locCp1, hConn);

// Some more values to set


s7NewConn.set_Attribute("LFD_NO", "16");
s7NewConn.set_Attribute("REMMOD_LFDNR", "16");
string rackNo = Convert.ToString(remRack.Index);
s7NewConn.set_Attribute("REMMOD_RACKNO", rackNo);
string slotNo = Convert.ToString(remCpu.Index);
s7NewConn.set_Attribute("REMMOD_SLOTNO", slotNo);
s7NewConn.set_Attribute("REMOTE_PARTNER_INFO", remCpu.LogPath);
s7NewConn.set_Attribute("REMOTE_PARTNER", remCpu.LogPath);
if (active)
s7NewConn.set_Attribute("ACTIVE_CONN_SETUP", "1");
else
s7NewConn.set_Attribute("ACTIVE_CONN_SETUP", "0");
}
catch
{
MessageBox.Show("An error occurred while creating the user-h-connection");
}
}

This function is called twice. One time, to create the connection in the local project and another
time, to create the connection in the remote project.

You might also like