Hi Marco,
After spending several days learning PIL technology, I’ve realized that the communication speed mentioned in papers, like Baudrate or TCP speed, is not the most important factor. In PIL simulation, data needs to be transferred over 20,000 times per second. Based on my tests, I found that if the communication speed is sufficiently high, the pure communication time accounts for less than 10% or even 1% of the total simulation time. The most significant factor is actually the delay caused by the communication process on PC drivers and applications.
For serial communication on Windows PC, there is always an IOCTL_SERIAL_WAIT_ON_MASK period, which takes at least 2 ms for each data transfer. This means that if the control task executes 20,000 times in one second, over 40 seconds would be spent just on this WAIT event—while the entire simulation only lasts 50 seconds. Moreover, most serial drivers on Windows don’t even allow configuration of this setting. In such cases, you might end up waiting over 30 ms for each data transfer, making the simulation extremely slow.
As for TCP communication on Windows PC, there is a similar configuration issue like IOCTL_SERIAL_WAIT_ON_MASK . The solution was shared in my previous post. Additionally, inspired by AI, I discovered that setting TCP_NODELAY when opening the socket can significantly speed up the simulation! Today, I tested the buck example again, and with 100M TCP communication, the simulation took only 6 seconds to complete 1 second of simulation time ! Just by adding a few lines of code both in hostCommSockOpenConnection and targetCommSockOpenConnection function:
int flag = 1;
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&flag, sizeof(flag)) == SOCKET_ERROR)
{
LogError(("setsockopt TCP_NODELAY failed with error code %d", WSAGetLastError()));
}
I’m interested in using PIL because I find it very challenging to implement control mode transitions in simulation. For example, consider a grid-connected inverter that can also operate in island mode. The transition between grid-connected control and island control is difficult to realize using block diagrams. As you mentioned, SIL simulation can help with this transition. But what I really want is to test my control strategies on a real 5kW inverter. PIL can help me verify not only the control logic but also protection, communication, and other functionalities. The same code can then be directly applied to a real inverter design. Now I can confidently say that using TCP for PIL makes the simulation very fast—almost like a normal simulation—and I believe there’s no need for HIL testing just for software verification.
The only code I added to your OPIL framework is the snippet above. Since I’m not very familiar with Git procedures, you can easily add it yourself—it’s simple but makes a significant improvement. When you fix your technical issues, could you please help me check my tests? I would be very grateful.
Best regards