Using TwinPy with a remote target
You can also use TwinPy (and other pyads applications) remotely. In this scenario a client PC runs the GUI, interacting with a running TwinCAT instance on a target PC.
Using TwinPy remotely involves two steps:
Getting access to the compiled Simulink model’s XML file for the model structure
Making a remote ADS connection
Tip
Often in a target and client situation, the client is also the development PC (which compiles the TwinCAT solution for the target). When this is the case, giving access to the XML files for TwinPy is trivial since they already exist on the client computer.
Access to the XML file
When the client is not the computer that compiles the Simulink model, it won’t automatically have access to the most recent model XML. There are a few approaches:
- Compile the model also on the client PC
This will require all the compile dependencies on the client PC, and each compilation has to be done twice.
- Copy the XML from the compiled model to the client PC
No extra compilation is needed, but copying the XML each time can be time consuming.
- Set up a file share to give direct access to the compiled XMLs
By sharing the XMLs directly a client has access to the model structure without extra steps
Remote ADS connection
See the pyads documentation on routing for more information: https://pyads.readthedocs.io/en/latest/documentation/routing.html
Adding routes on Windows
Use the TwinCAT UI and add the remote. Right-click on the TwinCAT icon in the taskbar and click ‘Router…’ > ‘Edit Routes’.
This gif exemplifies the procedure:
The route must not be set to ‘unidirectional’, which seems to be the default.
Note that you might need to add allow-rules in the firewall for both inbound and outbound traffic on TCP ports 48898 and 8016, and UPD port 48899.
Adding routes on Linux
The pyads.connection.Connection
will create a route from the client to the target. You can then use
pyads.ads.add_route_to_plc()
to create a route back to the client. Or you can use the TwinCAT UI on the remote target
to create the route back.
TwinPy Remote
In your application script, set the IP address, AMS net id and port correctly for the remote target when
instantiating TwincatConnection
.
In case no local XML file is available, specify an absolute path to the XML file when creating a SimulinkModel
.