Get OPC data into Perl
How does QuickOPC allow integration of OPC data into Perl?
- QuickOPC provides COM (OLE Automation) objects with easy interfaces to perform all kinds of OPC tasks
- You instantiate one of the main QuickOPC objects.
- You call methods that perform operations such as OPC reading or writing.
OPC Perl ExampleIf you want see it for yourself, we have an example that shows how to read a value of an OPC item in Perl and print it out. It is just a few lines of code, and for OPC Data Access server, it looks like this:
# Create EasyOPC-DA component $client = Win32::OLE->new("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
# Read item value and display it print $client->ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Single");
The example connects to Simulation OPC Server, but you can quickly modify it to connect to your OPC server instead. Simply download the product and then open the project.
It is also possible to subscribe to OPC item changes in Perl. We have tested this example with ActivePerl v5.14.2.
With an OPC Unified Architecture (OPC UA), the code is just as simple:
use Win32::OLE; # Create EasyOPC-UA component $client = Win32::OLE->new("OpcLabs.EasyOpc.UA.EasyUAClient"); # Read node value and display it print $client->ReadValue("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853");
Footnote & required disclosure: QuickOPC (including its Options) is a software development kit (SDK) for development of OPC clients. Installing QuickOPC or its Options does not change system settings.