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

From OPC Labs Knowledge Base
Jump to navigation Jump to search
Line 18: Line 18:
 
# 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).  
 
# 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).  
 
# 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.
 
# 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.
 +
 +
{{Template:Note|This second problem should be possible to resolve in QuickOPC 2016.2 or later. Select the custom installation option on the setup dashboard, use the "Typical installation (COM)" install type, and then make sure you check "Embedded assemblies" in the list of the installation components.}}
  
 
Contact us should you need further help developing a PowerShell solution with QuickOPC.
 
Contact us should you need further help developing a PowerShell solution with QuickOPC.

Revision as of 12:43, 9 October 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.
Note2-icon.png

Note: This second problem should be possible to resolve in QuickOPC 2016.2 or later. Select the custom installation option on the setup dashboard, use the "Typical installation (COM)" install type, and then make sure you check "Embedded assemblies" in the list of the installation components.

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


Links related to/used when writing this article: