Simulink PIL using emulator and virtual ports

5 次查看(过去 30 天)
Hello,
I'm trying to do a PIL simulation in Simulink. My setup is as follows:
- Real World: A Simulink model that generates the synthetic measurements
- On Board: A Simulink model that implements the logic that will then be deployed into the board
- All Models: A top Simulink model that references the Real World and On Board models
Also, some DataDictionary are linked to the models, in particular:
-Real World is linked to RealWorldDD, which is set to have a variable step size solver to ensure the best results
-On board is linked to OnBoardDD, which is set to have a fixed step size solver
For the purposes of this question, let's assume a simple case in which the Real World model generates random numbers and the On Board model simply add 1 to the given value.
Unfortunately, I do not have the physical board on which I have to deploy the code, but I have an emulator installed in my PC and Simulink add-ons for my board do not exists.
In addition, I need to pass informations between simulink and the emulator.
My questions, in regards, are:
  • In the All Models, that is the top model, which solver shall I set? Should i link it to RealWorldDD or to OnBoardDD?
  • How do I setup the PIL Simulation given that I have an emulator of a board not natively supported by Simulink?
  • How can I create a connection between simulink and the emulator? Is it possible to create a virtual serial link?

回答(1 个)

Adit
Adit 2025-8-12
Hello Niccolò,
Here’s how you can approach PIL simulation in Simulink in your scenario:
1. Top Model Solver and Data Dictionary
  • Solver: Since your "On Board" model is intended for code generation and will run in a PIL loop (which requires a fixed-step solver), the top model ("All Models") should also use a fixed-step solver. This ensures correct timing and compatibility with the PIL process.
  • Data Dictionary: Link the top model to the OnBoardDD data dictionary. This keeps the simulation settings consistent with the code that will eventually run on your emulator.
2. Setting Up PIL Simulation with an Emulator
Since your board is not natively supported by Simulink and you have an emulator on your PC:
  • Code Generation: Use Embedded Coder to generate code from your "On Board" model.
  • Emulator Integration: Compile the generated code with your emulator toolchain, so the emulator can execute it.
  • PIL Configuration: Since there is no official Simulink support for your emulator, you need to set up a custom PIL connection. This involves configuring Simulink to communicate with your emulator using a standard protocol (like serial).
3. Connecting Simulink to the Emulator with a Virtual Serial Link
Yes, it is possible and common to use a virtual serial port:
  • Create a Virtual Serial Port Pair: Use tools like com0com (Windows) or socat (Linux/Mac) to create two linked virtual COM ports (e.g., COM5 and COM6).
  • Simulink Side: Configure Simulink (using its PIL custom target options or via S-Functions/MATLAB scripts) to use one end of the virtual port (e.g., COM5).
  • Emulator Side: Configure your emulator to use the other end (e.g., COM6) to send/receive data as if it were a physical board.
For more information, refer to the following MathWorks documentation links:

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by