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 to set values with a Test Manager Python script

Bakkertje
2015-12-03
2015-12-04
  • Bakkertje - 2015-12-03

    How can I set values for testing with a Test Manager Python script?
    See the screen copy below this question.

    The next software is used: Codesys V3.5 SP7 Patch 2 and Test Manager 4.0.1.1.

    IMG: TestManager_SetValueWithPythonScript.PNG

     
  • mkeller - 2015-12-04

    Hi Bakkertje.

    Zitat:
    How can I set values for testing with a Test Manager Python script?

    What do you mean?

    If you want to set the value of a script variable you use an ASSIGNMENT. You can use it again if you want to change the value. For example, you want to call the same test script but with different values.

    If you want to set the value of an IEC variable on the PLC, you have to use one of the commands from TestManager.Monitoring or use the Scripting API in a test action with the command ExecuteScript from TestManager.Scripting.

    BR
    Martin

     
  • Bakkertje - 2015-12-04

    Hi Martin,

    Thanks for your reply.
    With the "CompareVariableList" I can compare more variables in one time. That gives a good overview.
    And with the "WriteVariable" I can set one variable value. Is there a way to set more variable values with one command?

     
  • mkeller - 2015-12-04

    Hi Bakkertje.

    Bakkertje hat geschrieben:
    And with the "WriteVariable" I can set one variable value. Is there a way to set more variable values with one command?

    You can use the Scripting API to prepare your values and send them to the PLC together. For example:

    onlineApp = online.create_online_application()
    onlineApp.set_prepared_value("PLC_PRG.iVal1", iSetValue1)
    onlineApp.set_prepared_value("PLC_PRG.iVal2", iSetValue2)
    globalVars = executionContext.GlobalVariables
    onlineApp.set_prepared_value("PLC_PRG.iVal2", globalVars["g_var1"])
    onlineApp.write_prepared_values()
    

    BR
    Martin

     
  • Bakkertje - 2015-12-04

    Hi Martin,

    Thanks, this is useful.
    I only have to convert the value to s string type with str() and it works.

    onlineApp.set_prepared_value("PLC_PRG.iVal1", str(iSetValue1))
    
     
  • mkeller - 2015-12-04

    Hi Bakkertje,

    you are absolutely right. I forgot to look at the API documentation. If you can't be sure that all the variables contain only strings the "str()" is necessary.

    BR
    Martin

     

Log in to post a comment.