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.

Best approach to process returned values

More
14 Mar 2012 07:57 #797 by support
Hello.
Even with relatively small number of items, I would definitely recommend to subscribe to all items at once (prepare the arguments upfront, and then call SubscribeMultipleItems). There are performance problems when doing it one by one. The events that get generated afterwards are the same as if you had used SubscribeItem individually.
With small number of items as yours, you can (in the ItemChanged event handler) test ItemDescriptor.ItemId sequentially against specific known values, as you have suggested. For effective code in larger applications, there are different approaches, making use of the State argument (property). This is an arbitrary object that you pass to the component when making a subscription to an OPC item, and that you receive with each event notification related to that item. This can be used to various things; in the HmiScreen example, we pass in the reference to control to be updated, and when the item changes, we can directly update that control. Other uses might be e.g. to pass in a delegate to a method that would process that particular OPC item, or a PropertyInfo obtained by reflection and determining which property needs to be set.
DAVtq.DisplayValue() returns a string. The string contains the value (if available), together with timestamp and quality informayion, all expressed in one string. If you have typed properties (not just strings), you may consider typecasting DAVtq.Value to an appropriate type instead; in this case, you need to be aware that in some cases (e.g. Bad quality), the Value may not be available and is a null reference.
If you decide to do reading (as opposed to subscriptions), you can either use the fact that arguments in the output array of ReadMultipleItem[Value]s have the same indices as input arguments, or you can also use the State property - see e.g. www.opclabs.com/Support/Online... .
Best regards,

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

More
14 Mar 2012 07:39 #796 by support
Zbynek

<span lang="EN-GB" style="font-family: "Arial","sans-serif"; color: #1f497d; font-size: 12pt; mso-ansi-language: EN-GB">I have at last got round to evaluating your software on my application. I have a requirement to read approximately 25 values (Some integers, some real and a few Booleans) from a Siemens OPC Server that resides on the same PC as my app. I have already managed to communicate with it using your software but I have a question concerning what you consider to be best practice in moving forward from where I am now.
<span lang="EN-GB" style="font-family: "Arial","sans-serif"; color: #1f497d; font-size: 12pt; mso-ansi-language: EN-GB">
<span lang="EN-GB" style="font-family: "Arial","sans-serif"; color: #1f497d; font-size: 12pt; mso-ansi-language: EN-GB">I have looked at the EasyOPCNetDemo and the SubscribeToMany examples and can see how they work. In my case, I simply want to store the returned values in some local fields and make them available to other classes in my app by exposing them as properties.
<span lang="EN-GB" style="font-family: "Arial","sans-serif"; color: #1f497d; font-size: 12pt; mso-ansi-language: EN-GB">
<span lang="EN-GB" style="font-family: "Arial","sans-serif"; color: #376092; font-size: 12pt; mso-ansi-language: EN-GB">What is the best approach to subscribe to and read the values? Should I follow the SubscribeToMany example or the EasyOPCNetDemo? I was considering using a switch statement on the ItemDescriptor.ItemId value returned and then transferring the e.Vtq.DisplayValue() to the appropriate field value – is there a better way?



Regards

<span lang="EN-GB" style="font-family: "Calibri","sans-serif"; color: #1f497d; font-size: 11pt; mso-ansi-language: EN-GB; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">P.

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

Moderators: support
Time to create page: 0.042 seconds