Hello,
I would like to thank you for all the work behind this repository.
Using the following code I was able to connect to S7 1214 PLC with ver 4.7. PUT/GET disabled and DB non-optimized. I was also able to read the parameter CountsTest in loop.
#1214 PLC- 214-1AG40-0XB0 H/W Ver 4.7.1 TIA Portal Ver 18 -- Filename: CleanDownload
DB is Non-optimized and PUT/GET is disabled
import struct
import time
from s7commplus import Client
PLC_IP = "192.168.1.1"
DB_NUMBER = 1 # Target Data Block
POLL_INTERVAL = 3 # Seconds between reads
def read_counts_test():
client = Client()
try:
print(f"Connecting to S7-1200 at {PLC_IP} via S7CommPlus...")
client.connect(PLC_IP, use_tls=True)
print("Connected!\n")
# 1. Fetch browse metadata (Done once before polling)
items = client.browse()
if not items:
print("No browse items found.")
return
item = items[0]
acc_seq = item.get('access_sequence', '')
tag_name = item.get('name', 'CountsTest')
# 2. Extract Variable LID
parts = acc_seq.split('.')
var_lid = int(parts[1], 16) if len(parts) > 1 else int(parts[0], 16)
# 3. Compute Access Area
access_area = 0x8A0E0000 + DB_NUMBER
print(f"Tag Name: {tag_name}")
print(f"Access Sequence: {acc_seq}")
print(f"Access Area: 0x{access_area:08X} ({access_area})")
print(f"Variable LID: {var_lid} (0x{var_lid:X})")
print("-" * 42)
print("Starting continuous polling (Press Ctrl+C to stop)...\n")
# 4. Continuous Read Loop
while True:
raw_val = client.read_symbolic(access_area, [var_lid])
if len(raw_val) >= 4:
dint_value = struct.unpack(">i", raw_val[-4:])[0]
timestamp = time.strftime("%H:%M:%S")
print(f"[{timestamp}] LIVE DINT VALUE ({tag_name}): {dint_value}")
else:
print(f"Received incomplete data (Length: {len(raw_val)})")
time.sleep(POLL_INTERVAL)
except KeyboardInterrupt:
print("\nPolling stopped by user.")
except Exception as e:
print(f"\nCommunication Error: {e}")
finally:
client.disconnect()
print("Disconnected.")
if name == "main":
read_counts_test()
However, when I use similar script to connect to S7 1511C PLC ver 2.1.0 to read a parameter it is throwing me error on connection itself. Same settings on this PLC. PUT/GET is disabled and DB is non-optimized. Error shown below.
=================================================================================== RESTART: C:/Users/Gaurav S Mithari/Desktop/===================================================================================
Testing S7 connection to 10.0.1.101...
Connection Error: Connection closed by peer
Connection closed.
The wireshark dump between TIA portal and 1511PLC shows no TLS communication. Only shows S7commplus, TCP and COTP.
Could you please help me on this.
Hello,
I would like to thank you for all the work behind this repository.
Using the following code I was able to connect to S7 1214 PLC with ver 4.7. PUT/GET disabled and DB non-optimized. I was also able to read the parameter CountsTest in loop.
#1214 PLC- 214-1AG40-0XB0 H/W Ver 4.7.1 TIA Portal Ver 18 -- Filename: CleanDownload
DB is Non-optimized and PUT/GET is disabled
import struct
import time
from s7commplus import Client
PLC_IP = "192.168.1.1"
DB_NUMBER = 1 # Target Data Block
POLL_INTERVAL = 3 # Seconds between reads
def read_counts_test():
client = Client()
if name == "main":
read_counts_test()
However, when I use similar script to connect to S7 1511C PLC ver 2.1.0 to read a parameter it is throwing me error on connection itself. Same settings on this PLC. PUT/GET is disabled and DB is non-optimized. Error shown below.
=================================================================================== RESTART: C:/Users/Gaurav S Mithari/Desktop/===================================================================================
Testing S7 connection to 10.0.1.101...
Connection Error: Connection closed by peer
Connection closed.
The wireshark dump between TIA portal and 1511PLC shows no TLS communication. Only shows S7commplus, TCP and COTP.
Could you please help me on this.