Python Scripted Save_Archive with noUI

hermsen
2020-01-21
2023-05-15
  • hermsen

    hermsen - 2020-01-21

    EDIT :

    Dear support,

    Would you be so kind to post a working example of python code to save an archive while calling CODESYS.exe with --noUi option?

    Thank you in advance!

    EDIT

    Dear Forum,

    When we run a testscript embedded in the CODESYS IDE , we can call

    projects.primary.save_archive(path, name)
    

    and the script will save our project as an archive.
    When we run this same test script called agains the CODESYS IDE --noUI, the script fails and returns:

    Error: Object reference not set to an instance of an object
    

    With kind regards

     
  • mkeller - 2020-01-28

    Hi.

    Which version of CODESYS does throw the error?

    BR
    Martin

     
  • hermsen

    hermsen - 2020-01-28

    Hi,

    Currently we use 3.5.13.10

     
  • mkeller - 2020-01-29

    Hi.

    Does the error also occur with CODESYS 3.5.15.30?

    BR
    Martin

     
    • flow - 2020-06-25

      Hi Martin,
      I have the same problem with 3.5.15.20.
      The origin problem is, that the project will not open when I call

      "C:/Program Files/CODESYS 3.5.15.20/CODESYS/Common/CODESYS.exe" --Profile="CODESYS V3.5 SP15 Patch 2" --noUI --project="C:/.../COM/MQTT.library" --runscript="C:/.../Codesys/Test/UpdateScript.py"
      

      Without --noUI everything is fine. When I open the project within the script then also all is fine.

      from __future__ import print_function
      from scriptengine import *
      #import sys, os, time, shutil, logging
      import time
      
      ProjectPath = "C:/.../COM/MQTT.library"
      
      Project = projects.open(ProjectPath)
      print(Project)
      print(Project.library)
      system.exit(0)
      

      How to open the project within the call like without --noUI?

       

      Last edit: flow 2020-06-25
  • hermsen

    hermsen - 2020-01-29

    Hi,

    Sadly, we cannot use that version, because it is installed in a offline environment.

    Regards,

    Hermsen

     
  • vladilen - 2023-05-15

    Same problem with project save in version 3.5.19.0.
    A minimal example for reproducing:

    PS C:\codesys_test> cat .\save_test.py
    from scriptengine import *
    
    FILE_PATH = "C:\\codesys_test\\codesys_test.project"
    
    print("Opening")
    prj = projects.open(FILE_PATH)
    
    print("Saving")
    prj.save()
    
    
    PS C:\codesys_test> .\run.bat
    
    C:\codesys_test>"C:\Program Files\CODESYS 3.5.19.0\CODESYS\Common\CODESYS.exe" --Profile="CODESYS V3.5 SP19" --runscript="C:\codesys_test\save_test.py" --noUI
    Opening
    Saving
    Error: Running script 'C:\codesys_test\save_test.py' caused exception System.NullReferenceException: Traceback (most recent call last):
      File "C:\codesys_test\save_test.py", line 9, in <module>
    SystemError: Object reference not set to an instance of an object.
    

    The same without --noUI flag works fine

     

    Last edit: vladilen 2023-05-29

Log in to post a comment.