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

Accessing a array instance variable is declared in VAR

kyehyun
2015-10-08
2015-10-10
  • kyehyun - 2015-10-08

    I've created three of FBs : FB_Framebuffer, FB_Pixel, FB_Painter. And I've added a instance for 2D array of FB_Pixel in FB_Framebuffer.

    As you see the code, In FB_Painter I want to access the 2D array variable is declared in VAR.
    But, I couldn't access it. How can I access the instance variable keeping it in VAR region of FB_Framebuffer without VAR_IN or VAR_OUT? Is it possible via Property, Reference or Pointer?

    FUNCTION_BLOCKΒ  FB_Framebuffer
    VAR
    Β  Β Buffer : ARRAY[0..1, 0..1023] OF FB_Pixel;
    END_VAR
    
    FUNCTION_BLOCKΒ  FB_Painter
    VAR
    Β  Β FrameBuffer : FB_Framebuffer;
    END_VAR
    
     
  • Anonymous - 2015-10-09

    Originally created by: scott_cunningham

    VARs are considered private variables by design. This is desired and a good thing. Now, to address your situation...

    Option 1) create a method for FB_FrameBuffer, that's takes the 2D arguments as VAR_INPUTS and returns the FB_Pixel. This may, or may not be the best solution, depending on the size of FB_Pixel.

    Option 2) rethink your solution. If FB_Painter should not be bothered by buffering details, then it should not need direct access to the array. Instead, FB_FrameBuffer should have methods and properties that FB_Painter can use to command general things like: GetNextPixel() or MoveLeft() or whatever you are trying to achieve. If FB_Painter should access the 2D array, then maybe it should be defined there, which then why have FB_FrameBuffer....

     
  • kyehyun - 2015-10-10

    Thank you for your reply.

    I'll try to create some methods to access internal variables indirectly.

     

Log in to post a comment.