libplctag icon indicating copy to clipboard operation
libplctag copied to clipboard

Create UDT Tags or Array

Open enesaygunea opened this issue 3 years ago • 2 comments

Hi,

How can I create UDT tags? When I browse PLC tags, I guess this library does not give me UDT or array directly. If I create tags in loop (as follows) the program takes a lot of time. How can I solve this problem ?

Is this API give me UDT type such as Mtu_Com.Module_Communication_Error, Mtu_Com.Serial_Port[0] ? Or should I create tags in loop?

        for (int i = 0; i < childTag->elem_count; ++i)
	{
		array_name = tag_name_buf;
		array_name += '[' + std::to_string(i) + ']';

		arrTag.parent = childTag;
		arrTag.name = array_name;
		arrTag.elem_count = 1;
		arrTag.elem_size = childTag->elem_size;
		arrTag.type = childTag->type & 0xFF;
		
		TagCreate(arrTag);
	}

enesaygunea avatar Jul 27 '22 12:07 enesaygunea

Thanks for using the library!

The library (and the underlying protocol) reads tags as if they were all arrays. A non-array tag is read as if it is an array of length 1. If you read a UDT tag, you will get the entire UDT. You can read individual fields one at a time using the "." notation:

name=myUDT.myField

If you read an entire UDT you can use the various data accessor function calls with offsets to get the individual fields. It is often tricky to find out where a field is because Rockwell uses some packing rules that are not obvious. For instance individual boolean fields are packed into single USINT (byte) values.

I hope this helps.

kyle-github avatar Jul 28 '22 14:07 kyle-github

Hi Kyle, thanks for your response.

Actually I just want to learn how can I combine tag in list operation. (It's like list_tag_logix.c)

I can access tag such as myUDT, but I can not access directly such as myUDT.myField. I guess I need to combine. So, In list operation, when I combine UDT or Array Tag such as Mtu_Com.Serial_Port[0], myUDT.myField, the program takes a lot of time.

Can I access UDT or Array tags as combined (like myUDT.myField, Mtu_Com.Serial_Port[0]) directly in list operation?

enesaygunea avatar Jul 28 '22 16:07 enesaygunea

These questions are probably better on the forum.

kyle-github avatar Nov 16 '22 16:11 kyle-github