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 = 4 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()