将读取文件添加PLC的名字
This commit is contained in:
@ -30,6 +30,8 @@ class CacheManager:
|
||||
self.logger = logging.getLogger("CacheManager")
|
||||
self.init_cache()
|
||||
|
||||
|
||||
|
||||
def init_cache(self):
|
||||
"""初始化缓存结构"""
|
||||
for plc in self.config["plcs"]:
|
||||
@ -643,6 +645,8 @@ class CacheManager:
|
||||
plc_status = self.plc_connection_status.get(plc_name, "unknown")
|
||||
return None, "Area is read-only", plc_status, 0
|
||||
|
||||
cache_file = f"{plc_name}_area_{area_name}.log"
|
||||
|
||||
# 计算实际DB偏移
|
||||
db_offset = area["offset"] + offset
|
||||
|
||||
@ -669,7 +673,7 @@ class CacheManager:
|
||||
|
||||
try:
|
||||
# 使用Snap7Client的read_generic方法
|
||||
result = client.read_generic(area["db_number"], db_offset, data_type, count)
|
||||
result = client.read_generic(area["db_number"], db_offset, data_type, cache_file, count)
|
||||
if result is None:
|
||||
return None, "Read failed", plc_status, 0
|
||||
|
||||
@ -873,4 +877,5 @@ class CacheManager:
|
||||
"plc_connection_status": plc_status,
|
||||
"last_update": last_update,
|
||||
"last_update_formatted": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(last_update)) if last_update > 0 else "Never"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user