Best way to achieve dynamic image

spiritcore
2021-07-04
2023-06-20
  • 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 2021-07-09

      It's working!
      Thank you Marcel!

       
  • CellOHorst - 2023-06-08

    Thanks to you I got my project working, too!

    But I have a question.
    As I realized the image to be dynamically refreshed has to be in the folder ../visu.
    Is there a way to put it into any other folder?
    Reason: we use a compute module 4 with its internal eMMC which isn't that fast.
    The image is an image of a barcode-reader that should be shown in the Visu and then, in a background task, be copied to somewhere else.
    So - it is in process and copying the image from the BC-CAM to the ../visu-folder takes ~150ms, whereas copying it to a ramdisk is done in less than 50ms.
    We use, e.g., tmpfs /var/opt/codesys/PlcLogic/cmexchange tmpfs mode=1777 0 0 in the fstab.
    No problem to create another ramdisk below ../visu.

    BUT: is it somehow possible to have the POOL-Image in that sub-folder on the PLC - or any other folder at all?

    Kind regards,
    Horst

     

    Last edit: CellOHorst 2023-06-08
    • kislov - 2023-06-08
       
      • CellOHorst - 2023-06-20

        Thanks.

        But I'm pretty sure that that is about the folders in Codesys Developer
        (i.e. the IDE) and not the runtime.

        Let me know if I'm wrong.

        Cheers,

        Horst

        Am 08.06.23 um 11:53 schrieb kislov:

        Maybe this option helps...
        https://content.helpme-codesys.com/en/CODESYS%20Visualization/_visu_dlg_project_settings.html

        "Visualization Directories"


        Best way to achieve dynamic image
        https://forge.codesys.com/forge/talk/Visualization/thread/3dbe632d0b/?limit=25#da2a/2b9e


        Sent from forge.codesys.com because you indicated interest in
        https://forge.codesys.com/forge/talk/Visualization/

        To unsubscribe from further messages, please visit
        https://forge.codesys.com/auth/subscriptions/

        --
        bar

        Horst Noecker
        - Geschäftsführer -
        Logo
          CellOmation GmbH & Co. KG

        www.cellomation.de http://www.cellomation.de/

        • Stammsitz -
            Staufenstr. 1

        63128 Dietzenbach

        Tel.   : +49 18 03 23 55 66 (9ct./min. - Bei Anrufen über das
        deutsche Festnetz.)
          FAX  : +49 60 74 37 09 666
          Mobil: +49 160 5 30 26 48

        Horst.Noecker@cellomation.de

        HRA Nr.: 41648
          USt-IdNr.: DE280920848
          Gerichtsstand: Amtsgericht Offenbach

        bar

        Diese Information ist ausschliesslich fuer den Adressaten bestimmt und
        kann vertraulich oder gesetzlich
        geschuetzte Informationen enthalten. Wenn Sie nicht der
        bestimmungsgemaesse Adressat sind, unterrichten
        Sie bitte den Absender und vernichten Sie diese Mail. Anderen als dem
        bestimmungsgemaessen Adressaten
        ist es untersagt, diese E-Mail zu lesen, zu speichern, weiterzuleiten
        oder ihren Inhalt auf welche Weise auch
        immer zu verwenden. Wir verwenden aktuelle Virenschutzprogramme. Fuer
        Schaeden, die dem Empfaenger
        gleichwohl durch von uns zugesandte mit Viren befallene E-Mails
        entstehen, schliessen wir jede Haftung aus.
        The information contained in this email is intended only for its
        addressee and may contain confidential and/or
        privileged information. If the reader of this email is not the intended
        recipient, you are hereby notified that
        reading, saving, distribution or use of the content of this email in any
        way is prohibited. If you have received
        this email in error, please notify the sender and delete the email. We
        use updated antivirus protection software
        We do not accept any responsibility for damages caused anyhow by viruses
        transmitted via email.

         

Log in to post a comment.