Setting tag if user is logged in.

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
jydepower
Posts: 26
Joined: Thu Aug 16, 2012 9:33 am

Setting tag if user is logged in.

Post by jydepower »

Hallo.

I need to set a tag if user is logged in.

I tried this with no success.

public partial class Tags
{

void SystemTagCurrentUser_ValueOn(System.Object sender, System.EventArgs e)
{
Globals.Tags.TestBit.Value = 1;
}
}

Basicly i just need to check if the SystemTagCurrentUse string is empty or not.

User avatar
Ron L.
Posts: 214
Joined: Fri Jul 15, 2011 3:21 pm

Re: Setting tag if user is logged in.

Post by Ron L. »

I don't believe the "ValueOn" action works as it's name indicates. I would try using the "ValueChanged" action instead.
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer

jydepower
Posts: 26
Joined: Thu Aug 16, 2012 9:33 am

Re: Setting tag if user is logged in.

Post by jydepower »

I tried that. But have not clue why it changes. When i start run time it goes 1 right away. When when i login nothing happens. So i actually have no idea what status of SystemUser is.

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Setting tag if user is logged in.

Post by mark.monroe »

The current user is a string. The system may change it to a string with nothing in it, which would then trigger the ValueChange event.

You need to check the value of the tag to see if it is empty, or if it has something in it. If it has something in it, then you know that there is a user.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

jydepower
Posts: 26
Joined: Thu Aug 16, 2012 9:33 am

Re: Setting tag if user is logged in.

Post by jydepower »

Yes. That is what i wrote in first post. I basically need help to see if the string is empty.

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Setting tag if user is logged in.

Post by mark.monroe »

There are many C# tutorials available online. The best is to look at one of those.

http://csharp.net-tutorials.com/basics/if-statement/

if(Globals.Tags.MyString.Value == "")
//Do something if my string is empty
if(Globals.Tags.MyString.Value != "")
//Do something if my string is not empty
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

jydepower
Posts: 26
Joined: Thu Aug 16, 2012 9:33 am

Re: Setting tag if user is logged in.

Post by jydepower »

I can figure out the basic of checking tags and doing if's etc.

My problem is, if i cant use the "build-in" event handlers like screen opened and closed etc. i don't know how to start a simple if statement.

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Setting tag if user is logged in.

Post by mark.monroe »

Why can't you use the built in screen handles? The screen open/closed handles work.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

jydepower
Posts: 26
Joined: Thu Aug 16, 2012 9:33 am

Re: Setting tag if user is logged in.

Post by jydepower »

True.

But when user hits ok after typing username and password the screen is already opened. I would require to somehow refresh the screen or something.

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Setting tag if user is logged in.

Post by mark.monroe »

When the user logs in, then the tag changes value, which fires its ValueChange event. Therefore put your code in the SystemTagCurrentUser ValueChange event. That tag changes value when the unit turns on because the system is initializing the tag to empty. That is why you need to check the value of the tag in the value change event. If the tag is not a user, then you do nothing because you know that the tag was initialized by the system, and no one logged in.

You can put an AnalogNumeric Box on your screen and associate it with the SystemTagCurrentUser tag and see what is in that tag.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

Post Reply