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

Read bytes from Codesys runtime into external Python script

2017-02-23
2018-05-24
  • AndreasDeDeDe - 2017-02-23

    Hello there!

    I'd like to have a function in a python script, maybe looking like this:

    Β data = readBytesFromCodesys(someDataSourceIdentification) 
    

    with which i could read bytes from the Codesys runtime, for example, from a Profinet slave that runs in the currently running codesys Project.
    The best solution i came up with would involve writing and reading a shared file, and maybe synchronizing the data transfer between codesys and python via 4 GPIOs.
    is there another way to do this?

    Greetings

     
  • AndreasDeDeDe - 2017-02-27

    I have found a solution: Shared Memory. There is a free package to download from the codesys store, and for linux + python, google "posix_ipc" for a lib that implements shared memory in Python. There is example code on the download site. Also note, for ARM and Intel CPUs, you can use the shared memory without any mutexes. If you share the memory between only two processes (Here: codesys and my python script), and one only reads and the other only writes, they can do that asynchronously and simultaneously. For communicating into the other direction, just add another shared memory.

    Another possibility is modbus, but i didn't delve too deep into that subject.

     
  • efra-mx - 2018-05-23

    Hi,

    Could you share your example? I would like to do something similar but with C++
    It will be highly appreciated.

    Thanks

     

Log in to post a comment.