I have an existing project in Automation Studio 4.12 with all hardware modules configured.
For development and testing I would like to run the same project in ARSim and interact with the hardware IO from an external application such as Python or MATLAB.
The goal is to read and write the ARSim IO programmatically so that tests can be automated and hardware behavior can be simulated from outside the PLC application.
Ideally this should be a simple and fast way to simulate the system, similar to what can easily be done in MATLAB. For example it should be possible to inject signals, run simple simulations, or replay recorded data.
Are there recommended approaches to access or manipulate ARSim IO from an external tool when the project already contains configured hardware modules?
This would be my approach, but there are probably many other possibilities.
You could create a program to transfer I/O data to different places depending on if you’re in simulation or not. For example, say all of your I/O variables are in a global structure variable called gIO which has both inputs and outputs (gIO.Inputs and gIO.Outputs). All of your tasks use gIO to read/write I/O variables. You could then use a program (e.g., IOPrg) to populate gIO with either variables mapped to the I/O modules (e.g., IoChannels) or simulated variables (e.g., SimIo).
Such a program would look like this:
IF DiagCpuIsARSim() THEN
gIO.Inputs := SimIo.Inputs;
SimIo.Outputs := gIO.Outputs
ELSE
gIO.Inputs := IoChannels.Inputs;
IoChannels.Outputs := gIO.Outputs;
END_IF;
The advantage of this is that while you’re in sim, you can populate the SimIo variable from somewhere else (e.g., a Python script accessing it via OPC UA) and the data will be transferred to other programs like normal. You could also write programs in Automation Studio that access this simulated I/O structure without getting overwritten by the real I/O mappings.