Probelm ath AddItems() and array size/lowerbound|Miscellaneous|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Probelm ath AddItems() and array size/lowerbound
Avatar
Stephen Blake
New Member
Members
Forum Posts: 1
Member Since:
04/01/2018
sp_UserOfflineSmall Offline
1
04/01/2018 - 09:01
sp_Permalink sp_Print

Hi,

I'm using OPCDAAuto.dll in a Wonderware Archestra system to try to write to the FSGateway OPC server.

In the code I can connect to the server and I can add a group and loop through a few additem calls and write values to the items.

I want to use the AddItems() method to add many items and then syncwrite to them but the AddItems() method is failing on me. If I setup my arrays in the code to have 10 items and try to add the 10 items with AddItems() I get the following error which I believe indicates that my arrays are not the correct length?

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Plant_Blend1.Button10: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Value does not fall within the expected range.
at OPCAutomation.OPCItems.AddItems(Int32 NumItems, String[]& ItemIDs, Int32[]& ClientHandles, Int32[]& ServerHandles, Int32[]& Errors, Object RequestedDataTypes, Object AccessPaths)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at ArchestrA.QuickScript.EvaluateFunction.Evaluate(IReferenceManagerRuntime rmr)
at ArchestrA.QuickScript.RunExpressionStatement.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunStatements.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunTryCatch.Run(RuntimeContext context)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

If I use the same script with arrays of 10 items but just add 9 items with the AddItems() method then 9 items are added to the group starting from item 2 and I get the following error.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Plant_Blend1.Button9: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.SafeArrayRankMismatchException: SafeArray cannot be marshaled to this array type because it has either nonzero lower bounds or more than one dimension.
at System.StubHelpers.MngdSafeArrayMarshaler.ConvertSpaceToManaged(IntPtr pMarshalState, Object& pManagedHome, IntPtr pNativeHome)
at OPCAutomation.OPCItems.AddItems(Int32 NumItems, String[]& ItemIDs, Int32[]& ClientHandles, Int32[]& ServerHandles, Int32[]& Errors, Object RequestedDataTypes, Object AccessPaths)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at ArchestrA.QuickScript.EvaluateFunction.Evaluate(IReferenceManagerRuntime rmr)
at ArchestrA.QuickScript.RunExpressionStatement.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunStatements.Run(RuntimeContext context)
at ArchestrA.QuickScript.RunTryCatch.Run(RuntimeContext context)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I am able to use the AddItems() method without any issue using Excel VBA but not from within the Archestra scripting.

Any help would be greatly appreciated.

The code in Archestra is as follows

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

dim myServer as OPCAutomation.OPCServerClass;
Dim myGroups As OPCAutomation.IOPCGroups;
Dim myGroup As OPCAutomation.IOPCGroup;
Dim myItems As OPCAutomation.OPCItems;
dim n as integer;
dim myServers as System.Array;
dim szServerName as string;

Dim ClientHandles[10] as System.Int32;
Dim OPCItemIDs[10] As System.String;
Dim ItemServerHandles[10] as System.Int32;
Dim ItemServerErrors[10] as System.Int32;
dim ItemPath[10] as System.String;
dim ItemType[10] as System.Int16;
dim ItemVal[10] as System.object;
dim szAddress as string;

myServer = new OPCAutomation.OPCServer();
myServers=myServer.GetOPCServers();
for n = myServers.GetLowerBound(0) to myservers.GetUpperBound(0)
if StringInString(myServers.GetValue(n),"FSGate",1,false) then
szServerName=myServers.GetValue(n);
exit for;
endif;
next;
myServer.Connect(szServerName, "");
myGroups = myServer.OPCGroups;
myGroup = myGroups.Add("Add10");
myGroup.UpdateRate= 5000;
myItems = myGroup.OPCItems;
myGroup.IsActive=true;
myGroup.IsSubscribed=true;

for n = 1 to 10
szAddress="PLC1.Batch.P01P15.CPU1.ZR" + text(80000 + n,"00000");
ClientHandles[n]=n;
OPCItemIDs[n]= szAddress;
ItemVal[n]=n+10;
ItemPath[n]="";
ItemType[n]=2;
next;
'Log to SMC for debugging purposes
Utilities1.DEBUGText = "OPCConnect - AddItems10 Before";
try
myItems.AddItems(10,OPCItemIDs[],ClientHandles[],ItemServerHandles[],ItemServerErrors[],ItemType[],ItemPath[]);
catch
LogMessage(error);
endtry;
'Log to SMC for debugging purposes
Utilities1.DEBUGText = "OPCConnect - AddItems10 After";

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 34
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1395
Posts: 4715