SungjuNewPrime/OPC Server Setting/OPC Client sample(DotNet to Delphi13)/Delphi13_VCL/test_write.vbs
jhw 6516e4a8f0 first upload
OPC test program upload
2026-09-04 11:41:21 +09:00

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"