python-3.xpymodbussiemens

Siemens Logo! 8 <-> pymodbus


Using Siemens Logo!Soft Comfort, I want to connect a Siemens Logo! (8) with pymodbus

Settings on a network input on siemens soft comfort (I also tried Unit ID 255 and Modbus Type "DI" (Digital input))

Settings on siemens soft comfort (I also tried Unit ID 255 and Modbus Type "DI" (Digital input))

Pc Settings, (I have tried both Interfaces) Pc Settings, (I have tried both Interfaces)

Pymodbus code:

import time

client = ModbusTcpClient('192.168.0.3')
print(client.connect())
while True:
    time.sleep(1)
    print(client.write_coil(1, True))
    time.sleep(1)
    print(client.write_coil(1, False))

The output:

True
Modbus Error: [Input/Output] [WinError 10054] An existing connection was forcibly closed by the remote host
Modbus Error: [Input/Output] [WinError 10054] An existing connection was forcibly closed by the remote host

Solution

  • There are two ways to connect to the Logo via PC, either with the Logo acting as a Modbus server or a Modbus client.

    LOGO! as a Modbus server:

    Add a server connection:

    enter image description here

    Leave the options completely empty:

    enter image description here

    You should then see a little yellow socket at the bottom of the logo:

    enter image description here

    No further configuration is needed (the Diagram Editor can be left empty)

    Push this configuration to the Logo:

    enter image description here

    Send modbus-tcp-messages to the Logo, as described in the original post. The coils to target are described in the Logo!-Settings (they start at 1, while pymodbus starts at 0, so you need to subtract 1: enter image description here enter image description here

    So if we want to turn on the Q1:

    from pymodbus.client.sync import ModbusTcpClient
    
    client = ModbusTcpClient('192.168.0.3') # Default port is 502
    client.write_coil(address=8192, value=True) # Default unit_id is 1
    

    LOGO! as Client

    Add a Client connection:

    enter image description here

    Enter the values you want to read:

    enter image description here

    Run a modbus server, see Documentation