1228
This commit is contained in:
@ -80,7 +80,7 @@ class TransmitterController:
|
||||
self.relay_controller.modbus_client.close()
|
||||
|
||||
# 直接读取 变送器返回的数据并解析
|
||||
def read_data_normal(self, transmitter_id):
|
||||
def read_data_sub(self, transmitter_id):
|
||||
|
||||
"""
|
||||
Args: transmitter_id 为1 表示上料斗, 为2 表示下料斗
|
||||
@ -90,7 +90,7 @@ class TransmitterController:
|
||||
BUFFER_SIZE= 1024
|
||||
IP = None
|
||||
PORT = None
|
||||
weight = 0
|
||||
weight = None
|
||||
if transmitter_id == 1:
|
||||
# 上料斗变送器的信息:
|
||||
IP = ini_manager.upper_transmitter_ip
|
||||
@ -102,7 +102,7 @@ class TransmitterController:
|
||||
|
||||
if not IP or not PORT:
|
||||
print(f"未配置变送器 {transmitter_id} 的IP或PORT")
|
||||
return 0
|
||||
return None
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
try:
|
||||
s.settimeout(TIMEOUT)
|
||||
@ -134,7 +134,7 @@ class TransmitterController:
|
||||
# 成功返回重量(int),失败返回None
|
||||
return weight
|
||||
|
||||
def read_data(self, transmitter_id):
|
||||
def read_data_sub_test(self, transmitter_id):
|
||||
|
||||
"""
|
||||
测试用:模拟读取变送器数据mock
|
||||
@ -266,4 +266,16 @@ class TransmitterController:
|
||||
except (IndexError, ValueError, UnicodeDecodeError) as e:
|
||||
# print(f"数据解析失败:{e},原始数据包:{packet_data}")
|
||||
return None
|
||||
|
||||
|
||||
def read_data(self,transmitter_id):
|
||||
"""获取重量函数:根据变送器ID获取当前重量,三次"""
|
||||
max_try_times=5
|
||||
try_times=0
|
||||
while try_times<max_try_times:
|
||||
weight=self.read_data_sub(transmitter_id)
|
||||
if weight is not None:
|
||||
return weight
|
||||
try_times+=1
|
||||
print(f'-----获取重量异常-------------- transmitter_id: {transmitter_id}')
|
||||
print(f'-----获取重量异常-------------- transmitter_id: {transmitter_id}')
|
||||
return None
|
||||
Reference in New Issue
Block a user