Closed brunoluizkatz-NETZSCH closed 2 months ago
It depends on if you need the variable type in the PLC or the equivalent go type.
When the reads occur from the PLC it does send the type back, but I don't know that I expose this anywhere (But I can if needed). The Read_single function will give you the value of a tag without having to know what type it is before hand.
value, err := client.Read_single("tagname", gologix.CIPTypeUnknown, 1)
if err != nil {
log.Printf("error reading testint. %v", err)
}
// do whatever you want with the value
log.Printf("tag has value %v of type %T", value, value)
// outputs "tag has value 65 of type int32"
This will work for elementary tags (DINT, INT, BOOL, etc...) If you try to read a UDT/structure you'll get a byte array returned (I think - I will test this when I get a chance) and you'll have to parse that out yourself. If you try to read an array tag you'll only get the number of items you specify.
There is also a function to read all the tags and their types out of the controller, but it may have some bugs in it. Look at the "ReadAllTags" example for info on how to use that. By looking at the KnownTag
structs for each tag it finds you can see what type it is, what size the array is if it is an array tag, etc...
Closing for inactivity.
Hello, our system design currently lacks a mechanism to identify variable/tag types. As a result, I am unable to execute the
Read(tag, &v)
function withv
set to the correct type before initiating communication with the Rockwell PLC.I would like to verify if there is any existing method or recommended practice that addresses the identification of tag/variable types. Today I'm trying each type by the "most used" type we have at the PLCs and caching it to be reused.