jhim

System.InvalidOperationException in Server.UpdateValues

Discussion created by jhim on Sep 17, 2014
Latest reply on Sep 19, 2014 by jhim

Hi, I'm helping a partner company programmer on coding issues since he's not able to speak english.

 

Right now he's trying to write a code which gets data from a device called TC-NET made by TMEIC.

 

 

 

The code has a Data Gathering Part which gets data from the source and puts it in a List. The error occurs on the Data Saving part which sends the events in the List to PI. He's using AFSDK 2.6.

 

 

 

The error message is : “System.InvalidOperationException”

 

According to the Engineer, he declared List<AFValue>[] _WRITE_DATA which is an array of AFValue list. The Writing Method is locked and copies the _WRITE_DATA to _FINAL_DATA and then send the events in _FINAL_DATA to PI via For loop. It loops until all the arrays are sent.

 

 

 

                     private void DoWork_Writing()

 

                     {

 

                                lock (lockPIData) //The code below is run once in only one thread

 

                                {

 

                                          lock (lockData) //_WRITE_DATA is shared with data gathering thread so it is locked

 

                                          {

 

                                                     _FINAL_DATA = _WRITE_DATA; //Transfer data <- reading data

 

                                                     _WRITE_DATA = afvaluesList; //array Initialize

 

                                          }

 

                                          for (int i = 0; i < _FINAL_DATA.Length; i++)

 

                                          {

 

                                                     List<AFValue> val = _FINAL_DATA [ i ];

 

                                                     if (val.Count == 0) break;

 

                                                     OSIsoft.AF.AFErrors<AFValue> errors = server.UpdateValues(val, OSIsoft.AF.Data.AFUpdateOption.Insert); //error here!!

 

                                          }

 

                                }

 

                     }

 

 

 

Seems to me, the type of val and UpdateValues required parameter doesn’t match. But I'm not really sure. I need some advice for this code.

 

Asked programmer about additional errors but he couldn’t find anything else. Is there a way I could help him? Any advice would be helpful.

Outcomes