Automating Siemens S7 and SiMotion Tasks Using C# .NET

Automating Siemens S7 and SiMotion Tasks Using C# .NET

Siemens offers useful tools for accessing both Simatic and SiMotion projects programmatically, in the form of registered COM Type Library DLLs. These tools offer many exciting possibilities (well, it does if you're like me, and get excited by things like automating automation tools). If you have Simatic Manager installed, the following DLLs are registered with it:

S7hcom_x 1.0 Type Library - The default location on my laptop is C:\Program Files (x86)\Siemens\Step7\S7BIN\S7HCOM_X.DLL)

Simatic 1.0 Type Library - C:\Program Files (x86)\Siemens\Step7\S7BIN\S7ABATCX.dll

Likewise, if you have SiMotion installed, the following DLL is registered with it:

SiMotion 1.0 Type Library - C:\Program Files (x86)\Siemens\Step7\S7BIN\U7WSCOAX.dll

With these libraries, PLC and SiMotion programmers can automate repetitive or difficult tasks in the familiar .NET development environment using the off-the-shelf Microsoft COM Interop tool.


Working withSimatic Manager

Using these DLL’s to mimic Simatic Manager is called using the Command Interface, and  the object reference manual can be found on CD 2 of the Step 7 installation CD. After adding the DLLs as references in your project, getting started is as easy as the following:

 Simatic Sim = new Simatic(); Project Proj = Sim.Projects.Add(@“C:\MyProject\MyProject.s7p”); Console.WriteLine("Project created on: “ + Proj.Created); 


Working with SiMotion Scout

The parallel tool in SiMotion scout is simply called external scripting, and its object reference is in the standard Scout help interface. It’s pretty straightforward as well:

 Application App = new Application(); Project Proj = App.Projects[@"C:\MyProject\MyProject.s7p"] Console.WriteLine("Compiling Project”); Proj.Build(); 

There it is. You can see how easy it is to access project data and remotely send commands to projects.

Implementation Ideas

As someone who works with Simatic Manager and SiMotion Scout on a daily basis, there are some interesting possibilities for automation using these tools. Here are a few ideas I am throwing around:

  1. Source control integration using SVN or similar tools. Currently Siemens does not offer a comprehensive source control solution for code, and third party tools are prohibitively expensive and do not offer the same merging, branching, and traceability features that are common in text-based programming languages. I could see DMC using these DLLs to automate exporting  code source files into an SVN repo, and also importing them back into projects in order to have more sophisticated diff, merge, and trace capabilities in our Siemens projects.
  2. Automating repetitive programming tasks. For instance, oftentimes customers supply huge IO lists that need to be entered into a Siemens program, whether into the Symbol Table, data blocks, or code itself. These tools would let us automate these tasks to save a great deal of time, and reduce human error.
  3. Improving connectivity with other applications. We often have to export tag information from a Siemens data block to a CSV file in order to import it into some other company’s tool- an OPC server for instance. These DLLs give us a straightforward way to move data in and out of Siemens projects.
  4. Data acquisition from online data. Simatic Manager does not have a great trace feature like SiMotion does. These DLLs would allow a custom DAQ tool to collect data from the PLC without the need of an intermediary party’s driver, OPC server, etc.

I’m sure there are many more possibilities (and of course many may have been done already). Thanks for giving us these great tools, Siemens! And if anyone have any other insights or implementation ideas, be sure to let me know in the comments below.

Learn more about DMC's software and web development services.


# ashish

First of all, hats off to Siemens for sharing this dlls and not only that but also providing very detailed documentation for how to use it.

I have successfully use this tool to build the complete offline v/s online inventory and have found it very powerful.

Do you know of if something similar is available for Rockwell. I know there is System Ferret tool, but want the full documentation for how to use it like Siemens have provided.

Alternatively, do you know if Rockwell has any SDKs, etc. which can do similar job.

Thanks again for sharing your knowledge.

# Rajdeep
Can you please inform us why you have used "Simatic" interface instead of "SimaticClass"?

When you add reference of the "Simatic 1.0 Type Library" to your code it will creat interfaces and classes having same name as interface followed by "Class" suffiex.

So if we have class available then why we call methods and properties using the interface? Is there any difference in both this ways? actually this happens when we add reference of all COM type libraries. Can you please explain the difference?
# Ros
Hi, exciting possibilities? Is also possible to read out "Block checksum" of all blocks in a project? This number is displayed only after Comparing under Details.
# Tom
Is a description simatic objects available?

# brega
hi, nice article,
I have a function which requires more than 20 inputs, in a normal projects, I must add this inputs one by one, which is very frustrating.

is there any way to assign this function inputs via an external script as you mentioned above? i mean to find the relevant inputs from symbol table and assign it to the inputs?

Post a comment

Name (required)

Email (required)

Enter the code shown above:

Related Blog Posts