This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Run script on screen open
#1
Hi,

Is there any way to run event script on screen open event? I need this for all environments (visu, touch). Also, for "while screen open" state and "on screen close" event.

Or the other way round can I check inside scripts (probable resident) which screen is open by its name? If so, if two layouts have exactly the same name one for visu and other for touch how is distinction possible?

Thank you in advance!
Reply
#2
What are you trying to achieve by this?
Reply
#3
Basically, I want to execute a read request on screen open.

Some examples may be:
  - Pop up an information window every time a specific screen is accessed. The pop-up could be disabled later with a button.
  - Set a timer to return to home screen after some time of inactivity
  - Inform that a page is accessed and the name of user (if possible)

This is standard feature for HMIs and I was wondering if this is possible for LM too...
Reply
#4
Hi,

All is possible as you have client (JS and LUA) and server side (LUA) scripting at your service including websockets and KNX listeners to do whatever you need but it would help to have a real use case, a read request on a screen open can be done but I don’t think you want to perform a read request on any page, any time as that does not makes sense to me..

A popup any time you access a page is also not logical, so what do you want exact?

You can fetch a user on a page but who, when and how do you want to inform anyone and for what purpose?

I never seen your requests as a standard feature for HMI’s so can you give a sample?

Back to start can be done by custom JS and there is a script created for this as that makes sense (:

Code:
$(function() {
 
  // Back to Start after x seconds (in miliseconds)
  var SE_Timeout = 90000; // adjust this timer value if needed (90 seconds in miliseconds)
  var SE_Startpage = currentPlanId; // First page that is loaded
  var eventlist = 'vclick vmousedown vmouseout touchend';
 
  // Timer function no usage detected
  function No_Usage_Detected(callback, timeout, _this) {
    var timer;
    return function(e) {
        var _that = this;
        if (timer)
            clearTimeout(timer);
        timer = setTimeout(function() {
            callback.call(_this || _that, e);
        }, timeout);
    }
  }

  // Back to start function when timer elapsed
    var SE_Goto_Startpage = No_Usage_Detected(function(e) {
    if ( currentPlanId != SE_Startpage ) {
    showPlan(SE_Startpage);
    $(location).attr("href", "/logout");
    }
  }, SE_Timeout);
 
  // Add event listener to document to detect user input
  $(document)
  .on(eventlist, function() {
    SE_Goto_Startpage();
  });

  // Add event listener to all iframes to detect user input inside iframes
  $('iframe').load(function() {
    var iframe = $('iframe').contents().find('html');
    iframe.on(eventlist, function(event) {
     SE_Goto_Startpage();
    });
  });

});
BR,

Erwin
Reply
#5
(25.09.2020, 22:05)Erwin van der Zwart Wrote: Hi,

All is possible as you have client (JS and LUA) and server side (LUA) scripting at your service including websockets and KNX listeners to do whatever you need but it would help to have a real use case, a read request on a screen open can be done but I don’t think you want to perform a read request on any page, any time as that does not makes sense to me..

A popup any time you access a page is also not logical, so what do you want exact?

You can fetch a user on a page but who, when and how do you want to inform anyone and for what purpose?

I never seen your requests as a standard feature for HMI’s so can you give a sample?

Back to start can be done by custom JS and there is a script created for this as that makes sense (:

Code:
$(function() {
 
  // Back to Start after x seconds (in miliseconds)
  var SE_Timeout = 90000; // adjust this timer value if needed (90 seconds in miliseconds)
  var SE_Startpage = currentPlanId; // First page that is loaded
  var eventlist = 'vclick vmousedown vmouseout touchend';
 
  // Timer function no usage detected
  function No_Usage_Detected(callback, timeout, _this) {
    var timer;
    return function(e) {
        var _that = this;
        if (timer)
            clearTimeout(timer);
        timer = setTimeout(function() {
            callback.call(_this || _that, e);
        }, timeout);
    }
  }

  // Back to start function when timer elapsed
    var SE_Goto_Startpage = No_Usage_Detected(function(e) {
    if ( currentPlanId != SE_Startpage ) {
    showPlan(SE_Startpage);
    $(location).attr("href", "/logout");
    }
  }, SE_Timeout);
 
  // Add event listener to document to detect user input
  $(document)
  .on(eventlist, function() {
    SE_Goto_Startpage();
  });

  // Add event listener to all iframes to detect user input inside iframes
  $('iframe').load(function() {
    var iframe = $('iframe').contents().find('html');
    iframe.on(eventlist, function(event) {
     SE_Goto_Startpage();
    });
  });

});
BR,

Erwin

Hi, thanks for the reply.

For the main purpose of the post, that is to execute read request on screen open, I want to have a page in touch visualization that will act as a central status report page. For example, I want to know if all windows are closed, so (due to the fact that states may change at any time) I want to execute read request when the user accesses the page and then perform a "logical and" to all separate statuses to get the result. Maybe that could be done with use of a Tag ("window status") that would execute a script and update the central status object each time a window would change state but the desired solution (on screen open) could save some resources as it would run only when needed.

The other examples were just a thought and concern basically pages that have to do with electromechanical equipment. Keep in mind that at the time being I use only Touch interface because I don' t have the skills to make a decent visualization.

So suppose I had a page for a machinery that I would like to keep as simple as possible then a pop-up window could be a solution to give a small report for the devices (running hours, last error e.t.c.). However, the pop-up is really not a good idea.

The third example, would be used as a login activity for the supervisor to know how often a installation is monitored.

By saying "standard feature for HMIs" I didn' t mean any of the examples I gave but the possibility of "HMI Touch Screens" to execute scripts "on screen open", "on screen close" and "while on screen".

Anyway, the question was aiming basically on the ability and not for real case scenarios...
Reply
#6
Within any app there is (unfortunately) no option to use custom JS or custom CSS so when using Touch you are limited to the options the app offers.

If you want to use the power of custom scripts you need to use the free visualization.

Back to start won’t work on Touch / Mosaic.

For knowing if a window is open you can use TAG’s with a logic script to update an object to a certain state.
Reply
#7
Hello, is it possible to automatically return to a home page when the display is on a specific page? In the rest of the pages the script cannot act.
Reply
#8
Yes, just change:

if ( currentPlanId != SE_Startpage ) {

To:

if ( currentPlanId == 3 ) {

Where 3 is the plan that should enable the back to start..
Reply
#9
Hello, I want to ensure that when inserting the initial page in visu it only remains for a while (5 seconds) and it is automatically redirected to a parameterizable page.
Reply
#10
Redirect to plan #2 after 5000 ms timeout:
Code:
$(function() {
  var timeout = setTimeout(function() {
    showPlan(2);
  }, 5000);
  
  $('body').on('showplan', function() {
    clearTimeout(timeout);
  });
});
Reply
#11
(18.01.2021, 08:45)admin Wrote: Redirect to plan #2 after 5000 ms timeout:
Code:
$(function() {
  var timeout = setTimeout(function() {
    showPlan(2);
  }, 5000);
 
  $('body').on('showplan', function() {
    clearTimeout(timeout);
  });
});

Thanks Admin, with this I can create an intro to visualization.

By the way, to go back to that Plan 2, what do I need to change in the script that Erwin shares?
Reply
#12
Set line 5 to var SE_Startpage = 2; and remove line 25: $(location).attr("href", "/logout");. This will redirect the user to plan #2 after 90 seconds of inactivity.
Reply


Forum Jump: