Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDT tag reading #21

Open
InofensivoJimmy opened this issue Mar 23, 2022 · 3 comments
Open

UDT tag reading #21

InofensivoJimmy opened this issue Mar 23, 2022 · 3 comments
Labels
question Further information is requested

Comments

@InofensivoJimmy
Copy link

an example of how you can read or write a UDT tag with libplctag4j, thanks

@InofensivoJimmy
Copy link
Author

I use a compatLogix, and the latest version of libplctag4j

@kyle-github
Copy link
Member

UDTs are read like any other tag type. When you read an entire UDT, you get the whole thing as a blob of bytes. You can also read each field individually.

name="myUDTTag" -> gets the entire tag.
name="myUDTTag.aField" -> gets the field "aField" within the UDT tag.

You can use the tag_rw2 tool from the C project to experiment with this.

If you read an entire UDT at once, it is very fast, but you will need to determine the offsets within the bytes of each field.

For instance, if you have a UDT, myUDTTag, with 3 DINTs, A, B, and C, you can read and extract them like this:

Tag tag = new Tag("...name=myUDTTag"...);

tag.read(1000) // you should check the status here

int fieldAValue = tag.getInt32(0);
int fieldBValue = tag.getInt32(4); // DINTs are 4 bytes
int fieldCValue = tag.getInt32(8);

There are many different packing rules for UDTs that Rockwell imposes. If you have boolean values in a UDT, they are packed into hidden byte values that are stored at the start of the UDT or before the boolean field. Each bit is allocated from one of the bits in the hidden field.

Most fields are padded to their nearest power-of-two size. For instance if you have a UDT with a SINT (one byte) followed by a DINT (4 bytes), the UDT will be a total of 8 bytes. The SINT field will be at the beginning, then there will be 3 bytes of padding and then the DINT field.

Let me know if you still have questions!

@kyle-github kyle-github added the question Further information is requested label Mar 26, 2022
@InofensivoJimmy
Copy link
Author

Thank you very much, it works, I understand that string data type tags are 88 bytes? I seemed to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants