WinCC: Exporting tag groups

L

Thread Starter

Lauri

<p>I'm working with WinCC V6.0 and I'm trying to export an entire tag group to an external database (Access). I dug up from the help documents a way to export single tags:
<pre>
Dim objConnection
Dim strConnectionString
Dim lngValue
Dim strSQL
Dim objCommand

strConnectionString = "Provider=MSDASQL;DSN=SampleDSN;UID=;PWD=;"
lngValue = HMIRuntime.Tags("TankLevel").Read
strSQL = "INSERT INTO WINCC_DATA (TagValue) VALUES (" & lngValue & ");"

Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With

objCommand.Execute
Set objCommand = Nothing
objConnection.Close

Set objConnection = Nothing
</pre>
<p>But can I export an entire tag group instead of exporting every single tag one by one?
 
if each tag has it's own column in your Access table, then just expand the INSERT query

e.g.
strSQL =
"INSERT INTO WINCC_DATA (Tag1, Tag2, Tag3, ...)
VALUES (" & Val1 & "," & Val2 & "," & Val3 & ", ...);"

If you want each tag to be a separate record in the table then you can do multiple INSERT commands. Just keep changing the value in the strSQL variable and rerunning the Command.Execute function.

Alternatively you can use an INSERT INTO with a SELECT statement (instead of specifying VALUES)

This is very basic SQL. I'd recommend you research the INSERT command and standard ADO commands. A good starting site for both is http://www.w3schools.com

hope this helps
Salma
 
Thanks

Actually I was aiming to somehow skip separately writing the name of each tag since the number of tags can be up to a few hundred... What I wanted to do was assign the tag group name to be the table name and then write each tag of that tag group to the columns of the table.

And I am searching for a way to make this as automated as possible because it would be used in several projects.

Is there a way to list all the tags of the project?
 
You have three options:

1) Open Development Kit (ODK) Option for WinCC
This is a developers toolkit which offers lots of advanced functions for both the runtime and development environment. It contains a series of functions for tag handling (reading, creating, deleting, etc.)

2) All the tagnames are listed in the configuration database...
However this is COMPLETELY unsupported. The problem with this method is if you affect the configuration database in any way then you run a high risk of corrupting your project and stopping it running correctly!!

However if you know what your doing, database wise, then it's a possiblility. I apologise for coming across strong but it's vital that you understand the importance of the config database

3) Export the tag list to a csv file. You can then easily set up a loop in your script to first read in the tagname and then write out the value. This method doesn't have the complexity of the first option nor the risk of the second method.

TIP: You can use the Tag Export/Import tool or the Mass Configuration tool to export the tagnames. You can then use the FileSystemObject to read files in a VBS script.

hope this helps
Salma
 
Have same problem as Lauri but for me it's ok to select each Tag and write them to their own field in Access.
I just can't get the SQL right if I have more than one tag.
Does any one know how to play with the (["' etc?

Fredi
 
i want to thank to salma.
your projects so usefull.
i've solved my problem with your project.
we are waiting for new comments :)
 
Top