Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

OPC DA item with an access path

More
17 Mar 2025 21:01 #13473 by wvklemov
I am looking for some example python code to read an OPC DA item with an access path.  I have installed QuickOPC, python.net, my OPC DA server is running and accessible.  The sample I found looks like this and returns the error: No method matches given arguments for DAItemDescriptor..ctor: (<class 'str'>, <class 'str'>)import clr  # From pythonnet, allows access to .NET assemblies
import sys# Add reference to QuickOPC .NET assembly
# Adjust the path based on where QuickOPC is installed on your systemsys.path.append(r"C:\Program Files (x86)\OPC Labs QuickOPC 2023.2\Assemblies\net472")
clr.AddReference("OpcLabs.EasyOpcClassic")# Import QuickOPC namespaces
from OpcLabs.EasyOpc.DataAccess import EasyDAClient, DAItemDescriptordef read_opc_item():    # Create an instance of the EasyDAClient    client = EasyDAClient()    try:        # Define server, ItemID, and access path        server_name = "Matrikon.OPC.Simulation"  # Replace with your server's ProgID
        item_id = "Random.Int4"                  # Example ItemID (server-specific)
        access_path = "SimulatedData"            # Example access path (server-specific)        # Create a DAItemDescriptor with ItemID and access path
        item_descriptor = DAItemDescriptor(item_id, access_path)        # Read the item from the OPC server
        result = client.ReadItem("", server_name, item_descriptor)        # Check if the read was successful and display the result
        if result.Exception is None:
            print(f"Value: {result.Value}")            print(f"Timestamp: {result.Timestamp}")
            print(f"Quality: {result.Quality}")        else:            print(f"Error reading item: {result.Exception.Message}")
    except Exception as ex:        print(f"An error occurred: {str(ex)}")if __name__ == "__main__":    read_opc_item()

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.180 seconds