|
|
|
@ -451,33 +451,38 @@ class TcRtdManage(object):
|
|
|
|
|
varTypeList = ['R', 'S', 'B', 'J', 'T', 'E', 'K', 'N', 'C', 'A']
|
|
|
|
|
pattern = re.compile(r'[^0-9\.-]+')
|
|
|
|
|
# or re.findall(pattern, varName)
|
|
|
|
|
if not varName or not varType or not varModel or not min or not max or not channelNumber :
|
|
|
|
|
if not varName or not varType or not varModel or not channelNumber :
|
|
|
|
|
errorInfo = '表TCRTD第{}行导入失败,有关键字段为空'.format(str(index + 1))
|
|
|
|
|
return errorInfo
|
|
|
|
|
if re.findall(pattern, str(channelNumber)) or re.findall(pattern, str(min)) or re.findall(pattern, str(max)):
|
|
|
|
|
errorInfo = '表TCRTD第{}行导入失败,{}'.format(str(index + 1), '通道号、工程量下限、工程量上限只能为数字')
|
|
|
|
|
return errorInfo
|
|
|
|
|
if varType not in varTypeList or varType != 'PT100':
|
|
|
|
|
errorInfo = '表TCRTD第{}行导入失败,{}'.format(str(index + 1), str(index + 1), '变量类型错误')
|
|
|
|
|
# 检查变量类型是否有效:热电偶类型必须在varTypeList中,或者必须是PT100
|
|
|
|
|
if varType not in varTypeList and varType != 'PT100':
|
|
|
|
|
errorInfo = '表TCRTD第{}行导入失败,变量类型错误:{}'.format(str(index + 1), varType)
|
|
|
|
|
return errorInfo
|
|
|
|
|
if varModel not in ['本地值', '远程值', '模拟值']:
|
|
|
|
|
errorInfo = '表TCRTD第{}行导入失败,{}'.format(str(index + 1), str(index + 1), '变量模型有误')
|
|
|
|
|
return errorInfo
|
|
|
|
|
if not varNumberManage.validateChannelNumber(varType, channelNumber):
|
|
|
|
|
errorInfo = '表TCRTD第{}行导入失败,{}'.format(str(index + 1), '通道号超出范围')
|
|
|
|
|
return errorInfo
|
|
|
|
|
|
|
|
|
|
if TcRtdVar.getByChannelNumber(channelNumber):
|
|
|
|
|
# 如果通道号已存在,更新其信息
|
|
|
|
|
if varType in varTypeList:
|
|
|
|
|
#导入热电偶
|
|
|
|
|
TcRtdVar.update(varName = varName, channelNumber = channelNumber, description=des, varType=varType,
|
|
|
|
|
min=min, max=max, compensationVar = compensationVar, unit = unit,
|
|
|
|
|
initialValue=initialValue).where((TcRtdVar.channelNumber == channelNumber) & (TcRtdVar.varType != 'PT100')).execute()
|
|
|
|
|
else:
|
|
|
|
|
#导入热电阻
|
|
|
|
|
TcRtdVar.update(varName = varName, channelNumber = channelNumber, description=des, varType=varType,
|
|
|
|
|
min=min, max=max, compensationVar = compensationVar, unit = unit,
|
|
|
|
|
initialValue=initialValue).where((TcRtdVar.channelNumber == channelNumber) & (TcRtdVar.varType == 'PT100')).execute()
|
|
|
|
|
else:
|
|
|
|
|
tcRtdVarType = TcRtdVar()
|
|
|
|
|
tcRtdVarType.createVar(varName = varName, channelNumber=channelNumber, des = des, varType = varType, min = min, max = max, compensationVar = compensationVar, varModel = varModel, unit = unit,nitialValue=initialValue)
|
|
|
|
|
# if TcRtdVar.getByChannelNumber(channelNumber):
|
|
|
|
|
# # 如果通道号已存在,更新其信息
|
|
|
|
|
# if varType in varTypeList:
|
|
|
|
|
# #导入热电偶
|
|
|
|
|
# TcRtdVar.update(varName = varName, channelNumber = channelNumber, description=des, varType=varType,
|
|
|
|
|
# min=min, max=max, compensationVar = compensationVar, unit = unit,
|
|
|
|
|
# initialValue=initialValue).where((TcRtdVar.channelNumber == channelNumber) & (TcRtdVar.varType != 'PT100')).execute()
|
|
|
|
|
# else:
|
|
|
|
|
# #导入热电阻
|
|
|
|
|
# TcRtdVar.update(varName = varName, channelNumber = channelNumber, description=des, varType=varType,
|
|
|
|
|
# min=min, max=max, compensationVar = compensationVar, unit = unit,
|
|
|
|
|
# initialValue=initialValue).where((TcRtdVar.channelNumber == channelNumber) & (TcRtdVar.varType == 'PT100')).execute()
|
|
|
|
|
# else:
|
|
|
|
|
tcRtdVarType = TcRtdVar()
|
|
|
|
|
tcRtdVarType.createVar(varName = varName, channelNumber=channelNumber, des = des, varType = varType, min = min, max = max, compensationVar = compensationVar, varModel = varModel, unit = unit, initialValue=initialValue)
|
|
|
|
|
# 操作后刷新缓存
|
|
|
|
|
refreshCache()
|
|
|
|
|
|
|
|
|
@ -610,13 +615,15 @@ class AnalogManage(object):
|
|
|
|
|
if varModel not in ['本地值', '远程值', '模拟值']:
|
|
|
|
|
errorInfo = '表IO第{}行导入失败,{}'.format(str(index + 1), '变量模型有误')
|
|
|
|
|
return errorInfo
|
|
|
|
|
|
|
|
|
|
if AnalogVar.getByChannelNumber(channelNumber):
|
|
|
|
|
# 如果通道号已存在,更新其信息
|
|
|
|
|
AnalogVar.update(varName = varName, description=des, varType=varType, min=min, max=max, unit = unit, initialValue=initialValue).where((AnalogVar.channelNumber == channelNumber) & (AnalogVar.varType == varType)).execute()
|
|
|
|
|
else:
|
|
|
|
|
analogVarType = AnalogVar()
|
|
|
|
|
analogVarType.createVar(varName = varName, channelNumber = channelNumber, des = des, varType = varType, min = min, max = max, varModel = varModel,unit = unit, initialValue=initialValue)
|
|
|
|
|
if not varNumberManage.validateChannelNumber(varType, channelNumber):
|
|
|
|
|
errorInfo = '表IO第{}行导入失败,{}'.format(str(index + 1), '通道号超出范围')
|
|
|
|
|
return errorInfo
|
|
|
|
|
# if AnalogVar.getByChannelNumber(channelNumber):
|
|
|
|
|
# # 如果通道号已存在,更新其信息
|
|
|
|
|
# AnalogVar.update(varName = varName, description=des, varType=varType, min=min, max=max, unit = unit, initialValue=initialValue).where((AnalogVar.channelNumber == channelNumber) & (AnalogVar.varType == varType)).execute()
|
|
|
|
|
|
|
|
|
|
analogVarType = AnalogVar()
|
|
|
|
|
analogVarType.createVar(varName = varName, channelNumber = channelNumber, des = des, varType = varType, min = min, max = max, varModel = varModel,unit = unit, initialValue=initialValue)
|
|
|
|
|
# 操作后刷新缓存
|
|
|
|
|
refreshCache()
|
|
|
|
|
|
|
|
|
@ -791,13 +798,26 @@ class GlobalVarManager(object):
|
|
|
|
|
case 'IO' | 'TCRTD':
|
|
|
|
|
requiredFields = ['变量名', '通道序号', '变量类型'] if sheetName == 'IO' else \
|
|
|
|
|
['变量名', '通道序号', '变量类型', '补偿值']
|
|
|
|
|
importFunc = AnalogManage.importVarForm if sheetName == 'IO' else TcRtdManage.importVarForm
|
|
|
|
|
|
|
|
|
|
# 先清空现有数据,再导入新数据
|
|
|
|
|
if sheetName == 'IO':
|
|
|
|
|
try:
|
|
|
|
|
deleted_count = AnalogVar.delete().execute()
|
|
|
|
|
print(f"已清空 {deleted_count} 条IO变量数据")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"清空IO数据失败: {str(e)}")
|
|
|
|
|
else: # TCRTD
|
|
|
|
|
try:
|
|
|
|
|
deleted_count = TcRtdVar.delete().execute()
|
|
|
|
|
print(f"已清空 {deleted_count} 条TCRTD变量数据")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"清空TCRTD数据失败: {str(e)}")
|
|
|
|
|
|
|
|
|
|
importFunc = AnalogManage.importVarForm if sheetName == 'IO' else TcRtdManage.importVarForm
|
|
|
|
|
for index, row in data.iterrows():
|
|
|
|
|
if any(pd.isna(row[field]) for field in requiredFields):
|
|
|
|
|
errorConList.append(f'第{index+1}行关键字段为空')
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if sheetName == 'IO':
|
|
|
|
|
errInfo = importFunc(
|
|
|
|
@ -832,6 +852,9 @@ class GlobalVarManager(object):
|
|
|
|
|
errorConList.append(errInfo)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
errorConList.append(f'第{index+1}行导入失败: {str(e)}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'Hart模拟' | 'Hart读取':
|
|
|
|
|
requiredFields = ['变量名']
|
|
|
|
@ -860,5 +883,56 @@ class GlobalVarManager(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class varNumberManage(object):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(varNumberManage, self).__init__()
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def validateChannelNumber(cls, varType, channelNumber):
|
|
|
|
|
"""
|
|
|
|
|
验证通道号是否在正确的范围内
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
varType (str): 变量类型
|
|
|
|
|
channelNumber (int): 通道号
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
bool: 通道号在范围内返回True,否则返回False
|
|
|
|
|
"""
|
|
|
|
|
# 确保channelNumber是整数
|
|
|
|
|
try:
|
|
|
|
|
channelNumber = int(channelNumber)
|
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# 定义各类型的通道号范围
|
|
|
|
|
channelRanges = {
|
|
|
|
|
'AO': (1, 16),
|
|
|
|
|
'DO': (1, 16),
|
|
|
|
|
'AI': (1, 8),
|
|
|
|
|
'DI': (1, 16),
|
|
|
|
|
'PT100': (1, 8),
|
|
|
|
|
# 热电偶类型
|
|
|
|
|
'R': (1, 8),
|
|
|
|
|
'S': (1, 8),
|
|
|
|
|
'B': (1, 8),
|
|
|
|
|
'J': (1, 8),
|
|
|
|
|
'T': (1, 8),
|
|
|
|
|
'E': (1, 8),
|
|
|
|
|
'K': (1, 8),
|
|
|
|
|
'N': (1, 8),
|
|
|
|
|
'C': (1, 8),
|
|
|
|
|
'A': (1, 8)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 检查变量类型是否在支持的类型中
|
|
|
|
|
if varType not in channelRanges:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# 获取该类型的通道号范围
|
|
|
|
|
minChannel, maxChannel = channelRanges[varType]
|
|
|
|
|
|
|
|
|
|
# 验证通道号是否在范围内
|
|
|
|
|
return minChannel <= channelNumber <= maxChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|