suche dringend Hilfe ( OPC DA Client,Excel, VBA)

Haining

Level-1
Beiträge
1
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo Leute,
Ich habe ein OPC DA Client geschrieben. Irgendwie läuft es einfach nicht. Könnte jemand es mal sich anschauen? Es wäre nett.



Dim MyItem(300) As OPCItem
Dim MyItems As OPCItems
Dim MyGroup As OPCGroup
Dim MyGroups As OPCGroups
Dim MyOPCServer As OPCServer





Dim isserverstarted As Boolean
Dim isgroupadded As Boolean
Dim isitemadded(2) As Boolean


Dim MyOPCItemID(300) As String
Dim addItemCount As Long
Dim MyOPCItemIDs(300) As String


Dim clienthandles(300) As Long
Dim serverhandles(300) As Long


Dim Source As Integer
Dim Value(300) As Variant
Dim Quality(300) As Variant
Dim Timestamp(300) As Variant
Dim Errors() As Long


Dim allopcservers As Variant




Dim i As Integer








Public Sub Probe()
Set MyOPCServer = New OPCServer


allopcservers = MyOPCServer.GetOPCServers


For i = 1 To UBound(allopcservers)
Cells(i, 1) = "gefundener Server Nr. " + CStr(i) + ":" + (allopcservers(i))
Next i
MyOPCServer.Connect (allopcservers(1))

Dim MyOPCServerBrowser As OPCBrowser
Set MyOPCServerBrowser = MyOPCServer.CreateBrowser
MyOPCServerBrowser.ShowBranches
MyOPCServerBrowser.MoveDown (MyOPCServerBrowser.item(1))
MyOPCServerBrowser.DataType = vbInteger
MyOPCServerBrowser.ShowLeafs
Cells(1, 2) = MyOPCServerBrowser.Count & " Register"
Dim name As Variant
For i = 1 To MyOPCServerBrowser.Count
MyOPCItemIDs(i) = MyOPCServerBrowser.item(i)
Cells(i + 10, 10) = MyOPCItemIDs(i)
Cells(i + 10, 3) = ""
Next i



Dim mygroupname As String
mygroupname = "random"

Set MyGroups = MyOPCServer.OPCGroups
Set MyGroup = MyGroups.Add(mygroupname)

MyGroup.UpdateRate = 1000
MyGroup.IsActive = True
MyGroup.IsSubscribed = True

Set MyItems = MyGroup.OPCItems



Source = OPC_DS_Cache

For i = 1 To MyOPCServerBrowser.Count
clienthandles(i) = i
serverhandles(i) = i

Set MyItem(i) = MyGroup.OPCItems.additem(MyOPCItemIDs(i), clienthandles(i))

'serverhandles(i) = MyItem(i).ServerHandle

'Set OPCItem = OPCItems.GetOPCItem(serverhandles(i))
'Cells(i + 10, 14) = MyItem(i).ItemID

Next i

Cells(i + 10, 1) = serverhandles(i)





Dim NumItems As Long
NumItems = MyOPCServerBrowser.Count





Call MyGroup.SyncRead(OPCCache, NumItems, serverhandles(), Value(), Errors(), Quality(), Timestamp())


Cells(i + 10, 2) = MyOPCItemIDs(i)
Cells(10 + i, 7) = Value(i)
Cells(10 + i, 8) = Timestamp(i)
Cells(10 + i, 9) = Quality(i)




End Sub


Gruß
 
Kommentare im Quellcode sind ne tolle Erfindung so könnte man schneller verstehen was du da machen möchtest.
 
Zurück
Oben