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.

Reading Multiple values. Wrong data ?

More
23 Oct 2014 12:02 #2465 by Dirk
Hi There,

I got it to work. The code i had submitted are only parts so the code i have does compile.

The real confusion was in the line :

String ItemName = "S7:[S7_Connection_1].DB101" + ",WORD" + i.ToString();

it has to be :

String ItemName = "S7:[S7_Connection_1]DB101" + ",WORD" + i.ToString();

There is no dot between the connection name and the item. All works now. Thanks

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

More
21 Oct 2014 15:55 - 21 Oct 2014 15:56 #2463 by support
The code you provided does not have a declaration of the 'tags' variable, but I think it won't compile anyway, because either 'tags' is an array and then it would be impossible to assign a DAItemDescriptor to it, or it is a single object and then it would be impossible to use it as a second argument of ReadMultipleItems.

Also, "" is almost certainly not a server ProgID, therefore you should not place it into the ServerDescriptor. It looks like a part of your item name (I have seen similar names with Siemens servers, but do not know the precise syntax).

Anyway, I tried to guess what you wanted to do, and I came with the following code:

var easyDAClient1 = new EasyDAClient();
DAItemDescriptor[] tags = new DAItemDescriptor[5];
 
// You need to put in the proper *server* identification to the line below. 
OpcLabs.EasyOpc.ServerDescriptor Server = new OpcLabs.EasyOpc.ServerDescriptor("", "<here comes the ProgID of the server>");
 
for (int i = 0; i < 5; i++)
{
    // Not sure about the item syntax below - it depends on your server, you need to figure it e.g. by browsing it.
    String ItemName = "S7:[S7_Connection_1].DB101" + ",WORD" + i.ToString();
    tags[i] = new DAItemDescriptor(ItemName);
}
 
easyDAClient1.InstanceParameters.UpdateRates.ReadAutomatic = System.Threading.Timeout.Infinite;
DAVtqResult[] vtqResults = easyDAClient1.ReadMultipleItems(Server, tags);
 
for (int i = 0; i < 5; i++)
{
    listBox1.Items.Add(vtqResults.ToString());
}
 
 
for (int i = 0; i < 5; i++)
{
    // Not sure about the item syntax below - it depends on your server, you need to figure it e.g. by browsing it.
    String ItemName = "S7:[S7_Connection_1].DB101" + ",WORD" + i.ToString();
    tags[i] = new DAItemDescriptor(ItemName);
}
 
easyDAClient1.InstanceParameters.UpdateRates.ReadAutomatic = System.Threading.Timeout.Infinite;
DAVtqResult[] vtqResults = easyDAClient1.ReadMultipleItems(Server, tags);
 
for (int i = 0; i < 5; i++)
{
    listBox1.Items.Add(vtqResults.ToString());
}

Best regards
Last edit: 21 Oct 2014 15:56 by support.

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

More
21 Oct 2014 13:54 - 21 Oct 2014 13:59 #2462 by Dirk
Hi,

I have adjusted my code to:

OpcLabs.EasyOpc.ServerDescriptor Server = new OpcLabs.EasyOpc.ServerDescriptor("", "S7:[S7_Connection_1]");

for (int i = 0; i < 5; i++)
{
String ItemName ="DB101" + ",WORD" + i.ToString();
tags= new DAItemDescriptor(ItemName);
}

easyDAClient1.InstanceParameters.UpdateRates.ReadAutomatic = System.Threading.Timeout.Infinite;
DAVtqResult[] vtqResults = easyDAClient1.ReadMultipleItems(Server,tags);

for (int i = 0; i < 5; i++)
{
listBox1.Items.Add(vtqResults.ToString());
}


I get : [0] = {*** Failure -2147221005 (0x800401F3): Ongeldige klassereeks }

Is my DataItemDescriptor declaration wrong ? In need to read a DBBLOCK WORD and not a Tag.
Last edit: 21 Oct 2014 13:59 by Dirk.

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

More
15 Oct 2014 16:06 #2440 by support
There are some things they do not seem correct.

First, for reading, you should use ReadMultipleItemValues method. The use of OPC properties is very inefficient, and has other disadvantages as well. It is true that the value can be accessed as a property as well, but that should avoided unless there is a specific need for it.

Second, your code, as presented, does not compile: "ItemDesecriptors" is declared as an array of DAPropertyArguments, but assigning a single DAPropertyObjects object to it inside each loop gives a "Cannot convert...." compiler error. Unless I am missing something, please rather send the actual code so that my reasoning can be valid.

Third, assuming that "somehow" this compiles, assigning into ItemDescriptors inside each loop will overwrite its value - it shoud instead place the value into appropriate element inside the array.

I do not have an example of ReadMultipleItemValues right at hand, but I have one that uses ReadMultipleItems (which is even better because it gives you back data qualities and timestamps). Here it is, maybe it helps:
            public static void Main()
            {
                var easyDAClient = new EasyDAClient();
 
                DAVtqResult[] vtqResults = easyDAClient.ReadMultipleItems("OPCLabs.KitServer.2", 
                    new DAItemDescriptor[] { "Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4" });
 
                for (int i = 0; i < vtqResults.Length; i++)
                {
                    Debug.Assert(vtqResults[i] != null);
                    Console.WriteLine("vtqResult[{0}].Vtq: {1}", i, vtqResults[i].Vtq);
                }
            }
 
If you still would not be able to put it together, let me know and I will try to write that piece for you.

Best regards

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

More
15 Oct 2014 15:08 #2437 by Dirk
I need to read 4 DBblocks each conataining 5 integer values from an S5. The data seems tow be WORD oriented.

OpcLabs.BaseLib.ValueResult[] Vals;
DAPropertyArguments[] ItemDescriptors = new DAPropertyArguments[20];


I use for (int i = 0; i < 5; i++)
{
String ItemName = ConnectionName + "DB101" + ",WORD" + i.ToString();
ItemDescriptors = new DAPropertyArguments(OPCHostName, OPCServer, ItemName, 2);

}

for (int i = 5; i < 10; i++)
{
String ItemName = ConnectionName + "DB102" + ",WORD" + (i - 5).ToString();
ItemDescriptors = new DAPropertyArguments(OPCHostName, OPCServer, ItemName, 2);

}

for (int i = 10; i < 15; i++)
{
//String ItemName = ConnectionName + "DB103" + ",INT" + (i - 10).ToString();
String ItemName = ConnectionName + "DB103" + ",WORD" + (i - 10).ToString();
ItemDescriptors = new DAPropertyArguments(OPCHostName, OPCServer, ItemName, 2);

}

for (int i = 15; i < 20; i++)
{
String ItemName = ConnectionName + "DB104" + ",WORD" + (i - 15).ToString();
ItemDescriptors = new DAPropertyArguments(OPCHostName, OPCServer, ItemName, 2);

}

Folowed by

Vals = easyDAClient1.GetMultiplePropertyValues(ItemDescriptors);

listBox1.Items.Clear();
for (int i = 0; i < 20; i++)
{
listBox1.Items.Add(Vals.ToString());

}
listBox1.Items.Add(System.DateTime.Now.TimeOfDay.ToString());



Both INT and WORD yield the same data.
Is this the right way to do this ? The data is not completely what i expect. The WORD1 value is also changing if i write a value in WORD0

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

Moderators: support
Time to create page: 0.082 seconds