Call Pythonscript in Codesy 3.5 PLC code

dumpfbacke
2020-12-17
2020-12-20
  • dumpfbacke - 2020-12-17

    hi,

    its possible to call a pythonscript in Codesys 3.5 PLC code?

    Thanks, Dumpfbacke

     
  • hermsen

    hermsen - 2020-12-18

    It can be done if your Runtime is mostly Linux based and you have open access to the OS. Otherwise it cannot be done. Besides that it can be done, why do you want to do that?

     

    Last edit: hermsen 2020-12-18
    • dumpfbacke - 2020-12-19

      hi,
      my idea is to run a pythonprogram to read/write data into sql database.
      Fisrt step for me is try to execute pythonscript.
      Second step try to read tags vom codesysruntime with python, any idea wether this iss possible?

       
  • eschwellinger

    eschwellinger - 2020-12-18
     
    πŸ‘
    1
    • dumpfbacke - 2020-12-20

      hi,
      i tried now based to your sample run python script.
      My testpythonscript opens the broswer with goolgewebsite to see simple wether it works.

      i allowed commands in
      CODESYSControl_User.cfg and CODESYSControl.cfg
      with
      [SysProcess]
      Command=AllowAll

      i am not sure is runtime pi or root?

      I also made thr sccriptfile executable.
      i also copied the file int /var/opt/codesys similar your sample project.

      my coding is this:

      // Aktuelle CPU Frequenz lesen
      //command1:= 'vcgencmd measure_clock arm';
      //command1:= 'sudo python mytest.py';
      //command1:= 'sudo python /home/pi/mytest.py';
      //command1:= 'sudo python /var/opt/codesys/mytest.py';
      command1:= 'python /var/opt/codesys/mytest.py';
      
      IF bDummyBool THEN
          SysProcess.SysProcessExecuteCommand2(pszCommand:=command1, pszStdOut:=stdout1, udiStdOutLen:= SIZEOF(stdout1),pResult := ADR(Result));
          //bDummyBool := FALSE;
      END_IF;
      

      doesn not work, what i am doing wrong?
      Can you please amser once more
      Thanks

       

      Last edit: dumpfbacke 2020-12-20
  • eschwellinger

    eschwellinger - 2020-12-19

    .. in the same section (old examples) there is a python OPC UA client example to
    read symbols from the plc runtime

     
    πŸ‘
    1

Log in to post a comment.