Reputation: 11
I’m trying to use PowerShell to read values from an OPC server. I have been doing some research but I can’t see any reference or similar case.
I installed the Matrikon OPC Simulation server and tried loading OPCdotNETLib.dll assembly. The assembly is loaded successfully. I can see intellisense when operating with the objects. I’m not getting any error now but I don’t think is connecting successfully.
$Path = "C:\OPCdotNETLib.dll"
Add-Type -Path $Path
[System.Reflection.Assembly]::LoadWithPartialName('System.Runtime.InteropServices')
$OPCServer = New-Object OPC.Data.OpcServer
$OPCServer = [OPC.Data.OPCServer]::new()
$OPCServerName = "Matrikon.OPC.Simulation.1"
$OPCServer.Connect($OPCServerName)
Would you have any clue or help reference?
Upvotes: 1
Views: 4343
Reputation: 1608
You can use QuickOPC (http://www.opclabs.com/products/quickopc ; disclaimer: this is a self-promotion). OPC read is done as follows:
Add-Type -Path OpcLabs.EasyOpcClassic.dll
# Create EasyOPC-DA component
$client = New-Object OpcLabs.EasyOpc.DataAccess.EasyDAClient
# Read item value and display it
$client.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Single")
Taken from: http://kb.quickopc.com/How_to_read_an_OPC_item_value_in_PowerShell
Upvotes: 1