Open Dialog in PLC

2022-08-09
2022-08-11
  • masmith1553 - 2022-08-09

    Hello,

    I am trying to use the fbOpenDialogExtended block from Visu Utils. My code works only a third of the time and I am not sure why...

    FUNCTION_BLOCK FB_SeqChgMsgBx
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    END_VAR
    VAR
        xOpenMessageDialog              :       BOOL;
        xStartTimer                     :       BOOL;
        fbOpenMessageDialog             :       VU.FbOpenDialogExtended;
        MessageInfo                     :       d01_MessageBox_VISU_STRUCT;
    
        seqChgTemp                      :       INT;
        TON_0                           :       TON;
        tonET                           :       TIME;
    END_VAR
    
    IF GVL_Visual.autoSeqNumber <> seqChgTemp THEN
    
        CASE GVL_Visual.autoSeqNumber OF
            0:
                MessageInfo.sMessageTxt := 'Sequence has been changed to Manual';
                MessageInfo.sBitmapID := 'icons8-info-50';
                MessageInfo.sTitle := 'Auto Sequence Change';
                xOpenMessageDialog := TRUE;
                xStartTimer := TRUE;
    
            1:
                MessageInfo.sMessageTxt := 'Sequence has been changed to Auto Sequence 1 which includes door movement';
                MessageInfo.sBitmapID := 'icons8-info-50';
                MessageInfo.sTitle := 'Auto Sequence Change';
                xOpenMessageDialog := TRUE;
                xStartTimer := TRUE;
    
            2:
                MessageInfo.sMessageTxt := 'Sequence has been changed to Auto Sequence 2 which is compaction only';
                MessageInfo.sBitmapID := 'icons8-info-50';
                MessageInfo.sTitle := 'Auto Sequence Change';
                xOpenMessageDialog := TRUE;
                xStartTimer := TRUE;
    
    
        END_CASE
    
        fbOpenMessageDialog(sDialogName := 'd01_MessageBox', xModal := TRUE, pTopLeftPosition := 0, itfClientFilter := VU.Globals.AllClients,
        xExecute := xOpenMessageDialog, pbyDialogInterfaceData := ADR(MessageInfo), udiDialogInterfaceDataSize := SIZEOF(MessageInfo));
        seqChgTemp := GVL_Visual.autoSeqNumber;
        IF xOpenMessageDialog THEN
            xOpenMessageDialog := FALSE;
            fbOpenMessageDialog.xExecute := FALSE;
        END_IF
    END_IF
    TON_0(IN:=xStartTimer AND NOT GVL_J1939.rgtJoystk_Btn8_0, PT:=T#30S);
    tonET := TON_0.ET;
    IF TON_0.Q THEN
        GVL_Visual.closePopup := TRUE;
    
        xStartTimer := FALSE;
    END_IF
    
     

    Last edit: masmith1553 2022-08-09
  • surikan - 2022-08-11

    I found myself that I have to run the FB first with xExecute:= false, then run it again with Execute:= True and it works every time.

    So in your scenario just try to stick this above your case statement or just after :
    fbOpenMessageDialog(sDialogName := 'd01_MessageBox', xExecute:= false);

    Maybe somebody else could tell us why it is like this.

     
    πŸ‘
    1
  • tvm - 2022-08-11

    It's because the fbOpenMessageDialog function block is looking for a rising edge on the xExecute input.

    This section:

    IF xOpenMessageDialog THEN
        xOpenMessageDialog := FALSE;
        fbOpenMessageDialog.xExecute := FALSE;
    END_IF
    

    doesn't actually run the function block, it just sets the xExecute input to false. But fbOpenMessageDialog doesn't actually run again until you change GVL_Visual.autoSeqNumber on line 1. But when it does run, it doesn't see a rising edge, because xExecute is TRUE, the same as it was the last time it ran. The function block hasn't actually seen the FALSE state of xExecute.

    As surikan said above, you need to reset the input so it sees the rising edge on the next cycle. You could do it here

    IF xOpenMessageDialog THEN
        xOpenMessageDialog := FALSE;
        //fbOpenMessageDialog.xExecute := FALSE;
        fbOpenMessageDialog(sDialogName := 'd01_MessageBox', xExecute:= FALSE);  
       //this resets the input to false and runs the function block, so it sees the false state
    

    This might explain the behaviour a bit better
    https://help.codesys.com/webapp/behaviour_model;product=LibDevSummary;version=3.5.17.0

     
    • surikan - 2022-08-11

      I suspected that would be one reason for it, yet the provided example on forge does not include this.

      In my experience if you do the reset after opening the dialog you still end up with having open twice after power cycle/ download/ online change, hence I suggested to do before

       
      πŸ‘
      3
  • masmith1553 - 2022-08-11

    Thank you for the responses, I was able get it working.

     

Log in to post a comment.