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

Best way to achieve dynamic image

spiritcore
2021-07-04
2021-07-09
  • spiritcore

    spiritcore - 2021-07-04

    Hi,
    I'm working in a project where I need to get a picture from a camera into a Python program, do some process and then pass it to Codesys in order to show it on the HMI.
    My plan is to use OPC-UA client on Python to change variables in Codesys.
    From what I understand, images in Codesys can only be used with pool with declaration of location of the image and that's not dynamic.
    I thought about Web Browser element but that means I will need to use an HTTP server on Python because only TargetVisu can show local images (Browsers can't access local files from WebVisu).
    What approach is recommended to achieve it?
    Thanks!

     
  • m.prestel

    m.prestel - 2021-07-05

    Hey @spritcore,

    if the python program is running on the PLC or it can access the PLC via e.g. SSH you could do the following things.
    An image has the property "Bitmap version" (https://help.codesys.com/webapp/_visu_elem_image;product=core_visualization;version=3.5.17.0#element-property-dynamic-image).
    If this variable is changed, the cached image will be cleared and reloaded from file.

    Yes, you are correct that CODESYS only uses imagepools.
    But you can create a template entry in the imagepool, determine the real file name on the plc (file names will get changed to ensure no name conflict) and simply replace it by the python script and then increment the bitmap version.

    Of course the solution with the WebBrowser is also possible.
    If you are using a WebVisualization you could use the PLC webserver.

    Hope this helps you solve your issue.

    Best regards,
    Marcel

     
  • spiritcore

    spiritcore - 2021-07-05

    Thank you Marcel!
    The Python program will run on a PC (Delta AX series with Codesys runtime) so both Codesys and the program are on the same machine.
    I'm trying to avoid using to many protocols so I wonder if I can use the OPC-UA instead of SSH.
    Also, I'm not sure how to find the real filename on the PLC so I can replace the image...
    If you could elaborate a little bit more it would be much appreciated!

     
  • m.prestel

    m.prestel - 2021-07-05

    Hello @spritcore,

    you dont need any protocol if both python and runtime are on the same machine.
    you can simply access the filesystem.

    In your $PlcLogic$/$visu$ there is a file named application.imagepoolcollection.csv
    There you can find the mapping from id to file name.
    This mapping does not change if you dont do any download. So you can also manually determine the file name.

    Best regards,
    Marcel

     

    Last edit: m.prestel 2021-07-05
  • spiritcore

    spiritcore - 2021-07-05

    Ok,
    I never tried to access the file system (don't even know what $PlcLogic$/$visu$ means).
    Do you have a link to Codesys documenation about it?
    So I can learn how to access the file system.
    Currently, I'm testing on the Codesys Control Win x64.

     
  • m.prestel

    m.prestel - 2021-07-05

    You are on the same plc, you share the same file system.
    $PlcLogic$ and $visu$ are two placeholders, which SysFile resolves.
    You can simply check the filesystem of your plc and look for the visu folder.

     
  • spiritcore

    spiritcore - 2021-07-07

    Hi Marcel,
    I can't get it to work.
    I have an image called "image.jpg" and I added it to the image pool using the option "Remember the link and embed into project" and I set the Change Tracking to "Reload the file automatically" but when I replace the image with another one (but keep the file name) nothing changes.
    Also tried changing the Bitmap Version but it doesn nothing.
    What am I missing here?
    Thanks!

    Update: I just read that the option to load the image automatically is only for the IDE and not for the PLC.
    Not sure what to do now...

    Another update:
    I found where the image is placed in the PLC folder and when I replace it It change but only if I refresh the browser.
    So I need to find a way around that.

     

    Last edit: spiritcore 2021-07-07
  • m.prestel

    m.prestel - 2021-07-07

    Hey,
    I found where the image is placed in the PLC folder and when I replace it It change but only if I refresh the browser.
    So I need to find a way around that.

    Thats the way to go.
    This folder is your $PlcLogic$/$visu$ folder.
    If you replace the image in this folder and change the Bitmap Version of the image, it will be reloaded (without the need to refresh the browser).

    Best regards,
    Marcel

     
    • spiritcore

      spiritcore - 2021-07-08

      Thanks Marcel!
      Currently, I need to refresh the browser or use chrome with the Developers Tools open on the network tab and Disable Cache option ticked.
      When closing the developer tools window it doesn't work again.
      @sedoerr had the same issue here:
      https://forge.codesys.com/forge/talk/Visualization/thread/79526ea338/#1435

      Stuck in a dead end with it.

       
      • m.prestel

        m.prestel - 2021-07-08

        Hey,
        could you attach a example project for me to reproduce the issue?
        Which browser and which version are you using?

        Best regards,
        Marcel

         
        • spiritcore

          spiritcore - 2021-07-08

          Sure, I attached the files.
          The example is in the second Visualization and I have a timer to change the bitmap so it will change the image immediately .

          Right now I'm using Firefox 89.0.2 and Chrome 91.0.4472.124
          On the real PLC we will use Chrome.

           
  • m.prestel

    m.prestel - 2021-07-08

    Hey,
    A few things.
    You should not increment your bitmap version that much.
    And the issue seems to be caused by the bitmap ID variable.
    Just remove this from the configuration as you dont need it.

    Best regards,
    Marcel

     
  • spiritcore

    spiritcore - 2021-07-08

    You should not increment your bitmap version that much.

    I know, It was just for making it easy so I don't have to change it manually every time.

    And the issue seems to be caused by the bitmap ID variable.
    Just remove this from the configuration as you dont need it.

    I removed the variable (and the timer) and it still require refresh both on Firefox and Chrome.

     

    Last edit: spiritcore 2021-07-08
  • m.prestel

    m.prestel - 2021-07-09

    Ok, ok I feel stupid now.

    If you can disable the feature "Support client ainimations and overlay of native elements" it should work.

    Raising an issue and trying to get it fixed in 4.1.0.0 Visu Package.

    Best regards,
    Marcel

     

    Last edit: m.prestel 2021-07-09
    • spiritcore

      spiritcore - 2021-07-09

      It's working!
      Thank you Marcel!

       

Log in to post a comment.