init: PLC data collection system
This commit is contained in:
commit
ae90bc9368
38 files changed
+5234
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import snap7
|
||||
|
||||
plc = snap7.client.Client()
|
||||
plc.connect('192.168.2.125', 0, 2)
|
||||
|
||||
print(f"PLC 连接状态: {plc.get_connected()}")
|
||||
|
||||
db_number = 1
|
||||
start_byte = 0
|
||||
byteoffset = 16
|
||||
|
||||
|
||||
data = bytearray(2)
|
||||
new_value = 3
|
||||
snap7.util.set_int(data, 0, new_value) # 修改字节数组
|
||||
plc.db_write(db_number, start_byte+byteoffset, data) # 写回PLC
|
||||
|
||||
data = plc.db_read(db_number, start_byte+byteoffset, 2)
|
||||
value = snap7.util.get_int(data, 0)
|
||||
print(value)
|
||||
|
||||
plc.disconnect()
|
||||
Reference in new issue
Block a user