Industry Online Support
Technical Forum
6/14/2011 12:04 AM | |
Posts: 1 Rating: (0) |
Hello, Thank you for an example from what I can see you are creating: Private array_length(0) As Integer Private array_lowerbound(0) As Integer then you set them to some value: array_length(0) = 2 array_lowerbound(0) = 1 and then you create the Arrays that then are passed to for example addItems: Dim ItemClientHandles As Array ItemClientHandles = Array.CreateInstance(Type.GetType("System.Int32"), array_length, array_lowerbound) The problem with that is when I try to do array_length(0) = 2 i get error saying: "Index was outside the bounds of the array." Which makes sense because I create array with zero elements so I cannot write to the first element??? Please could you explain to me how did you manage to achive that, I am really strugguling and needs to get this working. (ps I am having the same problem as person on the first post) My translated to c#: int[] array_lowerbound = new int[0]; int[] array_length = new int[0]; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int count = 2; array_lowerbound[0] = 1; array_length[0] = 2; Array ArrayErrors = Array.CreateInstance(typeof(System.Int32), array_length, array_lowerbound); Array ClientHandles = Array.CreateInstance(typeof(System.Int32), array_length, array_lowerbound); Array ServerHandles = Array.CreateInstance(typeof(System.Int32), array_length, array_lowerbound); Array OPCTags = Array.CreateInstance(typeof(System.String), array_length, array_lowerbound); //Talking to OPC server OPCServer MyOPCServer = new OPCServer(); String ConnectedServerName = "ICONICS.Simulator.1"; MyOPCServer.Connect(ConnectedServerName); OPCGroups MyServerGroups = MyOPCServer.OPCGroups; MyServerGroups.DefaultGroupIsActive = true; MyServerGroups.DefaultGroupDeadband = 0; String MyGroupName = "MyDataGroup"; OPCGroup MyOPCGroup = MyServerGroups.Add(MyGroupName); MyOPCGroup.UpdateRate = 1000; OPCTags.SetValue("SimulatePLC.INPUTS.Int Random",0); ClientHandles.SetValue(0, 0); OPCTags.SetValue("SimulatePLC.INPUTS.Int Sin", 1); ClientHandles.SetValue(1, 1); OPCItems MyOPCItemCollection = MyOPCGroup.OPCItems; MyOPCItemCollection.DefaultIsActive = true; int numberOfItem = 2; //MyOPCItemCollection.Validate(numberOfItem, ref OPCTags, out ArrayErrors); MyOPCItemCollection.AddItems(numberOfItem, OPCTags, ClientHandles, out ServerHandles, out ArrayErrors); Array Values; Values = new int[2]; object Timestamp; object Quality; MyOPCGroup.SyncRead(2, 2, ServerHandles, out Values, out ArrayErrors, out Quality, out Timestamp); Splitted from S7 200, OPC & C#. |
Last edited by: O_Moderator at: 6/14/2011 11:26 AMnew subject after splitting |
|
12/13/2011 10:29 AM | |
Joined: 1/26/2011 Last visit: 11/12/2024 Posts: 243 Rating: (67) |
Hi ToolTips, i you need some help to use arrays look at the link below. http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx help for Visual Basic http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx help for C# i hope this will help you... nice greetings bigfoot |
Follow us on