Commit 15402a79 authored by 方开's avatar 方开 🍔
Browse files

修复一个因为接收超时引发的异常

parent 1c76fb1e
......@@ -13,6 +13,8 @@ from common.filePath.filePath import logging
monkey.patch_all()
# 根据仓房类型不同对温度、空气温湿度、虫害、气体、通风控制数据作解析,水份类型数据直接全部返回
def checkData(data: bytes, houseType: str, measureType: str, pointnum):
# 收到的所有数据用小写表示便于处理
data = b2a_hex(data).decode().lower()
......@@ -166,7 +168,7 @@ def checkData(data: bytes, houseType: str, measureType: str, pointnum):
def measureClient(sendAddr, cmd, measureType, houseType="multi", pointnum=None, timeout=50):
try:
# 设置一个带有超时异常的tcp客户端
with gevent.Timeout(timeout, False) as timeout:
with gevent.Timeout(timeout, exception=TimeoutError):
tcpSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
logging.info(f"正在向{sendAddr}发送指令{cmd}")
tcpSocket.connect(sendAddr)
......
......@@ -119,10 +119,9 @@ def checkData(data: bytes, houseType: str, measureType: str, pointnum):
if crcValue == crc16s(tempData):
tempData = data[14:-4]
realTemp = []
# 对温度数据进行解析处理
for i in range(0, len(tempData), 4):
if i[0] == "8":
tempValue = int(i[1:], 16) / 10
if tempData[i] == "8":
tempValue = int(tempData[i+1:i+4], 16) * 0.0625
realTemp.append(tempValue)
else:
realTemp.append(None)
......@@ -165,7 +164,7 @@ def checkData(data: bytes, houseType: str, measureType: str, pointnum):
def measureClient(sendAddr, cmd, measureType, houseType="multi", pointnum=None, timeout=50):
try:
# 设置一个带有超时异常的tcp客户端
with gevent.Timeout(timeout, False) as timeout:
with gevent.Timeout(timeout, exception=TimeoutError):
tcpSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
logging.info(f"正在向{sendAddr}发送指令{cmd}")
tcpSocket.connect(sendAddr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment