38 lines
993 B
Plaintext
38 lines
993 B
Plaintext
Dim OPCServer, OPCGroup, OPCItem
|
|
Set OPCServer = CreateObject("OPC.Automation.1")
|
|
OPCServer.Connect "Takebishi.Dxp.7"
|
|
|
|
Set OPCGroup = OPCServer.OPCGroups.Add("Group1")
|
|
OPCGroup.UpdateRate = 1000
|
|
OPCGroup.IsActive = True
|
|
OPCGroup.IsSubscribed = False
|
|
|
|
' Add single item
|
|
Set OPCItem = OPCGroup.OPCItems.AddItem("SYSTEM.Tag020", 1)
|
|
WScript.Echo "ServerHandle: " & OPCItem.ServerHandle
|
|
|
|
' Method 1: OPCItem.Write direct
|
|
On Error Resume Next
|
|
OPCItem.Write(1)
|
|
If Err.Number <> 0 Then
|
|
WScript.Echo "Method1 OPCItem.Write(1) Error: " & Err.Description
|
|
Err.Clear
|
|
Else
|
|
WScript.Echo "Method1 OPCItem.Write(1) SUCCESS"
|
|
End If
|
|
|
|
' Method 2: SyncWrite with single item array
|
|
Dim sH(1), oVal(1), Errors
|
|
sH(1) = OPCItem.ServerHandle
|
|
oVal(1) = 2
|
|
OPCGroup.SyncWrite 1, sH, oVal, Errors
|
|
If Err.Number <> 0 Then
|
|
WScript.Echo "Method2 SyncWrite(1,...) Error: " & Err.Description
|
|
Err.Clear
|
|
Else
|
|
WScript.Echo "Method2 SyncWrite(1,...) SUCCESS"
|
|
End If
|
|
|
|
OPCServer.Disconnect
|
|
WScript.Echo "Done"
|