Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Release SP20 - Changes in behaviour?

Strucc.c
2024-03-24
2024-03-25
  • Strucc.c

    Strucc.c - 2024-03-24

    Dear all,

    I've just started to migrate some of my ancient projects to SP20. There is one strange error (?) I have noticed so far. In a method call, depending on the circumstances I would like to return reference to an object, or an invalid reference:

    METHOD Add_EVT_OUT : REFERENCE TO FB_MSG
    VAR
    END_VAR
    
    IF __ISVALIDREF(refMSG_Entry) THEN
        Add_EVT_OUT REF= MANAGER.AddMsg_EVT_OUT(
            refMSG_Entry, 
            _Get_EVT_Message(MSG_EVENT.OUT), 
            _Get_EVT_AddCode(MSG_EVENT.OUT)
        )^;
    ELSE
        Add_EVT_OUT := 0;
    END_IF
    

    So far setting a reference variable to 0, did this. But now, the expression Add_EVT_OUT := 0; gives an error:

    [ERROR] DB_WTP_370: Add_EVT_ACK MSG_TRIGGER_EXT: C0032: Cannot convert type 'BIT' to type 'REFERENCE TO FB_MSG'

    Naturally... I can write:

        Add_EVT_OUT := DWORD#0;
    

    But is this the correct way? Is there any constant I could use instead, like "NULL"?
    Or this is totally wrong and to be avoided?

     
  • Fless

    Fless - 2024-03-24

    use this to set an invalid reference

    Add_EVT_OUT REF= 0;
    
     
    πŸ‘
    1
    • Strucc.c

      Strucc.c - 2024-03-25

      Wow.... I missed this one in the manual - so there is a special syntax to invalidate a reference... Great :) Seems to work.
      (it's just mentionned in the examples line)...

      I've always assigned 0 to the variable, with := 0 - like setting a pointer to 0. In theory, that should work as well.

      Thanks!

       
    • Strucc.c

      Strucc.c - 2024-03-25
       

      Last edit: Strucc.c 2024-03-25
  • SiegeLion - 2024-03-25

    You should use this method:
    VAR
    NULL:REFERENCE TO FB_MSG
    END_VAR
    Add_EVT_OUT REF= NULL;

     
    • Strucc.c

      Strucc.c - 2024-03-25

      This... is not very practical for me - as I have a bunch of different classes - it's just doesn't seems to be very practical to define a NULL for each of them...

      Something like this I use in parameter definitions. For example:

      VAR_INPUT
          refVFD_Drive : REFERENCE TO FB_VFD_Drive := GVL_DUMMY.Dummy_VFD;
      END_VAR
      

      I use this to prepare objects for code I don't control: Typycally visualizations - had many troubles with references set on the fly, right before opening a corresponding visualization...

      And yes, the instance in GVL_Dummy reports itself as "Fake", so it does not influence the actual application at all. Actually this way I could invalidate a reference, just to set it to a "Dummy" instance.

       

Log in to post a comment.