1. Why does the openPLC read 0 instead of the actual value
Because you’re using the wrong address in your program. If you check the documentation on the OpenPLC project website about slave devices, you will see that slave devices attach to address 100 and above (i.e. %QX100.0). You can see the exact location your slave is attached on the slave devices page.
and what should I do to let the OpenPLC read the actual value?
Use the correct address.
Lastly, I am planning to replace the simulation with a Modbus slave script (using python3 and pymodbus) and would like to read an integer value. Should I use %IW0 or MW0?
Neither of those. If you’re reading an analog input (Modbus Input Register) then it will be %IW100 and up. You can also read Modbus registers (Modbus Holding Register) if you add them to the read section of your slave device configuration and they will also show up as %IW100 and up.
what type of encoding should the slave use to encode the int number in a way that can be read by OpenPLC ? Should I add any statement to the custom layer to decode the received value?
There is no encoding necessary. Modbus is a dead simple protocol. All registers are pure 16-bit numbers, not encoded in any format. If you’re using pymodbus, it will know what to do. You just have to provide the integer you want to send to pymodbus.