Срочно! Связь WinCC с Excel
roma; 23.6.04

Необходимо сформировать Excel документ со значениями процессорных тегов.

Для внутренних тегов через драйвер Windows DDE все работает, а вот для внешних тегов не подходит.
Подскажите, пожайлуста.
Может воспользоваться другим методом.
Re: Срочно! Связь WinCC с Excel
Nick Gashevsky; 23.6.04

На VisualBasik для своей программы исчпользовал компоненту OPC сервера SimaticNet. Дока и примеры есть справке по SimaticNet.

Re: Срочно! Связь WinCC с Excel
roma; 23.6.04

извени, можно подробнее

Re: Срочно! Связь WinCC с Excel
Nick Gashevsky; 23.6.04

Кусок хелпа WinCC 6.0

1
Open Microsoft Excel with a new workbook.

2
In the "Tools" menu, select "Macro" "Visual Basic Editor". This will launch the Visual Basic Editor for Microsoft Excel.

3
In the "Tools" menu of the Visual Basic Editor select "References...". A dialog titled "References - VBAProject" appears. Locate the entry "Siemens OPC DAAutomation 2.0" in the list of references available. Mark the corresponding checkbox. Click "OK" .

4
Click here. Copy the script. This script is only available in the online help.



Option Explicit

Option Base 1



Const ServerName = "OPCServer.WinCC"



Dim WithEvents MyOPCServer As OpcServer

Dim WithEvents MyOPCGroup As OPCGroup

Dim MyOPCGroupColl As OPCGroups

Dim MyOPCItemColl As OPCItems

Dim MyOPCItems As OPCItems

Dim MyOPCItem As OPCItem



Dim ClientHandles(1) As Long

Dim ServerHandles() As Long

Dim Values(1) As Variant

Dim Errors() As Long

Dim ItemIDs(1) As String

Dim GroupName As String

Dim NodeName As String



'---------------------------------------------------------------------

' Sub StartClient()

' Purpose: Connect to OPC_server, create group and add item

'---------------------------------------------------------------------

Sub StartClient()

' On Error GoTo ErrorHandler

'----------- We freely can choose a ClientHandle and GroupName

ClientHandles(1) = 1

GroupName = "MyGroup"

'----------- Get the ItemID from cell "A1"

NodeName = Range("A1").Value

ItemIDs(1) = Range("A2").Value

'----------- Get an instance of the OPC-Server

Set MyOPCServer = New OpcServer

MyOPCServer.Connect ServerName, NodeName



Set MyOPCGroupColl = MyOPCServer.OPCGroups

'----------- Set the default active state for adding groups

MyOPCGroupColl.DefaultGroupIsActive = True

'----------- Add our group to the Collection

Set MyOPCGroup = MyOPCGroupColl.Add(GroupName)



Set MyOPCItemColl = MyOPCGroup.OPCItems

'----------- Add one item, ServerHandles are returned

MyOPCItemColl.AddItems 1, ItemIDs, ClientHandles, ServerHandles, Errors

'----------- A group that is subscribed receives asynchronous notifications

MyOPCGroup.IsSubscribed = True

Exit Sub



ErrorHandler:

MsgBox "Error: " & Err.Description, vbCritical, "ERROR"

End Sub



'---------------------------------------------------------------------

' Sub StopClient()

' Purpose: Release the objects and disconnect from the server

'---------------------------------------------------------------------

Sub StopClient()

'----------- Release the Group and Server objects

MyOPCGroupColl.RemoveAll

'----------- Disconnect from the server and clean up

MyOPCServer.Disconnect

Set MyOPCItemColl = Nothing

Set MyOPCGroup = Nothing

Set MyOPCGroupColl = Nothing

Set MyOPCServer = Nothing

End Sub



'---------------------------------------------------------------------

' Sub MyOPCGroup_DataChange()

' Purpose: This event is fired when a value, quality or timestamp in our Group has changed

'---------------------------------------------------------------------

'----------- If OPC-DA Automation 2.1 is installed, use:

Private Sub MyOPCGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)

'----------- Set the spreadsheet cell values to the values read

Range("B2").Value = CStr(ItemValues(1))

Range("C2").Value = Hex(Qualities(1))

Range("D2").Value = CStr(TimeStamps(1))

End Sub



'---------------------------------------------------------------------

' Sub worksheet_change()

' Purpose: This event is fired when our worksheet changes, so we can write a new value

'---------------------------------------------------------------------

Private Sub worksheet_change(ByVal Selection As Range)

'----------- Only if cell "B3" chang10770983531013056416982307180 d:1037014088106325821410437455441093331638 10370140881063258214104374554410933316388648841020061471102464164810331299649692640919809328791077011985 ґ€9787100229493115521097065213995613702 ”
1020061471102464164810331299649692640919809328791077011985 њ#1020061471102464164810331299649692640919809328791077011985 d:10438255101000047111983181381  "1044017511102852248510777016801096170638 d:1037014088106325821410437455441093331638 д» 1046699983 Х#981107907 њ# Ё%10101347641018431611970118952ґ€930083434109809754794515565095858009410620551841034554952107580692010298288721026822958108269720894459826810825468381097040897103122367298551462010379742171094453735%Ѕ%9653682431013525035107511490221383510358780761075382586109801101610264607271081161809Advisories and threaded discussions. The threaded discussions allow you to ask questions, or look for solutions, on a subject that you may need help with where other PCS Users or Siemens staff may be able to assist you.
In closing let me assure you that we are firmly committed to providing you with regular up-to date information in order to make the integration of our Products and Systems, as well as the transition to new technologies, easier for you.
Yours sincerely!

Re: Срочно! Связь WinCC с Excel
Геннадий; 6.7.04

Попробуй так:


Dim MCP As Object
Dim WinCCValue As Variant

Set MCP=CreateObject("WinCC-Runtime-Project")
WinCCValue=MCP.GetValue("Имя_тэга_в_WinCC")

Читаются любые тэги (VisualBasic 6.0)
<<br>