Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

C# Read Array of strings or numbers

More
15 May 2019 05:34 #7365 by jomyver
Check this detailed tutorial on... C# Array

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

More
14 Jun 2013 18:09 #1339 by support
What makes you think that anything is wrong? What is the output of your program? If it only prints out the type name of the array, then it is because the .ToString() method does behave this way on arrays - it does not return the string of individual elements.

Generally, to work with readings that are arrays, you usually need to type-cast them to the type they are, such as

var myArray = (string[])spectra;
Debug.WriteLine(myArray[0]);

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

More
13 Jun 2013 01:55 #1335 by Ben_FA
Hi,

You are only getting a single value back because spectra object hasn't been declared are an array.

I've attached a VB.Net example it shouldn't be difficult to convert this to C#

Console.WriteLine("Reading array value...")
Dim value As Object() = client.ReadItemValue("", "OPCLabs.KitServer.2",
"Simulation.Register_ArrayOfI2")
Console.WriteLine(value(0))
Console.WriteLine(value(1))
Console.WriteLine(value(2))
Console.WriteLine("Press Enter to continue...")

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

More
12 Jun 2013 13:40 #1334 by trobalo
Hello,

I'm trying to read an array of strings or number using C#, but at this moment I'm only successful read single values.
var client = new EasyDAClient();
 
object spectra = client.ReadItemValue("127.0.0.1", "Matrikon.OPC.Simulation.1", "Random.ArrayOfString");
 
System.Diagnostics.Debug.WriteLine(spectra.ToString());

Who can help me with this?

Thanks in advance!

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

Moderators: support
Time to create page: 0.056 seconds