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

How is it possible enable and disable devices by script ?

Luke
2015-04-23
2015-04-27
  • Luke - 2015-04-23

    Hello everybody
    I need into a project to disable few device and enable some other using a Python script, but I’m a beginner with this language and I can’t find a solution.

    Someone could help me?
    Thank you

     
  • mkeller - 2015-04-23

    Hi Luke.

    Here my sample code:

    proj = projects.primary
    objs = proj.find('Device_1', recursive = True)
    assert(len(objs) == 1, 'no or more than one object found')
    assert(objs[0].is_device, 'object is not a device')
    device = objs[0]
    if device.is_enabled():
    Β  Β print('disable device...')
    Β  Β device.disable()
    else:
    Β  Β print('enable device...')
    Β  Β device.enable()
    

    BR
    Martin

     
  • Luke - 2015-04-23

    Thank You so much Martin
    Your code works fine
    Excuse a last question, something stupid, where can I find the syntax code integrated in Python to handle CoDeSys ? example 'is_device'

    BR
    Luke

     
  • mkeller - 2015-04-23

    Hi Luke.

    The documentation is in the file "ScriptEngine.chm" in the sub directory "Online Help" of CODESYS. It's not linked to the online help which you can reach directly from CODESYS.

    The scripting interface is in the book "_3S.CoDeSys.ScriptEngine.BasicFunctionality Namespace".

    BR
    Martin

     
  • Luke - 2015-04-27

    Thank You another time Martin

     

Log in to post a comment.