Jump to content
Sign in to follow this  
UNICO2

Tag Name to String

Recommended Posts

Hi All - I made a complex function that has used all 10 inputs, so I can't just add another input for this, I just need the name of the tag in the function (call it  CBA bit  or whatever it is called) that triggers a bad condition, and I need to post that tag name to a string (in a data table struct).  I am just looking for the easiest way to get that info into the data table from inside the function without a string input so that I don't have to do it 240 times elsewhere,  and I figure getting the tag name( which I know already) into a string would work best, if I can do it.  I am using a bunch of UID-0016R's and they have addresses with Alias Names which seem to be strings too but this is in the function output.  Any ideas how or any other options?  

Also, is it possible to see inside a function while in Online mode for troubleshooting - all I seem to be able to see is the inputs and outputs? 

Thanks!

Share this post


Link to post
Share on other sites

Hi,

3 schedules for 80 different relays = 240 possible configurations that could be in conflict with one another.  What I did was use an output for the function (I still had one left) and attached a string to that and used the string's power up default value as the error message and that seems to work.  BTW, I was thinking more like in C# you could do something like this:

string TagName = nameof(obj.Tag);

So it might be an easy addition to the source code.

Thanks.

Share this post


Link to post
Share on other sites

Well, C# is a managed language with code that compiles at run time, and it is not Real-Time.

On the other hand, the PLC must be real-time and the code is compiled to C++ and then to machine code. Furthermore, we allow having tag names with non-English characters and with spaces (which is not a valid variable name in c#, for example). When code is compiled, the tag names are compiled to a string with English characters only in the C++ code, and when it's compiled to machine code, it compiles to an absolute address, a value or a pointer (if for example, the value comes by ref in a UDFB input/output).

 

  • Upvote 1

Share this post


Link to post
Share on other sites

Ok, my point is that the tag string name could be added as a member of the tag structure or class or memory allocation or whatever it is, then maybe add a function like IP to string, it could be called Tag to string, any character that doesn't work disappears/not converted.   The benefit would be in a UDFB you can do something once for troubleshooting or logging or alarms and not 100's of times.

For example- how can I see the code inside the function in Online mode?  My understanding is that I can only see the inputs and outputs in real time.  With a Tag to string I could log the tag name and value to a file with a time stamp or iteration etc.  Again I have 240 possible conditions.  Right now I have to take the logic out of the function and put it somewhere else on the ladder and then change all the tag names just to troubleshoot that function code.  

Share this post


Link to post
Share on other sites

But the tag is not a structure. It's not like in c# where everything derives from Object.

It's c++, so a INT8 consumes 1 byte exactly. converting the tag name to a string could be done on compile time, so we know which tags are passed to the " magic function", and we compile their name as a const, but it cannot be done in run-time, whereas you pass a different argument to a UDFB each time.

 

The reason why you can't see the actual in/out/locals of a function is because each time you enter the function, it is called with different parameters, and the local tags are not allocated in the global area, but in the stack. When a function exists, the stack is used for the call of another function.

 

However, we are currently working on a solution for watching locals inside a function.

 

  • Upvote 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...