Troubleshooting
How to Show a Login Success Popup on an NA HMI
Short answer
Trigger the popup from a change in the logged-in user name or security level inside a global script, not from a button release. Open the page with ShowPage and return immediately. Close it after five seconds from a timer expiry or the script's next pass — never with System.Threading.Thread.Sleep(5000), which blocks the render, while the commented ClosePage line never runs.
On this page
Both symptoms come from two separate faults, and neither is the popup page itself. A button Release event only reports that a finger left the button, so it can never confirm that credentials were accepted. And the routine calls System.Threading.Thread.Sleep(5000) immediately after showpage("Page1000_AddUserFail"), which holds the script's execution context for the full five seconds so the page request cannot finish — while the leading apostrophe on the next line turns ClosePage into a comment that never runs. Trigger instead on the logged-in user name or security level changing in a global script, open the page with ShowPage, return at once, and close it after five seconds from a deadline check or a timer expiry.
Why the release event proves nothing #
A Release event fires the moment the operator's finger leaves the button. Everything that decides a login happens after that: the NA security function reads the credentials and accepts or rejects them. A wrong password produces the same release as a correct one, so a popup tied to release announces the press, not the result — it would celebrate failed logins. Drop the release trigger entirely. The signal you actually have is the authenticated state itself: the built-in variable that returns the currently logged-in user name, and the one that returns the current security level. Both sit in the NA's system variable list in Sysmac Studio, and both can be read from a global script.
The signal to trigger on #
Three candidates, and what each one buys you:
- Current user name — cleanly separates logged-out from logged-in and tells you who just logged in; a re-login as the same already-logged-in user leaves it unchanged.
- Current security level — separates authorization bands; two different users sharing one level look identical.
- A direct authentication result, if the version you run exposes one — the cleanest trigger when available; otherwise the user-name transition is the one to build on.
Initialize the retained previous value to the logged-out state and trigger exactly once on the transition into a real user name. A change back to logged-out is a logout, and a logout must not open a success popup. A continuously true logged-in condition is not an event at all — used directly, it re-opens the page right after every close. Levels deserve deliberate planning on any panel — granular user access on a CODESYS touch panel is configured the same way, each level mapped to what an operator may touch — but your popup trigger here is the user-name transition. Keep one thing straight while you wire this: the popup only reports state, and the real access control is the security level assigned to objects, so sensitive write actions stay level-protected no matter what the popup announces.
Why your popup never appeared #
Read the attempted routine as two faults stacked one line apart. showpage("Page1000_AddUserFail") is a request: the runtime displays the page once the script yields control back. System.Threading.Thread.Sleep(5000) prevents exactly that — the script occupies its execution context for five seconds, the page request stays pending, and you see nothing.
The third line, 'ClosePage("Page1000_AddUserFail"), never executes at all: the leading apostrophe is the comment marker in NA scripts, so even without the sleep the page would open and never close. And the page name itself is wrong for the job — Page1000_AddUserFail is an add-user failure page, and a working ShowPage call opens exactly the page it names. The decision this forces: no Sleep call belongs in any NA routine that displays a page.
The corrected sequence #
- Create the success popup as its own page with a name that says success, and leave it out of normal page navigation. Popup pages on the NA can be presented through ShowPage events, user alarms, or any other page-display method; the script-driven
ShowPageis the one that fits here. - Configure at least two user levels with known passwords in the NA security settings, so simulation can exercise a valid login, a rejected login, and a logout.
- In the global script, keep the retained state with explicit types and starting values:
' Illustrative names for your own variables.
' currentUser stands for the NA's built-in
' logged-in user name system variable.
' Page_LoginOK is your success page's name.
Dim previousUserName As String = ""
Dim popupCloseDue As DateTime = DateTime.MinValue
If currentUser <> previousUserName AndAlso currentUser <> "" Then
ShowPage("Page_LoginOK")
popupCloseDue = DateTime.Now.AddMilliseconds(5000)
previousUserName = currentUser
End If
If popupCloseDue <> DateTime.MinValue AndAlso DateTime.Now >= popupCloseDue Then
ClosePage("Page_LoginOK")
popupCloseDue = DateTime.MinValue
End If
- Each pass, the first block compares the current user name with the retained one. On a change into a real user name it opens the page and records a deadline five seconds ahead; the
DateTimemembers are standard .NET, the same library theSleepcall came from. - On a later pass — or in a timer expiry event, if you prefer the NA's timer objects — the second block closes the same page and resets the deadline.
Nothing waits: the script returns on the same pass that opened the page, and a login that arrives while the popup is already open simply rewrites the deadline. The test that proves the fix: build and run in simulation — a valid login opens the popup and it closes itself five seconds later, a wrong password opens nothing, and pages stay navigable the whole time.
Timing a 5-second login popup on the NA #
Inputs, each with its source:
- Display duration: 5 s — the duration in the original question, written there as
Sleep(5000). - Conversion factor: 1000 ms per 1 s — the
Thread.Sleepargument is milliseconds in .NET, which is why five seconds appeared as 5000. - Trigger source: the user-name change, checked on every global-script pass.
Rule in words: the routine never waits. The delay is a deadline written at open time and compared on later passes (or a timer preset loaded at open time), so the millisecond value you load equals the display duration in seconds multiplied by 1000.
Arithmetic: 5 s × 1000 ms per s = 5000 ms. The deadline is DateTime.Now.AddMilliseconds(5000); a timer object would get the same preset.
Result: the popup holds the full 5 s, closes itself, and the script has been returned the entire time.
Decision: 5000 ms is the setting for this message — long enough to read a user name — and it only moves if someone asks for a different duration, always as seconds × 1000. A two-line message keeps the same value.
What to confirm in simulation #
- Valid login: the popup opens at once, holds the full interval, and closes itself.
- Wrong password: no popup at any moment.
- Logout: no popup.
- During the open interval: page navigation and button presses still respond — that is the proof the blocking is gone.
- Login again as the same user: no popup, because the user name did not change; that is the designed behavior, not a fault.
Questions asked
Why doesn't the button Release event work as the login trigger?
Release reports only that a finger left the button. The NA security function checks the credentials afterward, so a wrong password produces the same release as a valid one. A release handler is still fine for submitting credentials or moving focus — just never use it as the success signal; the user-name change in the global script is that signal.
Would a shorter Sleep, such as 500 ms, be acceptable?
No. The failure is the blocking itself, not the length of the delay. Any Sleep holds the script's execution context for exactly as long as it sleeps, and the page request stays pending until the routine returns. Use the deadline comparison or a timer expiry event for every delay, short or long, so display work always gets the runtime back immediately.
What happens when the same user logs in again?
The user name is unchanged, so the change-detect raises nothing and the popup stays closed. That is usually the right behavior — the operator is already in. If a site must confirm every login attempt, trigger on the security-level transition instead, or clear the retained name at logout, and apply that one choice consistently for every user.
Why did the popup point at an add-user failure page?
Page1000_AddUserFail is simply the page name written into the call, and ShowPage opens exactly the page it names. A perfectly working display call can still present the wrong message. Create the success page separately, give it a name that says success, and pass that same name to both ShowPage and ClosePage so the open and the close always match.