Application Login via python

lvstrom
2021-01-04
2021-01-05
  • lvstrom

    lvstrom - 2021-01-04

    Hi,

    I trying to create a script in python which build the project and perform a download to the PLC.
    But when it tries to login an error occurs, that I do not know how to solve. See my attached picture.

    It only occurs when login via the script.

    I am using a Lenze PLC 3200C and Lenze PLC designer 3.21.
    This is my python code.

    from __future__ import print_function
    
    proj = projects.primary
    app = proj.active_application
    onlineapp = online.create_online_application(app)
    app.build()
    
    # Find device object
    found = proj.find('Device', False)
    assert(found and len(found) == 1, 'No or more than one device found')
    dev = found[0]
    
    print(dev.get_name())
    
    gws = online.gateways
    
    for gw in gws:
        if gw.name == 'Gateway-1':
            print(gw.name)
            break
    
    
    gw.perform_network_scan()
    
    PLC_address = gw.find_address_by_ip('192.168.17.10')
    dev.set_gateway_and_address('Gateway-1', PLC_address)
    
    onlineapp.login(OnlineChangeOption.Never, False)
    
    if not onlineapp.application_state == ApplicationState.run:
        print(onlineapp.application_state)
        onlineapp.start()
        print(onlineapp.application_state)
    

    Thanks and best regards
    Lars

     
    • Morberis

      Morberis - 2021-01-05

      Hopefully someone who knows sees this and can help. Unfortunately I don't have any experience in what you're trying to do so I just have some generic help, as well as what I've dug up doing my own google search.

      My first suggestion is to look on the Codesys Help page if you haven't done so already or if Lenze's IDE doesn't link to it. Looking at it myself it seems like this would be the relevant page within.

      I did find this post from someone trying to do something similar.

      If you can't get it figured out or don't have time to you will definately get your issue solved by purchasing a support ticket.

      Edit: I'm sorry, I tried clicking both "API Reference Documentation for the ScriptEngine" links and both lead to a blank page!

      I'll submit a bug report. In the meantime you might be able to find something by following these directions

      Before CODESYS V3.5 SP11 the ScriptEngine.chm was in the directory "Online Help" of the CODESYS installation path. With CODESYS V3.5 SP11 you can find in the file ScriptEngine.chm in the sub directory for the individual language of the directory "Online Help".
      
       

      Last edit: Morberis 2021-01-05

Log in to post a comment.