How to subscribe to OPC data changes in PowerShell

From OPC Labs Knowledge Base
Revision as of 16:01, 28 September 2016 by User (talk | contribs)
Jump to navigation Jump to search

The following PowerShell code subscribes to an OPC item and displays the incoming data changes:

Add-Type -Path OpcLabs.EasyOpcClassic.dll

# Create EasyOPC-DA component 
$client = New-Object OpcLabs.EasyOpc.DataAccess.EasyDAClient

# Hook events
Register-ObjectEvent -InputObject $client -EventName ItemChanged -Action { Write-Host $EventArgs }

# Subscribe
$client.SubscribeItem("", "OPCLabs.KitServer.2", "Demo.Single", 1000)

We have tested this with QuickOPC 5.40 and PowerShell 3.0.

Note2-icon.png

Note: For some issues and limitations, see How to read an OPC item value in PowerShell.


Links related to/used when writing this article: