1.修改部分代码风格,实现风格统一 2.添加数据刷新时间到config中 3.将html单独放到文件中并且添加一些相关说明
This commit is contained in:
@ -150,20 +150,18 @@ class Snap7Client:
|
||||
Returns:
|
||||
bool: 是否写入成功
|
||||
"""
|
||||
values = int(data)
|
||||
print("values:", values)
|
||||
value = bytearray(0)
|
||||
if isinstance(values, int):
|
||||
set_int(value, offset, values)
|
||||
data = value
|
||||
print(data)
|
||||
|
||||
if not self.connected and not self.connect():
|
||||
self.logger.warning(f"Write failed: not connected to {self.ip}")
|
||||
return False
|
||||
|
||||
try:
|
||||
with self.lock:
|
||||
values = int(data)
|
||||
value = bytearray(0)
|
||||
if isinstance(values, int):
|
||||
set_int(value, offset, values)
|
||||
data = value
|
||||
|
||||
self.client.db_write(db_number, offset, data)
|
||||
self.logger.debug(f"Wrote {len(data)} bytes to DB{db_number} offset {offset}")
|
||||
return True
|
||||
@ -210,21 +208,20 @@ class Snap7Client:
|
||||
Returns:
|
||||
bool: 是否写入成功
|
||||
"""
|
||||
data = data.decode('utf-8')
|
||||
# 将字符串安全转换为字典
|
||||
data_dict = ast.literal_eval(data) # 输出: {0: True}
|
||||
# value = bytearray(1)
|
||||
value = bytearray(offset+1)
|
||||
for bit, val in data_dict.items():
|
||||
set_bool(value, offset, bit, val)
|
||||
data = value
|
||||
if not self.connected and not self.connect():
|
||||
self.logger.warning(f"Write failed: not connected to {self.ip}")
|
||||
return False
|
||||
|
||||
try:
|
||||
with self.lock:
|
||||
print(db_number, offset, data)
|
||||
data = data.decode('utf-8')
|
||||
# 将字符串安全转换为字典
|
||||
data_dict = ast.literal_eval(data) # 输出: {0: True}
|
||||
value = bytearray(offset + 1)
|
||||
for bit, val in data_dict.items():
|
||||
set_bool(value, offset, bit, val)
|
||||
data = value
|
||||
|
||||
self.client.db_write(db_number, offset, data)
|
||||
self.logger.debug(f"Wrote {len(data)} bytes to DB{db_number} offset {offset}")
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user