Skip to content

Instantly share code, notes, and snippets.

@tallakt
Created July 23, 2009 09:52
Show Gist options
  • Save tallakt/152626 to your computer and use it in GitHub Desktop.
Save tallakt/152626 to your computer and use it in GitHub Desktop.
require 'win32ole'
opc_automation = WIN32OLE::new 'OPC.Automation'
# get list of servers
opc_automation.GetOPCServers
# Connect to specific server
opc_automation.connect 'Matrikon.OPC.Simulation.1'
opc_group = opc_automation.OPCGroups.Add
opc_items = opc_group.OPCItems
items = ['Bucket Brigade.Real8']
# validate tag names
# errors = opc_items.Validate items.size, [0] + items
# add tags to group
# last list is client handles
server_handles, errors = opc_items.AddItems items.size, [0] + items, [0] + 1.upto(items.size).to_a
errors = opc_group.SyncWrite server_handles.size, [0] + server_handles, [0] + [99]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment