Read system tags

453 views
Skip to first unread message

nai...@gmail.com

unread,
Sep 27, 2022, 5:26:26 PM9/27/22
to libplctag
Hi all and thanks for you great library.

im trying to write a simple program that will read all the values from my tags at runtime.
i was able to use the libplcrag.net by using the simple Tag class (not TagOfT) and was able to read most of the tags and i have some questions that i will be happy if you can point me in the right directions:
  1. i was unable to read tags that have a colon in the tag name like RIO:0:1. is there a way to overcome it?
  2. when reading a tag that is a udt, how can i understand the length of its array?
  3. can you please point me to somewhere that i can read an have a better understanding of the api?
Thanks!


Kyle

unread,
Sep 29, 2022, 11:17:22 AM9/29/22
to libplctag
There is example code in the libplctag.Net repo to list out tags from a Control or CompactLogix system.   Other types of PLCs generally do not fully support those operations.

If you are reading a tag that is a UDT, you will get the entire set of bytes of the whole UDT.   You need to use the data accessor functions to access the individual fields at the correct offsets.   The tag listing from list_tags_logix.c example in the core library outputs all the basic information you need to figure out which field goes where.   Note that boolean fields in UDTs are packed into single bytes and you will need to access the right bit in the correct byte.

Please look at the examples in the libplctag.Net repo for a nicer .Net approach to accessing tags and their data.  If you want to see what the lower level of the core DLL does, you can look at the examples in the libplctag repo.  However, those are all in the C programming language.

I hope this helps and thanks for looking at libplctag!

Best,
Kyle

nai...@gmail.com

unread,
Oct 9, 2022, 12:15:09 PM10/9/22
to libplctag
Thanks for all the tips Kyle!
one more quick question..
where can i find a list fo type codes to type names? 
like:
193 -> bool
8403 -> bool array 1d
202 -> float

etc..?

Thanks !

Krister Johnson

unread,
Oct 10, 2022, 3:50:17 PM10/10/22
to nai...@gmail.com, libplctag
Are you talking about these types in pccc.h:

typedef enum {
PCCC_FILE_UNKNOWN = 0x00, /* UNKNOWN! */
PCCC_FILE_ASCII = 0x8e,
PCCC_FILE_BCD = 0x8f,
PCCC_FILE_BIT = 0x85,
PCCC_FILE_BLOCK_TRANSFER = 0x00, /* UNKNOWN! */
PCCC_FILE_CONTROL = 0x88,
PCCC_FILE_COUNTER = 0x87,
PCCC_FILE_FLOAT = 0x8a,
PCCC_FILE_INPUT = 0x8c,
PCCC_FILE_INT = 0x89,
PCCC_FILE_LONG_INT = 0x91,
PCCC_FILE_MESSAGE = 0x92,
PCCC_FILE_OUTPUT = 0x8b,
PCCC_FILE_PID = 0x93,
PCCC_FILE_SFC = 0x00, /* UNKNOWN! */
PCCC_FILE_STATUS = 0x84,
PCCC_FILE_STRING = 0x8d,
PCCC_FILE_TIMER = 0x86
} pccc_file_t;

pccc.c is really interesting BTW, someday I'd like to pick Kyle's brain about how he divined this: https://github.com/libplctag/libplctag/blob/release/src/protocols/ab/pccc.c


--
You received this message because you are subscribed to the Google Groups "libplctag" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libplctag+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/libplctag/0a7b2e36-655f-4589-8034-f67640ab494fn%40googlegroups.com.

Kyle

unread,
Oct 12, 2022, 9:36:54 AM10/12/22
to libplctag
Hi, thanks for the interest in libplctag.

The data types for CIP are defined in /src/protocols/ab/defs.h starting on line 128.   That said, note that the type you get back from a tag read is not really a type.   If the tag is an atomic type (DINT, SINT etc.) then you get one of the values in that file as a two byte type field.   If the tag is an array or UDT, you get back a longer type field, usually 4 bytes but these do not seem to include the array dimensions.  In the case of a UDT the "type ID" part of the type data (the last two bytes) is not an ID.  It is a hash of some sort of the field names.   It is not unique and I have never found a CIP command that uses it.   I have no idea why AB sends it back.

If you list tags, you will get the UDT ID and you can get the array dimensions.   But you cannot get that information when just reading a tag.

PCCC is the older protocol that is used by PLC/5, SLC 500 and MicroLogix PLCs.  The version used in libplctag is wrapped in CIP commands.   There is another version used by older PLC/5 equipment that is closer to the raw protocol used on DH+, DF1.   There are documents from Allen-Bradley that describe that raw protocol, DF1, if you search their web site.

I hope that helps!

Best,
Kyle

Krister Johnson

unread,
Oct 12, 2022, 11:39:39 AM10/12/22
to Kyle, libplctag
Excellent, glad I could lead someone astray. It won't be the last time I'm sure

Kyle

unread,
Oct 13, 2022, 10:00:44 AM10/13/22
to libplctag
Not at all!   There are so many different partial sources of information for AB/CIP stuff that it is really hard to keep track of what is correct and what is complete (almost nothing).

Best,
Kyle
Reply all
Reply to author
Forward
0 new messages