- Posts: 12
- Thank you received: 0
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 ?
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.
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:
Best regards
Please Log in or Create an account to join the conversation.
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.
Please Log in or Create an account to join the conversation.
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:
Best regards
Please Log in or Create an account to join the conversation.
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.