Professional OPC
Development Tools

logos

× If you are developing in .NET, but are using the OPC-UA (OPC Unified Architecture), please post in the QuickOPC-UA category instead.

QUICKopc Client application missing the values and not retaining back

More
09 Feb 2018 07:46 #6010 by support
Dear Sir,

thank you very much. This is very helpful information, and I am finally starting to get reasonable grasp of what is happening.

I understand that your final goal is, of course, to obtain the data whenever possible, and if not, to automatically recover. That's also for what QuickOPC is designed.

At this point, however, I cannot give a recommendation, until you adjust your code and collect a bit more information. There is an essential piece of information missing: That is, the exception (error message etc.) that is causing the failed reads.

It looks like that when coding, you have not understood the principle of how possible problems are reported. Please study the following topics in the documentation (especially the first one):

In other words, it is "normal" that vtqResult.Vtq is sometimes null. Your code should not even get to the point of accessing it. It should *always* test vtqResult.Exception first, and if it is not-null, do something else instead - for example, log the contents of vtqResult.Exception.

Please enhance your code to 1) test vtqResult.Exception, and when not null, do not attempt to access vtqResult.Vtq, and 2) when vtqResult.Exception is not null, log the error message.

By doing so, of course, the problem of not-recovering from the error will not be resolved. But we will finally get an information telling us what kind of error is causing the .Vtq be null. Depending on that, we will decide on further steps.

Based on what you wrote, it is possible that the error will indicate simply a timeout; but it is also possible that sometimes it will indicate something else - and we need to know that. QuickOPC should normally be able to recover when possible, but there are situations (such as repeated failures on part of the OPC server) that prevent it from doing so. We must know all the errors (and especially the first ones) before we can tell more.

Best regards

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

More
09 Feb 2018 02:13 #6008 by SENTHILKUMAR
vtqResults.Vtq is Null

we are getting expected number of Count at vtqResult[] array. the count is equal to the number of OPC tags requested. there is no issue.

we are getting Null value at vtqResults.Vtq.

i am considering the string length of the vtqResults.Vtq. whenever the length of vtqResults.Vtq is less than 30, i am considering the value is not valid. but really observed that, the length of is vtqResults.Vtq Zero.

here we attached three files for your observation. Note that the log files were captured using same application ( same code) shared earlier.

log file 1 and log file 2 is captured in the condition of :

opc server and opc client are in different machines

log file 3 is captured in the condition of :

opc server and opc client are in same machine.

here machine is referred to Computer.

please find below our observations

observation 1:

for your information : we set instance parameter timeout to 30 seconds

easyOPCClient.InstanceParameters.Timeouts.ReadItem = 30000;//set 30 seconds timeout for read item

the program control is not waiting more than 30 seconds. Happiest portion of Quick OPC. the program control is coming out of read multiple item method after 30 seconds. thanks for your proper guidelines and reflects your expertise.

observation 2

the opc client application ( reported here) runs in local machine nor another machine, there is a possibility of vtqResults.Vtq is Null. here submitted the evidence of two log files log file 2 and log file 3. but here good part is , in next cycle, we can expect 100% data in vtqResults.Vtq.

but bad part is not waiting even two seconds ( since we set time out of 30 seconds as mentioned above), simply program control is coming out of the readmultipleitem method and vtqResults.Vtq is giving null value.

observation 3

the maximum timeout we observed is 3 seconds for capturing the data. if its crossed the time interval of 3 seconds, we can confirm there is no data in vtqResults.Vtq. and also in next cycle, the communication is not retaining back sometimes until restart the Application.

so we are planning to reduce the timeout to 10 seconds to avoid data loss. at present situation, we are loosing 1 minute data because of

easyOPCClient.InstanceParameters.Timeouts.ReadItem = 30000;//set 30 seconds timeout for read item

the program control wait for 2 cycles and restarts the application. so we loosing 1 minute data. instead 30 seconds time out we are planning to to reduce to 10 seconds. so we will loose only 20 seconds data only. please confirm is it advisable to reduce the timeout to 10 seconds instead of 30 seconds for reading 1000 tags from OPC Server. the OPC server is running in another computer




observation 4

our worry is the length of vtqResults.Vtq. is null whenever timeout of 30 seconds happens. due to this reason, there is a necessity of application restart which is Not advisable one. until restart , there is no data available in vtqResults.Vtq..

our request is how to retain the application and OPC communication without restart.


as requested we shared the Log files for your observation ,. you can find the timings in the log file

let me know info required.
Attachments:

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

More
08 Feb 2018 12:09 #6006 by support
I apologize, the forums cannot show angle brackets, I try to format the question better now:

Which of the following is the case you have complained about?

1.
vtqResult[i]
is null

or

2. the above is not null, but
vtqResult[i].Vtq
is null.

Thank you

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

More
08 Feb 2018 12:06 #6005 by support
Hello,

thank you for additional information, but I am still missing clear answers to some of my questions. So I will ask them one by one, and demand that you answer that clearly.

Which of the following is the case you have complained about?

1. vtqResult is null

or

2. vtqResult is not null, but vtqResult.Vtq is null.

Thank you

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

More
08 Feb 2018 09:59 - 08 Feb 2018 11:38 #6002 by SENTHILKUMAR
Dear Z,

thanks for your input.

as you mentioned , we had not given the below lines.

EasyDAClient.SharedParameters.Topic.SlowdownWeight = 0.0f;
EasyDAClient.SharedParameters.Topic.SpeedupWeight = 0.0f;

thank you for the parameters bring into picture.

Now we introduced in our code.

i am sure that Vtq is becoming null. because with that reference only i am breaking the for loop and re initiating the entire application. i am waiting for two cycles in the read OPC values module and break the for loop.

please find my code below

static void ReadOPCTagValues()
        {
 
            int count = GloabalVariables.TagCollection.ToArray().Length;
            string[] TagSubArray = GloabalVariables.TagCollection.ToArray();
            DAItemDescriptor[] subarray = new DAItemDescriptor[GloabalVariables.TagCollection.ToArray().Length];
            var ServerDetail = new OpcLabs.EasyOpc.ServerDescriptor();
 
            //var easyOPCClient = new EasyDAClient();
            //EasyDAClient easyOPCClient = new EasyDAClient();
 
 
 
            Console.WriteLine("Variable initialization Completed");
            LogWriter(" OPC Funtion : Varibale initialization completed");
 
 
            try
            {
                for (int i = 0; i < count; i++)
                    subarray[i] = new DAItemDescriptor(TagSubArray[i]);
 
 
 
                Console.WriteLine("Deccriptor creation Completed");
                LogWriter(" OPC Funtion : Deccriptor creation completed");
 
 
                ServerDetail.MachineName = HostName;
                ServerDetail.ObjectId = ServerClass;
                EasyDAClient.SharedParameters.ClientParameters.UseCustomSecurity = false;
            }
            catch(Exception e)
            {
                Console.WriteLine("Deccriptor creation Exception" + e.Message);
                ErrorLogWriter(" OPC Funtion : Deccriptor creation Exception" + e.Message);
            }
            try
            {
 
 
                StreamWriter WriteTagName = new StreamWriter(System.IO.Directory.GetCurrentDirectory().ToString() + @"\TagNamesWithDomain.txt", true);
                WriteTagName.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:fff") + " Start Cycle : " + countCycle.ToString());
 
               // Client. = true;
                Console.WriteLine("OPC Funtion : Trying to connect");
                LogWriter("OPC Funtion : Trying to connect");
 
 
                //iterate over tagarray and create //TagSubArray
                try
                {
                    DAVtqResult[] vtqResults = easyOPCClient.ReadMultipleItems(ServerDetail, subarray);
                    Console.WriteLine("OPC Funtion :OPC Buffer reading Completed with mesage length " + vtqResults.Length);
                    LogWriter("OPC Funtion :OPC Buffer reading Completed with mesage length " + vtqResults.Length);
                    string string1;
 
 
                    for (int i = 0; i < vtqResults.Length; i++)
                    {
                            try
                            {
                                Debug.Assert(vtqResults[i] != null);
                                string1 = Convert.ToString(vtqResults[i].Vtq);
                                Console.WriteLine("Tag index [{0}].Tag Value:{1}", i, vtqResults[i].Vtq);
                                //Console.WriteLine(" lENGTH OF REC MESSAGE : " + string1.Length);
                                LogWriter(Convert.ToString(i) + " " + string1);
 
 
                                if (string1.Length > 30)
                                {
                                    string[] splitString1 = string1.Split(' ');
                                    GloabalVariables.QualityCollection.Add("GOOD");
                                    GloabalVariables.ReadableTags.Add(i);
 
 
                                if (splitString1[1] == "{System.Boolean}")
                                    {
                                        //splitString1[0] = splitString1[0].Substring(0, 1);
                                        if (splitString1[0] == "False")
                                            GloabalVariables.BooleanValueCollection.Add(false);
                                        else
                                            GloabalVariables.BooleanValueCollection.Add(true);
 
                                        // Console.WriteLine(" The Boolean is " + GloabalVariables.BooleanValueCollection[GloabalVariables.BooleanValueCollection.Count-1]);
                                    }
                                    else
                                    {
 
                                        GloabalVariables.DoubleValueCollection.Add(Convert.ToDouble(splitString1[0]));
                                        // Console.WriteLine("the real value is " + RealValue);
                                    }
 
                                    Console.WriteLine(i + ". " + TagSubArray[i] + ": " + splitString1[0]);
                                    WriteTagName.WriteLine(i + ". " + TagSubArray[i] + ": " + splitString1[0]);
 
                                }
                                else
                                {
                                    GloabalVariables.QualityCollection.Add("BAD");
                                    GloabalVariables.ErrorMessageCount++;                                  
 
                                }
 
                            }
                            catch (IndexOutOfRangeException e)
                            {
                               // GloabalVariables.ErrorMessageCount++;
                                Console.WriteLine("Index out of range exception " + TagSubArray[i] + "  " + e.Message);
                                Console.WriteLine("Recived Message : " + vtqResults[i].Vtq + "LENGTH OF MESSAGE = " + vtqResults[i].Vtq.ToString().Length);
                                ErrorLogWriter("OPC Funtion :" + "IndexOutOfRangeException" + e.Message );
                            }
                            catch (OpcException e)
                            {
                               // GloabalVariables.ErrorMessageCount++;
                                Console.WriteLine("OPC exception " + e.Message);
                                ErrorLogWriter("OPC Funtion :" + "OPC Exception" + e.Message);
                            }
 
                            catch (Exception e)
                            {
                              //  GloabalVariables.ErrorMessageCount++;
                                Console.WriteLine(e.Message);
                                ErrorLogWriter("OPC Funtion :" + "General Exception" + e.Message);
                            }
                            finally
                            {
 
                             if (GloabalVariables.ErrorMessageCount > GloabalVariables.TagCollection.Count)
                             {
                                 GloabalVariables.ErrorMessageCount = 0;
                                 GloabalVariables.QualityCollection.Clear();
                                 GloabalVariables.ReadableTags.Clear();
                                 GloabalVariables.BooleanValueCollection.Clear();
                                 GloabalVariables.DoubleValueCollection.Clear();
                                 easyOPCClient.Reset();                                 
                                 easyOPCClient.Isolated = true;
                                 easyOPCClient.InstanceParameters.Timeouts.ReadItem = 30000;//set 20 seconds timeout for read item
                                 easyOPCClient.InstanceParameters.Mode.AllowAsynchronousMethod = false;
                                 easyOPCClient.InstanceParameters.UpdateRates.ReadAutomatic = Timeout.Infinite;
                                 easyOPCClient.InstanceParameters.UpdateRates.WriteAutomatic = Timeout.Infinite;
 
 
                                //clearBuffers();
                                GloabalVariables.ReInitialise = true;                               
 
                             }
 
 
 
                            }         
 
 
 
                    }
                }
                catch (OpcException e)
                {
                    Console.WriteLine("OPC exception " + e.Message);
                    ErrorLogWriter(" Read OPC Value : OPCException" + e.Message);
 
                }
                catch (FileNotFoundException e)
                {
                    Console.WriteLine("OPC exception " + e.Message);
                    ErrorLogWriter(" Read OPC Value : FileNotFoundException" + e.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine("OPC exception " + e.Message);
                    ErrorLogWriter(" Read OPC Value : General Exception" + e.Message);
                }
 
                WriteTagName.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:fff") + " End Cycle :" + countCycle.ToString());
                Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:fff") + "  End Cycle :" + countCycle.ToString());
                Console.WriteLine(" the license of Quick OPC {0}", easyOPCClient.LicenseInfo);
                WriteTagName.Close();
                countCycle++;
               // System.Threading.Thread.Sleep(1300);
 
 
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ErrorLogWriter(" Read OPC Value : General Exception" + e.Message);
 
            }
            finally
            {
 
 
            }
            return;
 
 
 
        }

in the above code, i am counting how many times vtq becomes NULL. if the count is greater than number of parameters to be read from OPC Server, i am enabling the Re-initialization of application itself. usually count (GloabalVariables.ErrorMessageCount) will be greater than No. of parameters (GloabalVariables.TagCollection.Count)

please find below module at if statement
if (GloabalVariables.ErrorMessageCount > GloabalVariables.TagCollection.Count)
                             {
                                 GloabalVariables.ErrorMessageCount = 0;
                                 GloabalVariables.QualityCollection.Clear();
                                 GloabalVariables.ReadableTags.Clear();
                                 GloabalVariables.BooleanValueCollection.Clear();
                                 GloabalVariables.DoubleValueCollection.Clear();
                                 easyOPCClient.Reset();                                 
                                 easyOPCClient.Isolated = true;
                                 easyOPCClient.InstanceParameters.Timeouts.ReadItem = 30000;//set 20 seconds timeout for read item
                                 easyOPCClient.InstanceParameters.Mode.AllowAsynchronousMethod = false;
                                 easyOPCClient.InstanceParameters.UpdateRates.ReadAutomatic = Timeout.Infinite;
                                 easyOPCClient.InstanceParameters.UpdateRates.WriteAutomatic = Timeout.Infinite;
 
 
                                //clearBuffers();
                                GloabalVariables.ReInitialise = true;                               
 
                             } 

using the reinitialize flag ( GloabalVariables.ReInitialise = true ), i am quiting the infinite for loop.

for (; ; )
                    {
                        Timer1 = Environment.TickCount;
                        try
                        {
                            if ((Timer1 - Timer3) > 10000)  //Read every 10 seconds
                            {
                                Console.WriteLine("Waiting for next cycle");
                                Timer3 = Environment.TickCount;
 
                                GloabalVariables.SystemTime = System.DateTime.Now;
                                Console.WriteLine("Start Reading OPC Values");
                                LogWriter("Start Reading OPC Values");
 
                                try
                                {
                                    GloabalVariables.ReInitialise = false;
                                    ReadOPCTagValues();
                                    Console.WriteLine(" Total No of Boolean values tags from DB {0}", GloabalVariables.BooleanValueCollection.Count);
                                    Console.WriteLine(" Total No of Double value tags from DB {0}", GloabalVariables.DoubleValueCollection.Count);
                                    Console.WriteLine(" Total No of Datatype collection from DB {0}", GloabalVariables.DataTypeCollection.Count);
                                    ConnectionStatus();
                                    if (GloabalVariables.ReInitialise == true)
                                    {
                                        break;
                                    }
 
 
 
 
 
                                }
                                catch(OpcException e)
                                {
                                    Console.WriteLine(" OPC Exception while checking Communication : " + e.Message);
                                    LogWriter("OPC Exception while checking Communication :");
                                }
                                catch(Exception e)
                                {
                                    Console.WriteLine(" General Exception while checking Communication : " + e.Message);
                                    LogWriter("General Exception while checking Communication :" + e.Message);
                                }
 
 
 
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                            ErrorLogWriter(" Error at Infinite Loop " + e.Message);
 
                        }
 
                    }


we are reading 1000 tags at 10 seconds interval from another computer connected in Local network.
Last edit: 08 Feb 2018 11:38 by support.

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

More
08 Feb 2018 08:50 #6001 by support
You have not answered my question "Do you get errors? What precisely are they?". Please do so.
You have not sent me the log files I have asked for. Please do so.

Regarding the piece of code where you call easyOPCClient.Reset(), set Isolated = true and some InstanceParameters: You only do it somehow in the middle of communication - that's not the way to do it.
You must set all these parameters right after creating the EasyDAClient, before any actual OPC operation is called. And, you *must not* change them later (the way you are doing now).
If you need a client object with different parameters, you should create a new instance of it, set its parameter right after the creation, and then use it.

Regarding the question about proper timeout settings: There is no advise as to "proper" value of timeouts. It depends on what *you* need, and on the on the actual speed of the communications etc. Are you actually getting some timeout errors?

Regarding the "vtqResults is an array of null" issue: That is somewhat hard to believe. Are you absolutely sure that, for example, vtqResult[0] is actually null?
Isn't it so that vtqResult[0] is not null, but then vtqResult[0].Vtq is null? That is a very important distinction. Please re-check and let me know. I can see that you have following line in your code:
Debug.Assert(vtqResults[i] != null);
Are you saying that when you run it, you sometimes get a debugging assert on this line?

Regarding the hang up issue: I do not know at the moment what can be causing it, but frankly, I think we first need to clarify what is actually happening, because the information from your side is very incomplete and confusing. Let's focus on the issue with "vtqResults are null" primarily.
I have noticed that you have used (part of) the suggestions from this forum article: www.opclabs.com/forum/reading-writing-subscriptions-property...scriptions-made-with-opc-reads .
But from the pieces of code you have provided, I can only verify that you have included the second half of it - that is,
target.InstanceParameters.UpdateRates.ReadAutomatic = Timeout.Infinite;
            target.InstanceParameters.UpdateRates.WriteAutomatic = Timeout.Infinite;
Can you uplease confirm that you have also the following in your code:
EasyDAClient.SharedParameters.Topic.SlowdownWeight = 0.0f;
            EasyDAClient.SharedParameters.Topic.SpeedupWeight = 0.0f;
That should be done *before* any EasyDAClient object is created - it just manipulates its static properties. Or, if you do not have these lines there, please do so, and re-test.

I should also note that using periodic reads in OPC is strongly discouraged; in most cases, the correct way of obtaining data continuously is using subscriptions.

Regards

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

More
08 Feb 2018 08:16 #5998 by support
Dear Sir, we will reply to you on our schedule.

Please stop flooding the forum and email with posts that have no new information in it. If you do not, I will block you from the communication.

Yours sincerely
Zbynek

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

More
08 Feb 2018 08:03 #5997 by SENTHILKUMAR
Dear Z,

any updates on the issue?
How to fix it?

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

More
08 Feb 2018 04:28 #5995 by SENTHILKUMAR
Dear Team, any update on our issue. let us know. if any info required from our end, please post it. we are in trouble because of this issue

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

More
08 Feb 2018 01:11 #5994 by SENTHILKUMAR
please let us know other info required from our end to get the reason why vtqresult becomes null?
how to resolve the issue?

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

Moderators: support
Time to create page: 0.262 seconds

      

 Recommend this on Google