This repository was archived by the owner on Mar 16, 2023. It is now read-only.
forked from gijzelaerr/python-snap7
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogo_7_8.py
More file actions
53 lines (35 loc) · 1.22 KB
/
logo_7_8.py
File metadata and controls
53 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import logging
import snap7
# for setup the Logo connection please follow this link
# https://snap7.sourceforge.net/logo.html
logging.basicConfig(level=logging.INFO)
# Siemens LOGO devices Logo 8 is the default
Logo_7 = True
logger = logging.getLogger(__name__)
plc = snap7.logo.Logo()
plc.connect("192.168.0.41", 0x1000, 0x2000)
if plc.get_connected():
logger.info("connected")
# read I1 from logo
vm_address = ("V923.0" if Logo_7 else "V1024.0")
print(f"I1: {str(plc.read(vm_address))}")
# write some values in VM addresses between 0 and 100
value_1 = 0b10110001
value_2 = 480
print("write 0b10110001 to V10")
plc.write("V10", value_1)
print(f"read V10.0 must be 1 - check: {str(plc.read('V10.0'))}")
print(f"read V10.3 must be 0 - check: {str(plc.read('V10.3'))}")
print(f"read V10.7 must be 1 - check: {str(plc.read('V10.7'))}")
print("write 480 analog value to VW20")
plc.write("VW20", value_2)
print(f"read VW20 must be 480 - check: {str(plc.read('VW20'))}")
print("trigger V10.2")
plc.write("V10.2", 0)
plc.write("V10.2", 1)
plc.write("V10.2", 0)
else:
logger.error("Conncetion failed")
plc.disconnect()
logger.info("Disconnected")
plc.destroy()