Modbus TCP connection between Codesys and Machine Simulator

Started by Jaime Fonseca, November 20, 2025, 04:20:41 PM

Previous topic - Next topic

Jaime Fonseca

Dear Sirs,
To test the operation of Modbus in Machine Simulator, I performed the following tests:

1st Test
Machine Simulator as Server with the configuration in image 1, and Codesys as the Client.

I tested Coils, Digital Inputs, Holding Registers, and Input Registers (analog inputs). Everything worked well; I only need to add one line of script to check whether the analog inputs were being received in Codesys.

2nd Test
Machine Simulator as Client with the configuration in image 2, and Codesys as the Server.

I tested Coils, Digital Inputs, Holding Registers, and Input Registers (analog inputs). I was not able, in any way, to get Machine Simulator to read the input registers sent by Codesys.
When testing with Modbus Poll as the client, I had no issues reading the same input registers written by Codesys.
If there is a known workaround or configuration adjustment that resolves this situation, I would appreciate any guidance.

Best regards

EasyPLC_Master

Hi Jaime!

When using the Client ModBus Driver, some considerations must be taken:

The ModBus client protocol do not allow to write in Digital Inputs or Analogue Inputs, for this reason, due the protocol for ModBus client treat these entities as read-only, Machines Simulator can not write on it.

In order to be able to write on Digital Inputs or Analogue Inputs, is necessary to use a ModBus protocol in Server mode.

Once this important point is clarified, I'll leave you with a couple of videos where you can see the Modbus driver in operation in client mode, where both digital and analog inputs and outputs are used.
This can serve as an example for you to learn how to configure your system.


----------------------------------------------------------------------------


Jaime Fonseca

Dear administrator,

I carefully watched the videos you sent, but they did not help me much with the problem I described. I will try to explain it better.

Please see image 2. In this image, you can see my environment in Machine Simulator and my Modbus Client configuration.
In image 1, you can see my configuration and programming in Codesys. It is very simple. Codesys is the server. In figure 1, you have the Modbus configuration. Machine Simulator and Codesys are running on the same machine.

In Figure 2, you can see the following:

The holding registers are inputs.

The input registers are outputs.

The coils are inputs.

The discrete inputs are outputs.

In Figure 3, you can see a very simple code — only assignments:

Valor_Coil receives the value of the digital input in Machine Simulator.

DiscreteValor sends the command to the digital output in Machine Simulator.

Valor_HoldingRegister receives the value of the analog output in Machine Simulator, but I need to include this line in the script:
IOManager.SetAInput(AI_entradaanalog_VALUE, 25.2f);
The variable Valor_HoldingRegister receives 25. That is OK and I understand why.

DiscreteInputValor — I change the value in Codesys, but the value of the analog input in Machine Simulator always remains unchanged.

If you can help me i appreciate.