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.

ReadItemValue is working very slowly

More
16 Jan 2016 06:37 #3771 by support
Thanks for letting me know. BTW, ReadItem (as opposed to ReadItemValue) also does not wait for a "Good" quality.
The following user(s) said Thank You: mikeboiko

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

More
15 Jan 2016 22:59 #3769 by mikeboiko
Hi, sorry about the late reply but I just wanted to say thank you for the help.

In the end, the problem was that the quality of the tag I was trying to read was uncertain. So, instead of using .ReadItemValue, I ended up using .GetPropertyValue and pulling Property 2, which is value. This way I didn't have to wait for the quality to be good before reading the value.

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

More
18 Nov 2015 07:37 #3685 by support
Alright, I think I have now a better understanding of what is happening. It is a combination of two things, and both of them have to do with the initial connection to the server. Unfortunately, you have initially written that the problem does *not* happen with the ReadItem method, which I think, after reading your last post, was not correct. I believe that without being connected upfront, the time to execute an *initial* ReadItem would be around 8-10 seconds as well.

Here is what I think is happening:

Step 1. An initial connection to the server requires 8-10 seconds (taken by the server)
Step 2. A time from the moment of the initial connection to the first "good" quality takes additional 8-10 seconds (taken by the server).

QuickOPC maintains the connections automatically. If not connected, the connection has to be made first. Therefore both methods (ReadItem and ReadItemValue) require at least the Step 1 delay; the ReadItemValue then also requires the Step 2 delay.

The initial delays are cause by the server and therefore *must* happen at some time. The only optimization that can be done is to avoid disconnections from the server, so that they are not required over and over.

One way to go is to enforce the connection - which is what you have done by using the Subscribe. Note that you have not really avoided the initial delay - that is impossible, you now have it between the SubscribeItem call and the first DataChange notification - but made it more suitable for your app. You do not need three EasyDAClient objects for this - it can be done with just one.

Other method (probably not so good in your case) is to significantly increase the HoldPeriod, which is for how long the client keeps the connection to the server open after it has been used. Normally it is just a couple of seconds, but you can make it e.g. 1 day or so or even more. This will get rid of the delay in case of second and third etc. Reads, but the first Read will still require the delay as before.

For some applications, it is also possible to *shorten* the timeout for Read methods (possibly combined with the previous method). Then, the first Read will simply timeout very quickly, but still initiate a connection. You can set the timeout e.g. to 1 second only. If you can handle the timeout by ignoring it or showing that the value is momentarily unavailable, and then come to do the same thing later, you would prevent what you call "freeze". The Read method won't take more than the configured timeout.

Best regards
The following user(s) said Thank You: mikeboiko

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

More
17 Nov 2015 23:54 #3682 by mikeboiko
Hi, I tried this new method and the read time was steady at 8s. However, I think I figured out a solution:

//First I subscribe to the OPC tag
daClient1.SubscribeItem(machine, server, tag_pv, 500);

//After the subscription is complete (7-20s) I read the values with ReadItemValue command
pv_value = Convert.ToSingle(daClient.ReadItemValue(machine, server, tag_pv));

The reason I prefer to use ".SubscribeItem" before ".ReadItemValue" is that my application doesn't freeze up and the user is able to select other parameters while the OPC connection is established in the background. I would only perform a read using ".ReadItemValue" instead of the "daClient1_ItemChanged" event if the OPC tag is staying constant and I need to get its value.

I have 3 tags (PV, MV and SV) that I need to read/write from. Do you think it would be ok for me to create 3 EasyDACLients and subscribe to them all in order for my reads not to cause any lag/freezing in the application?

If you can suggest any other more-efficient methods in order to get rid of the application freezing the first time I read a value, please do so.

Thanks,
Mike

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

More
17 Nov 2015 07:56 #3680 by support
Yes. As I explained, the ReadItemValue method waits until the value becomes "Good", by using a subscription. The subscription is initially relatively slow (10 seconds). Try to make it faster e.g. like this:
var target = new EasyDAClient();
target.InstanceParameters.UpdateRates.ReadAutomatic = 1000;
Best regards

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

More
17 Nov 2015 03:19 #3678 by mikeboiko
I tried both methods (DeviceSource and CacheSource) and the read action was slightly faster but still took about 8s. When I subscribe and read on change, both actions take less that 1s to perform.

Do you have any other ideas to speed up the read?

Thanks a lot!

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

More
03 Nov 2015 09:11 #3636 by support
In order to change the data source, modify your last line to read e.g.:
pv_value_ini = Convert.ToSingle(client.ReadItemValue(
         new ServerDescriptor(machine, server), tag_pv, DAReadParameters.DeviceSource));

And, try a .CacheSource as well.

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

More
02 Nov 2015 23:45 #3635 by mikeboiko
//I declare my variables
string machine = "HIS0164";
string server = "Yokogawa.CSHIS_OPC.1";
string tag_pv = "FCS0101!FIC100.PV";

//In another function, I read from OPC and there's a 20s delay
pv_value_ini = Convert.ToSingle(daClient.ReadItemValue(machine, server, tag_pv));

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

More
23 Oct 2015 08:36 #3623 by support
Please post the piece of your code that does the read, and I will respond with a corresponding modification.

Best regards

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

More
22 Oct 2015 01:03 #3622 by mikeboiko
Thank you for the reply. I tried the code you provided, but it does not work for my scenario because the OPC server I'm connecting to is on another machine. I couldn't figure out how to make this code work for remote OPC server connections. Any other ideas?

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

Moderators: support
Time to create page: 0.086 seconds