Difference between revisions of "How to read an OPC item value in PowerShell"

From OPC Labs Knowledge Base
Jump to navigation Jump to search
(Created page with "Category:.NET Category:Console application Category:PowerShell Category:How to Category:OPC DA The following PowerShell code reads an OPC item and displays...")
 
Line 12: Line 12:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
We have tested this with QuickOPC 5.40 and PowerShell 3.0. Presumably it works with OPC UA (Unified Architecture) too.
+
We have tested this with QuickOPC 5.40 and PowerShell 3.0. Presumably the same concept works with OPC UA (Unified Architecture) too.
  
 
For now, consider this just a proof of concept. So far, we have not specifically targeted PowerShell when designing the components, and there are some rough edges. We have found following issues so far:
 
For now, consider this just a proof of concept. So far, we have not specifically targeted PowerShell when designing the components, and there are some rough edges. We have found following issues so far:

Revision as of 07:33, 7 September 2016

The following PowerShell code reads an OPC item and displays its value:

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")

We have tested this with QuickOPC 5.40 and PowerShell 3.0. Presumably the same concept works with OPC UA (Unified Architecture) too.

For now, consider this just a proof of concept. So far, we have not specifically targeted PowerShell when designing the components, and there are some rough edges. We have found following issues so far:

  1. You need to specify a full path to the QuickOPC assemblies, or copy them over (from Assemblies\net452 folder) to your current directory (this is what we have done for the example code above).
  2. First time the Add-Type is executed, it throws a non-terminating error, indicating a problem loading the assembly. But the execution continues and the read works well. This has to do with the way we have embedded some dependent assemblies, in order to reduce the number of files the developer needs to deal with.

Contact us should you need further help developing a PowerShell solution with QuickOPC.