Modbus and siemens S1200

Hello everybody,
i want to ask how is the correct code to comunicate with siemens s1200 PLC with modbus comunication. i need to improve a simple switch on home assistant and i commute a input on plc. and after that, i need to read the state of an output.
I use i modbus TCP…
Anyone help me?
please…
thankss

I suggest starting on the Siemens support web site to make sure you have the PLC configured correctly:

https://support.industry.siemens.com/forum/ww/en/posts/s7-modbus-tutorial-s7-1200-s7-1500-as-modbus-rtu-master-read-and-write-simultaneously/185491

https://support.industry.siemens.com/forum/WW/en/posts/s7-1200-modbus-tcp/32313