Can't import enums OnlineChangeOption / ResetOption

Jusito
2019-10-29
2024-04-11
  • Jusito - 2019-10-29

    Hello,

    I want to create a small snippet which opens the project, create a boot application, do a login and perform a cold reset. Codesys 3.5.14.1
    My problem is, that this 2 lines not working:

    from _3S.CoDeSys.OnlineUI.OnlineChangeOption import OnlineChangeOption
    from _3S.CoDeSys.Core.Online.ResetOption import ResetOption
    

    The error message is always: >Zitat:
    ImportError: No module named _3S.CoDeSys.OnlineUI.OnlineChangeOption (same with ResetOption)

    My Code:

    from _3S.CoDeSys.OnlineUI.OnlineChangeOption import OnlineChangeOption
    from _3S.CoDeSys.Core.Online.ResetOption import ResetOption
    proj = projects.open("D:\\Starterkit_RPi.project")
    app = proj.find("Application", True)
    onlineapp = online.create_online_application(app[0])
    \#_3S.CoDeSys.OnlineUI.OnlineChangeOption . OnlineChangeOption.Force = 2
    onlineapp.login(change_option=OnlineChangeOption.Force, delete_foreign_apps=True)
    \# _3S.CoDeSys.Core.Online.ResetOption . ResetOption.Cold = 1
    onlineapp.reset(reset_option=ResetOption.Cold, force_kill=True)
    onlineapp.start()
    proj.close()
    

    As a workaround I tried to use the int values, which results in error:

    TypeError: Cannot convert numeric value 2 to OnlineChangeOption.Β  The value must be zero.
    

    I saw some code here (a while ago, so cant provide a link) which is using the enums, so it should be possible. How can I use this enums?

    Thanks for your time!

    Edit solution:
    Looks like I made two mistakes:
    1. I have to use ```

    import scriptengine

    , where is the documentation for this module or the information that this one contains the enums? 2.

    OnlineChangeOption.Force

    isn't possible, only

    OnlineChangeOption.Never

    ```

     
  • thomaspfrimmer - 2024-04-11

    Hello Jusito,

    Can you share your final code, please ?

    I tried to implement a similar feature (going online, doing the reset and the start).
    But I get a timeout on the reset/start when I'm testing the script.
    If you got something working, I would appreciate to see it.

     

Log in to post a comment.