generated from zhangwei/Train_Identify
683 lines
32 KiB
Python
683 lines
32 KiB
Python
import time
|
||
|
||
from service.interfaceToWeb import interfaceToWeb
|
||
from service.TagsList import TagsList, plc_info
|
||
from utils.Tool import logger, config, PLC_Tool
|
||
|
||
plcInfo = plc_info()
|
||
|
||
# 定量仓 实时状态 0-等待卸料、1-卸料、2-给料、3-等待操作台启动、4-读取重量、5-停止装载、6-已完成
|
||
houseStatus: int = -1
|
||
|
||
|
||
def writePLC(ip: str, slot: int = 0, tags=None):
|
||
if tags is None:
|
||
return False, "参数tags未写入需要修改的标签点位"
|
||
|
||
if not isinstance(tags, list):
|
||
return False, "参数tags应该是一个[{key:value},{key2:value2}]的格式"
|
||
|
||
if len(tags) < 1:
|
||
return False, "参数tags未写入需要修改的标签点位"
|
||
|
||
plc = PLC_Tool(ip, slot)
|
||
|
||
plc.batch_write_tag(tags)
|
||
|
||
return True
|
||
|
||
|
||
def read_loading_tags(tagsList, plc):
|
||
"""
|
||
读取【所有股道】PLC装车实时点位
|
||
:param tagsList: 点位列表
|
||
:param plc: PLC读取对象
|
||
:return: 错误信息
|
||
"""
|
||
|
||
if len(tagsList.getLoading_Tags()) < config.track_num:
|
||
logger.error("股道数量与PLC点位套数不一致!")
|
||
return False
|
||
for track in range(config.track_num):
|
||
logger.debug("")
|
||
logger.debug("------ 股道%d ------", track + 1)
|
||
|
||
loadingTagsNamelist = [loading_Tag_list[0] for loading_Tag_list in tagsList.getLoading_Tags()[track]]
|
||
loadingTagslist = [loading_Tag_list[1] for loading_Tag_list in tagsList.getLoading_Tags()[track]]
|
||
|
||
success, msg, tags_value = plc.get_tags(loadingTagslist)
|
||
if success:
|
||
index: int = 0
|
||
tag_dict = {}
|
||
for tag in tags_value:
|
||
# if loadingTagsNamelist[index] == "pre_reading_gross" \
|
||
# and len(plcInfo.loadingDict_List) > track:
|
||
# print("---", loadingTagsNamelist[index], plcInfo.loadingDict_List[track][loadingTagsNamelist[index]] != tag["value"], (tag["value"] == 1))
|
||
# 完成配煤时,记录标志,准备读取毛重(读取两次,一次是配煤完成;一次是配煤完成后开始放料)
|
||
if loadingTagsNamelist[index] == "pre_reading_gross" \
|
||
and len(plcInfo.loadingDict_List) > track \
|
||
and loadingTagsNamelist[index] in plcInfo.loadingDict_List[track].keys() \
|
||
and plcInfo.loadingDict_List[track][loadingTagsNamelist[index]] != tag["value"] \
|
||
and tag["value"] == 1:
|
||
tag_dict["read_gross_weight_%d_type_1" % (track + 1)] = True
|
||
if loadingTagsNamelist[index] == "gate_open_type" \
|
||
and len(plcInfo.loadingDict_List) > track \
|
||
and loadingTagsNamelist[index] in plcInfo.loadingDict_List[track].keys() \
|
||
and plcInfo.loadingDict_List[track][loadingTagsNamelist[index]] != tag["value"] \
|
||
and tag["value"] == 1:
|
||
tag_dict["read_gross_weight_%d_type_2" % (track + 1)] = True
|
||
# 开始配煤时,记录标志,准备读取掐煤量
|
||
# 注意:此处之前用 completion_coal_blending_type 从true变为false判断该读掐煤量,后发现PLC在点击“配煤重读”时,此值不准确跳动
|
||
# 故 改为 start_coal_blending_type 从false变为true时读取;效果会比前者稍慢
|
||
if loadingTagsNamelist[index] == "start_coal_blending_type" \
|
||
and len(plcInfo.loadingDict_List) > track \
|
||
and loadingTagsNamelist[index] in plcInfo.loadingDict_List[track].keys() \
|
||
and plcInfo.loadingDict_List[track][loadingTagsNamelist[index]] != tag["value"] \
|
||
and tag["value"] == 0:
|
||
tag_dict["read_pinch_coal_quantity_%d_type" % (track + 1)] = True
|
||
|
||
tag_dict[loadingTagsNamelist[index]] = tag["value"]
|
||
logger.debug("股道%d- %s : %s", (track + 1), loadingTagsNamelist[index], tag["value"])
|
||
|
||
index += 1
|
||
|
||
if len(plcInfo.loadingDict_List) > track:
|
||
plcInfo.loadingDict_List[track] = tag_dict
|
||
else:
|
||
plcInfo.loadingDict_List.append(tag_dict)
|
||
else:
|
||
logger.error(msg)
|
||
return False
|
||
|
||
|
||
pinch_coal_tag = tagsList.getPinchCoalQuantity_Tag()[track]
|
||
if len(pinch_coal_tag) == 0:
|
||
logger.error("股道%d- 掐煤标签读取失败!请检查配置文件!", track + 1)
|
||
return False
|
||
success, msg, tags_value = plc.get_array(pinch_coal_tag[1], int(pinch_coal_tag[3]))
|
||
if success:
|
||
if len(plcInfo.pinchCoalQuantityList_List) > track:
|
||
plcInfo.pinchCoalQuantityList_List[track] = tags_value["value"][int(pinch_coal_tag[2]):]
|
||
else:
|
||
plcInfo.pinchCoalQuantityList_List.append(tags_value["value"][int(pinch_coal_tag[2]):])
|
||
logger.debug("股道%d- %s : %s", (track + 1), pinch_coal_tag[1], tags_value["value"][int(pinch_coal_tag[2]):])
|
||
else:
|
||
logger.error(msg)
|
||
return False
|
||
|
||
gross_weight_tag = tagsList.getGrossWeight_Tags()[track]
|
||
if len(gross_weight_tag) == 0:
|
||
logger.error("股道%d- 毛重标签读取失败!请检查配置文件!", track + 1)
|
||
return False
|
||
success, msg, tags_value = plc.get_array(gross_weight_tag[1], int(gross_weight_tag[3]))
|
||
if success:
|
||
if len(plcInfo.grossWeightList_List) > track:
|
||
plcInfo.grossWeightList_List[track] = tags_value["value"][int(gross_weight_tag[2]):]
|
||
else:
|
||
plcInfo.grossWeightList_List.append(tags_value["value"][int(gross_weight_tag[2]):])
|
||
logger.debug("股道%d- %s : %s", (track + 1), pinch_coal_tag[1], tags_value["value"][int(gross_weight_tag[2]):])
|
||
else:
|
||
logger.error(msg)
|
||
return False
|
||
|
||
return True
|
||
|
||
|
||
def read_preload_tags(tagsList, plc):
|
||
"""
|
||
读取PLC预装量参数
|
||
:param tagsList: 点位列表
|
||
:param plc: PLC读取对象
|
||
:return: 错误信息
|
||
"""
|
||
pre_load_weight_Tags = tagsList.getPreLoadWeight_Tags()
|
||
for track in range(len(pre_load_weight_Tags)):
|
||
if len(pre_load_weight_Tags[track]) == 0:
|
||
logger.error("股道%d- 预装量标签读取失败!请检查配置文件!", track + 1)
|
||
return False
|
||
success, msg, tags_value = plc.get_array(pre_load_weight_Tags[track][1], pre_load_weight_Tags[track][3])
|
||
if success:
|
||
plcInfo.preLoadWeightList_List.append(tags_value["value"][pre_load_weight_Tags[track][2]:])
|
||
else:
|
||
logger.error(msg)
|
||
return msg
|
||
|
||
|
||
def read_belt_tags(tagsList, plc):
|
||
"""
|
||
读取PLC 皮带启动状态点位
|
||
:param tagsList: 点位列表
|
||
:param plc: PLC读取对象
|
||
:return: 错误信息
|
||
"""
|
||
tags_list_name = [tag_list[0] for tag_list in tagsList.getBeltStartTags()]
|
||
tags_list = [tag_list[1] for tag_list in tagsList.getBeltStartTags()]
|
||
|
||
# logger.warn(list(tags_dict.keys()))
|
||
success, msg, tags_value = plc.get_tags(tags_list)
|
||
if success:
|
||
type_change = []
|
||
index: int = 0
|
||
for tag in tags_value:
|
||
if plcInfo.belt_start_dict.get(tags_list_name[index], None) != tag["value"]:
|
||
type_change.append({"deviceType": 1,
|
||
"deviceCode": tags_list_name[index],
|
||
"actionType": int(tag["value"]),
|
||
"actionTime": time.strftime('%Y-%m-%d %H:%M:%S')})
|
||
plcInfo.belt_start_dict[tags_list_name[index]] = tag["value"]
|
||
# logger.debug("%s : %s", tags_list_name[index], tag["value"])
|
||
|
||
index += 1
|
||
else:
|
||
logger.error(msg)
|
||
return ""
|
||
|
||
return type_change
|
||
|
||
|
||
def read_feeder_tags(tagsList, plc):
|
||
"""
|
||
读取PLC 给煤机启动状态点位
|
||
:param tagsList: 点位列表
|
||
:param plc: PLC读取对象
|
||
:return: 错误信息
|
||
"""
|
||
tags_list_name = [tag_list[0] for tag_list in tagsList.getFeederStartTags()]
|
||
tags_list = [tag_list[1] for tag_list in tagsList.getFeederStartTags()]
|
||
|
||
# logger.warn(list(tags_dict.keys()))
|
||
success, msg, tags_value = plc.get_tags(tags_list)
|
||
if success:
|
||
type_change = []
|
||
index: int = 0
|
||
for tag in tags_value:
|
||
if plcInfo.feeder_start_dict.get(tags_list_name[index], None) != tag["value"]:
|
||
type_change.append({"deviceType": 2,
|
||
"deviceCode": tags_list_name[index],
|
||
"actionType": int(tag["value"]),
|
||
"actionTime": time.strftime('%Y-%m-%d %H:%M:%S')})
|
||
plcInfo.feeder_start_dict[tags_list_name[index]] = tag["value"]
|
||
# logger.debug("%s : %s", tags_list_name[index], tag["value"])
|
||
|
||
index += 1
|
||
else:
|
||
logger.error(msg)
|
||
return ""
|
||
|
||
return type_change
|
||
|
||
|
||
def readPLC(plc):
|
||
"""
|
||
读取PLC的点位
|
||
:param plc: 连接的PLC对象
|
||
:return:
|
||
"""
|
||
|
||
tagsList = TagsList()
|
||
read_result = read_loading_tags(tagsList, plc)
|
||
if not read_result:
|
||
return False, []
|
||
belt_change_type = read_belt_tags(tagsList, plc)
|
||
feeder_change_type = read_feeder_tags(tagsList, plc)
|
||
|
||
return True, [*belt_change_type, *feeder_change_type]
|
||
|
||
|
||
def upload_load_type(loadingDict: dict):
|
||
statusList = [
|
||
"配煤完成,等待卸料",
|
||
"卸料",
|
||
"给料",
|
||
"等待操作台启动",
|
||
"读取重量",
|
||
"停止装载",
|
||
"已完成"
|
||
]
|
||
|
||
if loadingDict.get("completion_coal_blending_type", False) is True \
|
||
and loadingDict.get("gate_open_type", False) is False:
|
||
# 配煤完成 并且 闸板未打开 此为 等待卸料
|
||
return 0, statusList[0]
|
||
elif loadingDict.get("completion_coal_blending_type", False) is True \
|
||
and loadingDict.get("gate_open_type", False) is True:
|
||
return 1, statusList[1]
|
||
elif loadingDict.get("start_coal_blending_type", False) is True:
|
||
return 2, statusList[2]
|
||
elif loadingDict.get("load_system_open", False) is False \
|
||
and loadingDict.get("report_open_type", False) is True:
|
||
return 5, statusList[5]
|
||
elif loadingDict.get("report_open_type", False) is False:
|
||
return 6, statusList[6]
|
||
else:
|
||
return -1, ""
|
||
|
||
|
||
def interval_read_PLC_up_web():
|
||
"""
|
||
循环读取PLC数据 根据条件上传至WEB
|
||
:return:
|
||
"""
|
||
plc = PLC_Tool(config.ip_address, config.slot)
|
||
interface = interfaceToWeb()
|
||
login_result, token_type, access_token = interface.loginWeb(config.login_web_url, config.username,
|
||
config.password, config.authorization)
|
||
|
||
while True:
|
||
up_result = ""
|
||
start_time = time.time()
|
||
load_result, flag_changeds = readPLC(plc)
|
||
end_time = time.time()
|
||
# print(end_time, "运行时长:%3.f \n" % (end_time - start_time))
|
||
if not load_result:
|
||
time.sleep(30)
|
||
continue
|
||
|
||
if login_result is not "":
|
||
logger.warn(login_result)
|
||
return
|
||
|
||
for track in range(config.track_num):
|
||
loadingDict = plcInfo.loadingDict_List[track]
|
||
grossWeightList = plcInfo.grossWeightList_List[track]
|
||
pinchCoalQuantityList = plcInfo.pinchCoalQuantityList_List[track]
|
||
|
||
if loadingDict.get("report_open_type", False) is True:
|
||
|
||
logger.debug("股道%d- 判定上传掐煤-> %s", track+1,
|
||
(loadingDict.get("read_pinch_coal_quantity_%d_type" % (track+1), False) is True))
|
||
logger.debug("股道%d- 判定第1次上传毛重-> %s", track+1,
|
||
(loadingDict.get("read_gross_weight_%d_type_1" % (track + 1), False) is True))
|
||
logger.debug("股道%d- 判定第2次上传毛重-> %s", track+1,
|
||
(loadingDict.get("read_gross_weight_%d_type_2" % (track + 1), False) is True))
|
||
|
||
if loadingDict.get("read_pinch_coal_quantity_%d_type" % (track+1), False) is True \
|
||
or (
|
||
loadingDict.get("loading_carriage_order", -1) == loadingDict.get("total_number_carriage", -2)
|
||
and loadingDict.get("load_system_open", True) is False
|
||
and loadingDict.get("completion_coal_blending_type", True) is False):
|
||
loadingDict["read_pinch_coal_quantity_%d_type" % (track+1)] = False
|
||
|
||
if loadingDict["loading_carriage_order"] == 0:
|
||
logger.warn("获取到掐煤量,但是车节号为0,取消上传")
|
||
continue
|
||
if config.upload_type == 1:
|
||
up_result = interface.upload_pinch_coal(config.upload_pinch_coal_url,
|
||
time.strftime('%Y-%m-%d %H:%M:%S'),
|
||
loadingDict["loading_carriage_order"],
|
||
pinchCoalQuantityList[
|
||
loadingDict["loading_carriage_order"]-1],
|
||
str(track+1))
|
||
logger.info(
|
||
"股道%d- 获取到第%d节车厢的掐煤数:%2.f 千克" % (
|
||
(track+1), loadingDict["loading_carriage_order"],
|
||
pinchCoalQuantityList[loadingDict["loading_carriage_order"]-1]))
|
||
|
||
if loadingDict.get("read_gross_weight_%d_type_1" % (track + 1), False) is True:
|
||
loadingDict["read_gross_weight_%d_type_1" % (track + 1)] = False
|
||
if loadingDict["loading_carriage_order"] == 0:
|
||
logger.warn("获取到装车毛重,但是车节号为0,取消上传")
|
||
continue
|
||
if config.upload_type == 1:
|
||
up_result = interface.upload_gross_weight(config.upload_gross_weight_url,
|
||
time.strftime('%Y-%m-%d %H:%M:%S'),
|
||
loadingDict["loading_carriage_order"],
|
||
float(loadingDict.get("real_weight",
|
||
0)) * 1000.0,
|
||
str(track+1))
|
||
logger.info(
|
||
"股道%d- 获取到第%d节车厢的预计毛重值:%2.f 千克" % (
|
||
(track+1), loadingDict["loading_carriage_order"],
|
||
float(loadingDict.get("real_weight", 0)) * 1000.0))
|
||
|
||
if loadingDict.get("read_gross_weight_%d_type_2" % (track + 1), False) is True \
|
||
and loadingDict.get("completion_coal_blending_type", False) is True:
|
||
loadingDict["read_gross_weight_%d_type_2" % (track + 1)] = False
|
||
if loadingDict["loading_carriage_order"] == 0:
|
||
logger.warn("获取到装车毛重,但是车节号为0,取消上传")
|
||
continue
|
||
if config.upload_type == 1:
|
||
up_result = interface.upload_gross_weight(config.upload_gross_weight_url,
|
||
time.strftime('%Y-%m-%d %H:%M:%S'),
|
||
loadingDict["loading_carriage_order"],
|
||
grossWeightList[
|
||
loadingDict["loading_carriage_order"]-1],
|
||
str(track+1))
|
||
logger.info(
|
||
"股道%d- 获取到第%d节车厢的实际毛重值:%2.f 千克" % (
|
||
(track+1), loadingDict["loading_carriage_order"],
|
||
grossWeightList[loadingDict["loading_carriage_order"]-1]))
|
||
|
||
if loadingDict.get("gross_weight_refresh", 0) > 0:
|
||
if loadingDict["loading_carriage_order"] == 0:
|
||
logger.warn("获取到配煤重读毛重,但是车节号为0,取消上传")
|
||
continue
|
||
if config.upload_type == 1:
|
||
up_result = interface.upload_gross_weight(config.upload_gross_weight_url,
|
||
time.strftime('%Y-%m-%d %H:%M:%S'),
|
||
loadingDict["loading_carriage_order"],
|
||
loadingDict.get("gross_weight_refresh", 0),
|
||
str(track+1))
|
||
logger.info(
|
||
"股道%d- 获取到第%d节车厢的配煤重读毛重值:%2.f 千克" % (
|
||
(track+1), loadingDict["loading_carriage_order"],
|
||
loadingDict.get("gross_weight_refresh", 0)))
|
||
|
||
plc = PLC_Tool(config.ip_address, config.slot)
|
||
|
||
grossrefresh_Tag = ""
|
||
for grossrefresh_l in TagsList().getLoading_Tags()[track]:
|
||
if grossrefresh_l[0] == "gross_weight_refresh" and len(grossrefresh_l) > 1:
|
||
grossrefresh_Tag = grossrefresh_l[1]
|
||
if grossrefresh_Tag == "":
|
||
logger.error("股道%d- 配煤重读点位读取失败 !!!", (track + 1))
|
||
success, msg = plc.write_tag(grossrefresh_Tag, 0)
|
||
|
||
if not success:
|
||
logger.error("股道%d- 配煤重读归零失败 !!!", (track+1))
|
||
|
||
if up_result != "":
|
||
logger.warn(up_result)
|
||
|
||
status, status_str = upload_load_type(loadingDict)
|
||
|
||
if status != -1 and "loading_carriage_order" in loadingDict.keys():
|
||
global houseStatus
|
||
if houseStatus != status:
|
||
houseStatus = status
|
||
if config.upload_type == 1:
|
||
up_result = interface.update_load_type(config.upload_gross_weight_url,
|
||
time.strftime('%Y-%m-%d %H:%M:%S'),
|
||
loadingDict["loading_carriage_order"],
|
||
houseStatus,
|
||
str(track+1))
|
||
logger.info(
|
||
"股道%d- 装车状态变化:%d-%s" % ((track+1), houseStatus, status_str))
|
||
|
||
if up_result != "":
|
||
logger.warn(up_result)
|
||
|
||
if len(flag_changeds) > 0:
|
||
if config.upload_type == 1:
|
||
up_result = interface.upload_device_type(config.upload_device_type_url,
|
||
flag_changeds)
|
||
logger.info(
|
||
"股道%d- 皮带给煤机状态变化:%s" % ((track+1), str(flag_changeds)))
|
||
|
||
if up_result != "":
|
||
logger.warn(up_result)
|
||
|
||
logger.debug("")
|
||
time.sleep(config.interval_plc / 1000)
|
||
|
||
|
||
def report_open(pound_no: str, total_number_carriage: int, pre_load: list):
|
||
"""
|
||
启动PLC报表
|
||
:param pound_no: 股道名
|
||
:param total_number_carriage: 总车节数
|
||
:param pre_load: 预装量
|
||
:return: [响应码:int, 提示信息:str, 结构数据:obj]
|
||
"""
|
||
over_write = False
|
||
old_total_number_carriage = 0
|
||
old_pre_load = [0] * config.carriage_num_max
|
||
|
||
if pound_no is None:
|
||
return 412, 'no pound_no', {}
|
||
if isinstance(pound_no, str) and not pound_no.isdigit():
|
||
return 412, "pound_no should be a int and 0 <= track < 2", {}
|
||
if not (0 < int(pound_no) <= 2):
|
||
return 412, "pound_no should be a int and 0 < track <= 2", {}
|
||
if total_number_carriage == 0:
|
||
return 412, 'no total_number_carriage', {}
|
||
if isinstance(total_number_carriage, str) and not total_number_carriage.isdigit():
|
||
return 412, "total_number_carriage should be a int and > 0", {}
|
||
if not pre_load:
|
||
return 412, 'no pre_load', {}
|
||
if not isinstance(pre_load, list):
|
||
return 412, '\"pre_load\" It should be of list type', {}
|
||
if not all(isinstance(item, int) and item >= 0 for item in pre_load):
|
||
return 412, '\"pre_load\" It should be of list[int,int,...] type and every pre_load >= 0', {}
|
||
if int(total_number_carriage) != len(pre_load):
|
||
return 412, '\'total_number_carriage\' should be the same length as the list \'pre_load\'', {}
|
||
|
||
pound_no = int(pound_no)
|
||
if pound_no > config.track_num:
|
||
return 412, '开启报表的股道号超过当前设置的股道数量,请检查配置', {}
|
||
|
||
total_number_carriage = int(total_number_carriage)
|
||
tagsList = TagsList()
|
||
loadingTagsList = tagsList.getLoading_Tags()[pound_no-1]
|
||
|
||
report_open_type_tag = 0
|
||
total_number_carriage_tag = 0
|
||
for tag_list in loadingTagsList:
|
||
if tag_list[0] == "report_open_type":
|
||
report_open_type_tag = tag_list[1]
|
||
elif tag_list[0] == "total_number_carriage":
|
||
total_number_carriage_tag = tag_list[1]
|
||
|
||
plc = PLC_Tool(config.ip_address, config.slot)
|
||
if "report_open_type" in plcInfo.loadingDict_List[pound_no-1].keys() and plcInfo.loadingDict_List[pound_no-1]["report_open_type"] == 1:
|
||
over_write = True
|
||
old_total_number_carriage = plcInfo.loadingDict_List[pound_no-1]["total_number_carriage"]
|
||
|
||
success, msg, tags_value = plc.get_array(tagsList.getPreLoadWeight_Tags()[pound_no-1][1], tagsList.getPreLoadWeight_Tags()[pound_no-1][3])
|
||
|
||
if success:
|
||
old_pre_load = tags_value["value"]
|
||
|
||
success, msg, results = \
|
||
plc.batch_write_tag([(report_open_type_tag, 1),
|
||
(total_number_carriage_tag, total_number_carriage)])
|
||
|
||
if not success:
|
||
return 412, msg, {}
|
||
else:
|
||
if success > 1:
|
||
return 417, msg, results
|
||
# else:
|
||
# return responseMsg(200, msg, results)
|
||
|
||
# 数字下标0 都不用(同毛重、掐煤量)
|
||
pre_load.insert(0, 0.0)
|
||
logger.info("股道%d- 总车节数:%d 上传预装量:%s", pound_no, total_number_carriage, str(pre_load))
|
||
|
||
success, msg = plc.write_array("AI.load", pre_load)
|
||
if not success:
|
||
return 412, msg, {}
|
||
|
||
if over_write:
|
||
if old_total_number_carriage != total_number_carriage and old_total_number_carriage != 0:
|
||
logger.warn(
|
||
"股道%d- 【开启PLC报表】疑似更新装车总节数! 输入的车厢总数为%d节,而原PLC中的车厢总数为%d节;当前在装车厢为第%d节",
|
||
pound_no,
|
||
total_number_carriage, old_total_number_carriage,
|
||
plcInfo.loadingDict_List[pound_no-1]["loading_carriage_order"])
|
||
|
||
if old_pre_load != pre_load and old_pre_load != [0] * config.carriage_num_max:
|
||
logger.warn(
|
||
"【开启PLC报表】疑似更新装车预装量! 输入的车厢总数为%d节" % total_number_carriage)
|
||
|
||
if plcInfo.loadingDict_List[pound_no-1]["loading_carriage_order"] == plcInfo.loadingDict_List[pound_no-1]["total_number_carriage"]:
|
||
logger.warn(
|
||
"股道%d- 【开启PLC报表】疑似装最后一节时更新装车数据! 输入的车厢总数为%d节,而原PLC中的车厢总数为%d节;当前在装车厢为第%d节",
|
||
pound_no,
|
||
total_number_carriage, plcInfo.loadingDict_List[pound_no-1]["total_number_carriage"],
|
||
plcInfo.loadingDict_List[pound_no-1]["loading_carriage_order"])
|
||
else:
|
||
logger.info("【开启PLC报表】")
|
||
|
||
return 200, msg, results
|
||
|
||
|
||
def report_close(pound_no: str, total_number_carriage: int):
|
||
"""
|
||
关闭PLC报表
|
||
:param pound_no: 股道名
|
||
:param total_number_carriage: 总车节数
|
||
:return: [响应码:int, 提示信息:str, 结构数据:obj]
|
||
"""
|
||
if pound_no is None:
|
||
return 412, 'no pound_no', {}
|
||
if isinstance(pound_no, str) and not pound_no.isdigit():
|
||
return 412, "pound_no should be a int and 0 < track <= 2", {}
|
||
if not (0 < int(pound_no) <= 2):
|
||
return 412, "pound_no should be a int and 0 < track <= 2", {}
|
||
if total_number_carriage == 0:
|
||
return 412, 'no total_number_carriage', {}
|
||
if (isinstance(total_number_carriage, str) and not total_number_carriage.isdigit()) \
|
||
or int(total_number_carriage) <= 0:
|
||
return 412, "total_number_carriage should be a int and > 0", {}
|
||
|
||
pound_no = int(pound_no)
|
||
if pound_no > config.track_num:
|
||
return 412, '开启报表的股道号超过当前设置的股道数量,请检查配置', {}
|
||
total_number_carriage = int(total_number_carriage)
|
||
|
||
tagsList = TagsList()
|
||
open_report_tags_list = tagsList.getOpenReportTags()
|
||
total_number_carriage_tags_list = tagsList.getTotalNumberCarriageTags()
|
||
if len(open_report_tags_list) <= (pound_no - 1):
|
||
return 412, "股道“开启报表”的点位配置未读到,请检查配置文件", {}
|
||
if len(total_number_carriage_tags_list) <= (pound_no - 1):
|
||
return 412, "股道“总车节数”的点位配置未读到,请检查配置文件", {}
|
||
|
||
pre_load_tags_list = tagsList.getPreLoadWeightTags()
|
||
if len(pre_load_tags_list) < (pound_no - 1):
|
||
return 412, "股道“预装量”的点位配置未读到,请检查配置文件", {}
|
||
|
||
plc = PLC_Tool(config.ip_address, config.slot)
|
||
success, msg, results = plc.batch_write_tag([(open_report_tags_list[pound_no - 1], 0),
|
||
(total_number_carriage_tags_list[pound_no - 1], 0)])
|
||
if not success:
|
||
return 412, msg, {}
|
||
else:
|
||
if success > 1:
|
||
return 417, msg, results
|
||
# else:
|
||
# return responseMsg(200, msg, results)
|
||
|
||
pre_load = [0] * config.carriage_num_max
|
||
success, msg = plc.write_array(pre_load_tags_list[pound_no - 1], pre_load)
|
||
if not success:
|
||
return 412, msg, {}
|
||
|
||
if len(plcInfo.loadingDict_List) < 1:
|
||
return 412, "PLC连接失败,数据异常", {}
|
||
|
||
if total_number_carriage != plcInfo.loadingDict_List[pound_no-1]["total_number_carriage"]:
|
||
logger.warn(
|
||
"【关闭PLC报表】疑似关闭的非同一列车! 输入的车厢总数为%d节,而实际PLC中的车厢总数为%d节;当前在装车厢为第%d节" % (
|
||
total_number_carriage, plcInfo.loadingDict_List[pound_no-1]["total_number_carriage"],
|
||
plcInfo.loadingDict_List[pound_no-1]["loading_carriage_order"]))
|
||
elif plcInfo.loadingDict_List[pound_no-1]["loading_carriage_order"] != plcInfo.loadingDict_List[pound_no-1]["total_number_carriage"]:
|
||
logger.warn(
|
||
"【关闭PLC报表】疑似提前误关报表! 输入的车厢总数为%d节,而实际PLC中的车厢总数为%d节;当前在装车厢为第%d节" % (
|
||
total_number_carriage, plcInfo.loadingDict_List[pound_no-1]["total_number_carriage"],
|
||
plcInfo.loadingDict_List[pound_no-1]["loading_carriage_order"]))
|
||
else:
|
||
logger.info("【关闭PLC报表】")
|
||
|
||
return 200, msg, {"carriageWeightHouse": plcInfo.pinchCoalQuantityList_List[pound_no-1],
|
||
"grossWeightHouse": plcInfo.grossWeightList_List[pound_no-1]}
|
||
|
||
|
||
def get_web_token():
|
||
"""
|
||
请求获取web token
|
||
:return:
|
||
"""
|
||
login_result, token_type, access_token = interfaceToWeb().loginWeb(config.login_web_url, config.username,
|
||
config.password, config.authorization)
|
||
|
||
if login_result is not "":
|
||
logger.warn(login_result)
|
||
return 412, "请求登录web失败,原因:%s" % login_result, {}
|
||
return 200, "", {"token_type": token_type, "access_token": access_token, "token": (token_type + " " + access_token)}
|
||
|
||
|
||
def upload_pinch_coal(carriage_order: int, pinch_coal: float, pound_no: str):
|
||
"""
|
||
上传掐煤量
|
||
:param carriage_order: 车厢序号
|
||
:param pinch_coal: 掐煤量
|
||
:param pound_no: 股道名
|
||
:return: [响应码:int, 提示信息:str, 结构数据:obj]
|
||
"""
|
||
if carriage_order == 0:
|
||
return 412, "no carriage_order", {}
|
||
if isinstance(carriage_order, str) and not carriage_order.isdigit() or int(carriage_order) <= 0:
|
||
return 412, "\"carriage_order\" It should be of INT type and greater than 0.", {}
|
||
if pinch_coal == -1:
|
||
return 412, "no pinch_coal", {}
|
||
if isinstance(pinch_coal, str) and not pinch_coal.isdigit() or float(pinch_coal) < 0:
|
||
return 412, "\"pinch_coal\" It should be of float type and greater than 0.", {}
|
||
if pound_no == "":
|
||
return 412, "no pound_no", {}
|
||
if isinstance(pound_no, str) and not pound_no.isdigit():
|
||
return 412, "pound_no should be a int, and 0 < pound_no <= 2 ", {}
|
||
if not 0 < int(pound_no) <= config.track_num:
|
||
return 412, "pound_no should be a int, and 0 < pound_no <= 2 ", {}
|
||
|
||
interface = interfaceToWeb()
|
||
login_result, token_type, access_token = interface.loginWeb(config.login_web_url, config.username,
|
||
config.password, config.authorization)
|
||
|
||
if login_result is not "":
|
||
logger.warn(login_result)
|
||
return 412, "请求登录web失败", {}
|
||
|
||
up_result = interface.upload_pinch_coal(config.upload_pinch_coal_url,
|
||
time.strftime('%Y-%m-%d %H:%M:%S'),
|
||
int(carriage_order),
|
||
float(pinch_coal),
|
||
pound_no)
|
||
if up_result != "":
|
||
return 417, up_result, {}
|
||
else:
|
||
return 200, "上传成功", {}
|
||
|
||
|
||
def upload_gross_weight(carriage_order: int, gross_weight: float, pound_no: str):
|
||
"""
|
||
上传毛重
|
||
:param carriage_order: 车厢序号
|
||
:param gross_weight: 毛重
|
||
:param pound_no: 股道名
|
||
:return: [响应码:int, 提示信息:str, 结构数据:obj]
|
||
"""
|
||
if carriage_order == 0:
|
||
return 412, "no carriage_order", {}
|
||
if isinstance(carriage_order, str) and not carriage_order.isdigit() or int(carriage_order) <= 0:
|
||
return 412, "\"carriage_order\" It should be of INT type and greater than 0.", {}
|
||
if gross_weight == -1:
|
||
return 412, "no pinch_coal", {}
|
||
if isinstance(gross_weight, str) and not gross_weight.isdigit() or float(gross_weight) <= 0:
|
||
return 412, "\"gross_weight\" It should be of float type and greater than 0.", {}
|
||
if pound_no == "":
|
||
return 412, "no pound_no", {}
|
||
if isinstance(pound_no, str) and not pound_no.isdigit():
|
||
return 412, "pound_no should be a int, and 0 < pound_no <= 2 ", {}
|
||
if not 0 < int(pound_no) <= config.track_num:
|
||
return 412, "pound_no should be a int, and 0 < pound_no <= 2 ", {}
|
||
|
||
interface = interfaceToWeb()
|
||
login_result, token_type, access_token = interface.loginWeb(config.login_web_url, config.username,
|
||
config.password, config.authorization)
|
||
|
||
if login_result is not "":
|
||
logger.warn(login_result)
|
||
return 412, "请求登录web失败", {}
|
||
|
||
up_result = interface.upload_gross_weight(config.upload_pinch_coal_url,
|
||
time.strftime('%Y-%m-%d %H:%M:%S'),
|
||
int(carriage_order),
|
||
float(gross_weight),
|
||
pound_no)
|
||
if up_result != "":
|
||
return 417, up_result, {}
|
||
else:
|
||
return 200, "上传成功", {}
|