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.

Setting DataSource when reading values through Python

More
20 Feb 2024 17:38 #12559 by support
Examples for OPC client and subscriber development in Python are now on GitHub: github.com/OPCLabs/Examples-QuickOPC-Python .

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

More
21 Nov 2023 13:42 #12406 by support
Note: QuickOPC now supports Python in much better way, cleaner syntax, and public packages (pypi.org/project/opclabs-quickopc/) on Python Package Index . See What's new in QuickOPC 2023.2 for more information. And, over 270 examples are available in the User's Guide!

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

More
29 Mar 2016 09:37 #3961 by support
We have many overloads in the .NET API that allow you to easily specify such things without extra coding, but unfortunately COM does not support function overloading, so without polluting the interface with many different functions, we had to select just one overload for each method name. As a result, in COM, we typically have one method that is very simple to use, with minimal arguments, and then a corresponding method that is more complicated to use, but provides all functionality that we have.

In your case, ReadItemValue is the "simple" method, and there is no way to pass it the DAReadParameters in our COM API. But you can switch to the ReadMultipleItemValues method, and that one should allow you to achieve what you want. I do not have an example ready for you, but in essence, you should do the following:

1. Create an instance of DAReadItemArguments object.

2. Set its properties: It has ServerDescriptor and ItemDescriptor properties under which you set what you want to read (in your example, .ServerDescriptor.ServerClass and .ItemDescriptor.ItemId would suffice). And, it has .ReadParameters property as well: There you can set e.g. .ReadParameters.DataSource, .ReadParameters.ValueAge.

3. Create an array with items to read: In this case, an array with one element - and set that element to your DAReadItemArguments object. I am not sure whether you will be able to use some standard Python array, or whether you need to somehow instantiate COM SafeArray-s: that's a Python<->COM binding thing and we are not experts in it here. Hopefulyl it will be possible to pass in the array somehow.

4. Call ReadMultipleItemValue on the EasyDAClient object, passing it the array you created above.

5. You will receive back an array with one element, of type _ValueResult. Test .Exception of that element for null-ness to see if there was an error; if not, the actual value read is in the .Value.


Best regards
ZZ

Note: Values for .DataSource are an enumeration, but some languages (Python?) will need to use an integer. Here is the encoding:


 
    public enum DADataSource
    {
        /// <summary>The data source (memory, OPC cache or OPC device) selection will be based on the desired value age and 
        /// current status of data received from the server.</summary>
        ByValueAge = 0 /*OCK_DS_BY_VALUE_AGE*/,
 
        /// <summary>OPC reads will be fulfilled from the cache in the OPC server.</summary>
        /// <remarks>Corresponds to OPC_DS_CACHE in the OPC specification.</remarks>
        Cache = 1,
 
        /// <summary>OPC reads will be fulfilled from the device by the OPC server.</summary>
        /// <remarks>Corresponds to OPC_DS_DEVICE in the OPC specification.</remarks>
        Device = 2,
    }

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

More
26 Mar 2016 23:05 #3959 by jihaekor
Hello,

I was looking for a way to set the datasource to 'device' using a Python implementation of QuickOPC, but I could not find a good way of getting this to work even after searching through the documentation. I see that there is a DAReadParameters class, but I was unable to figure out how to use the class through the Python COM implementation.

Below is a quick excerpt of the code that I have:
import win32com.client
c = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient')
r03 = c.ReadItemValue('', 'Kepware.KEPServerEX.V5', 'ChannelR-30iBMate.DeviceR-30iBMate.R03')

I was hoping to either add arguments to the dispatched client, or to the ReadItemValue function to achieve this. Is this something that can be done?

Thanks,
John

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

More
26 Mar 2016 22:56 #3958 by jihaekor
Hello,

I was looking for a way to set the datasource to 'device' using a Python implementation of QuickOPC, but I could not find a good way of getting this to work even after searching through the documentation. I see that there is a DAReadParameters class, but I was unable to figure out how to use the class through the Python COM implementation.

Below is a quick excerpt of the code that I have:
import win32com.client
c = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient')
r03 = c.ReadItemValue('', 'Kepware.KEPServerEX.V5', 'ChannelR-30iBMate.DeviceR-30iBMate.R03')

I was hoping to either add arguments to the dispatched client, or to the ReadItemValue function to achieve this. Is this something that can be done?

Thanks,
John

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

Moderators: support
Time to create page: 0.061 seconds