Paul Samek

Paul Samek

  • NA
  • 1
  • 0

System.Array and String[]

Mar 17 2007 2:32 PM
Hi, I have ( OPC – server /communication with PLC/ ) it based on COM (DCOM) object. Unfortunately manual is written only for VB. And I don’t know how to convert for C#. My problem start when I try use Array. It is original code: -------------------- Dim ItemIDs(2) As String Dim ItemClientHandles(2) As Long Dim Errors() As Long ' Array for returned Item related errors Set MyItems = MyGroup.OPCItems ' Get OPCItems Collection Object from MyOPCServer ' Initialize the [IN] parameters for the Add Items call ' ItemIDs -> ItemIDs of the Items to add ' ItemClientHandles -> Client defined handles for the Items. The Server sends these handles in the Callbacks ItemIDs(1) = txtItem1.Text ' Read ItemId 1 from Text Box ItemIDs(2) = txtItem2.Text ' Read ItemId 2 from Text Box ItemClientHandles(1) = 1 ItemClientHandles(2) = 2 ' [OUT] parameters are ' ItemServerHandles -> Server defined handles for the Items. The client must use ' these handles for all Read/Write calls ' Errors -> Item related errors ' Add Items to the Group Call MyItems.AddItems(2, ItemIDs, ItemClientHandles, MyItemServerHandles, Errors) My code ------- OPCItems ItemsObj; ItemsObj = opGoup.OPCItems; string[] ItemString = new string[2]{ "2,VW100,WORDL", "2,VB200,BYTE" }; int[] ItemClientHandles = new int[2] {1,2}; int[] ItemServerHandles = new int[2]; int[] Error = new int[2]; //I must used because compiler wrote: //“Argument '2': cannot convert from 'ref string[]' to 'ref System.Array'” //(all of array) Array aStr = ItemString; Array aCli = ItemClientHandles; Array aSer = ItemServerHandles; Array aErr = Error; ItemsObj.AddItems(ItemString.Length, ref aStr, ref aCli, out aSer, out aErr, null, null); Definition function: void AddItems(int NumItems, ref System.Array ItemIDs, ref System.Array ClientHandles, out System.Array ServerHandles, out System.Array Errors, object RequestedDataTypes, object AccessPaths) {Member of OPCSiemensDAAutomation.OPCItems} Argument 5 and 6 is optional. When program run AddItems that aSer, aErr is NULL and this result is wrong.

Answers (1)