Search code examples
twincat

How to get a return value from an external program into TwinCAT 3?


I am trying to get a single return value from an external user space program, which is started by TwinCAT, back into TwinCAT. I didn't manage to find anything on this forum or on Beckhoff's Infosys. I am not an experienced TwinCAT programmer.

The purpose is to do some fairly complex analysis and visualization in the external program, based on recorded data on file, and then let the operator decide whether to "continue" or "redo" based on the presented data. This operator decision would need to be read back into TwinCAT somehow, where it will determine what happens next.

Is there a way to achieve that?

One option would, of course, be for the operator to just close the external program window, and have the "continue" and "redo" selections in the TwinCAT HMI. But for future use, I would prefer to get a return value directly from the external program.

Thank you for any ideas and suggestions.


Solution

  • You could achieve this by ADS. Make your user-space program (in whatever language it's written to) writes the result back to the PLC using the ADS-protocol. You specifically need to do an write to an ADS-variable from the user-space application.

    Another variant is to do it the other way around, that you have your PLC do an ADS-read from the user-space application, though this is most likely a less optimal solution.

    Beckhoff's documentation about ADS: https://infosys.beckhoff.com/english.php?content=../content/1033/tcinfosys3/11291871243.html&id=

    And a free course about ADS: https://www.youtube.com/watch?v=JZChSdU2LMc