pyhostvm 0.41.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyhostvm/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.41.0"
pyhostvm/tj010.ptl ADDED
@@ -0,0 +1,243 @@
1
+ namespace tj010
2
+ {
3
+ struct UnitModel
4
+ {
5
+ int NumberofNumerator /* 分子系数的个数,optional,可为空 */;
6
+ int NumberofDenominator /* 分母系数的个数,optional,可为空 */;
7
+ double NumeratorCoefficient[~] /* 分子系数 optional,可为空 */;
8
+ double DenominatorCoefficient[~] /* 分母系数 optional,可为空 */;
9
+ int UnitStepRespLength /* 阶跃序列长度 */;
10
+ double UnitStepResponse[~] /* 阶跃响应序列 */;
11
+ int delay /* 纯滞后 */;
12
+ double StableGain /* 稳态增益 对于积分环节,为稳态增益斜率 */;
13
+ int IntegralMark /* 积分标志1:积分环节;0:非积分环节 */;
14
+ };
15
+
16
+ struct InputVariable
17
+ {
18
+ int MVType = 1 /* default: 1 0: DV; 1: MV */;
19
+ int Status = 1 /* default: 1 0:检测出现故障;1:正常 */;
20
+ int ControlStatus /* 控制状态 default: 0; 0: OFF;1:ON; 2: FeedForward */;
21
+ int KeyVariable /* 关键变量(没用) default: 0 0: NO; 1: YES */;
22
+ double HiLimit = 100.0 /* 上限 */;
23
+ double LoLimit /* 下限 */;
24
+ double PosSpeedLim = 10.0 /* 2022-01-16新增 MV正速率限制 */;
25
+ double NegSpeedLim = 10.0 /* 2022-01-16新增 MV负速率限制 */;
26
+ double _IncrConstraint = 10.0 /* 2022-01-16删除 增量约束(SpeedLimit) */;
27
+ double IRVExpect = 0.0 /* IRV期望值 default: 0 */;
28
+ double LinearWeight = 0.0 /* 线性权重 default: 0 */;
29
+ double QuadraticWeight = 0.0 /* 二次权重 default: 0 */;
30
+ double SoftHiLimit = 0.0 /* 缓冲区上间距 default: 0 */;
31
+ double SoftLoLimit = 0.0 /* 缓冲区下间距 default: 0 */;
32
+ double PRIWeight = 0.0 /* 优先权重(没用) default: 0 */;
33
+ double IncrementWeight = 1.0 /* 增量权重 default: 1 */;
34
+ double ErrorWeight = 0.0 /* 误差权重 default: 0 */;
35
+ int IntBlock = 15 /* default: 15 */;
36
+ double DVPrd[~] /* default: [], v0.28.1新增, 未来DV的预测数组(不包含当前值!) */
37
+ /* self.DVPrd = [] 表示未来的DV预测使用了默认方式:DVprd = [uk] */;
38
+
39
+ /* 以下属性不记入TaiJiMPC4.0的ojp工程文件 */
40
+ /* 即:仅允许用脚本修改,作为临时变量,脚本修改结果不存入.ojp的工程文件。*/
41
+ int SetNm = -1 /* 修改MV的控制时域(非负整数),请慎重!*/
42
+ /* 默认: -1,表示启动控制器(Start Control)时/模型更换时使用内部默认值。*/
43
+ /* 注意:若要使用内部默认的控制时域,需要:(1)控制器重启(Stop control -> Start control) 或 在线更换模型, (2)SetNm<0 */;
44
+ double EngHI /*注意内部要设置默认值正无穷*/;
45
+ double EngLO /*注意内部要设置默认值负无穷*/;
46
+ double OperatingRange = 1.0 /*默认: 1.0 */;
47
+ };
48
+
49
+ struct OutputVariable
50
+ {
51
+ int Status = 1 /* 状态 default: 1 0:检测出现故障;1:正常 */;
52
+ int ControlStatus = 0 /* 控制状态 0(default): OFF; 1: ON; 2: PRD only; */;
53
+ int KeyVariable = 0 /* 关键变量(没用) default: 0 0: NO; 1: YES */;
54
+ int ControlType = 2 /* 控制类型 1:设定值控制;2:区间控制(StickyRange); 3: 区间控制(FreeRange) */;
55
+ double SetPoint = 0.0 /* 设定值 (FTSPBias is included!) */;
56
+ double HiRange = 100.0 /* 区间上限 */;
57
+ double LoRange = 0.0 /* 区间下限 */;
58
+ double ClsLpRsponseTime = 2.0 /* 闭环响应时间(单位:分钟) */;
59
+ double IRVExpect = 0.0 /* IRV期望值 default: 0 */;
60
+ double LinearWeight = 0.0 /* 线性权重 default: 0 */;
61
+ double QuadraticWeight = 0.0 /* 二次权重 default: 0 */;
62
+ double SoftHiLimit = 0.0 /* 缓冲区上间距default: 0即为优化区域上限间距 */;
63
+ double SoftLoLimit = 0.0 /* 缓冲区下间距default: 0即为优化区域下限间距 */;
64
+ double PRIWeight = 1.0 /* 优先权重 default: 1 */;
65
+ int Priority = 1 /* 优先级 */;
66
+ double ErrorWeight = 1.0 /* 误差权重 default: 1 */;
67
+ double IncrementWeight = 100.0 /* CV 增量权重 2021-09-04新增 */;
68
+ int DistAdaptiveSwt = 0 /* 扰动自适应的开关; 0: OFF, 1: ON. */;
69
+ int DistModelOrder = 0 /* 干扰模型的阶次 */;
70
+ int DistPredHorizon = 6 /* 使用干扰模型进行输出预测的长度 */;
71
+ int DistAdaptiveMode = 2 /* 干扰模型的形式 {0:'', 1:'c0', 2:'c0c1', 3:'c0c1c2'} */;
72
+ int DistAdaptiveDataLen = 3 /* 估计干扰模型的数据长度 */;
73
+ double DistForgettingFactor = 1.0 /* 估计干扰模型的遗忘因子 */;
74
+ double DistFilterCoef = 3.0 /* 合并输出滤波系数 */;
75
+ int FTSPType = 0 /* 0: None, 1:协调控制负荷斜坡, 2:协调控制滑压曲线, 3: 架空稳态层 */;
76
+ double FTSPRate = 0.0 /* Slope Tag in Tai-Ji MPC */;
77
+ double FTSPEnd = 0.0 /* "End SP Tag" (FTSPBias is not included!) or "X Axis End Tag" in Tai-Ji MPC */;
78
+ int FTSPNum = 0 /* X Axis Cur. Tag in Tai-Ji MPC */;
79
+ astring FTSPXY /* strFXY in Tai-Ji MPC */;
80
+ double FTSPTau = 0.0 /* Filter in Tai-Ji MPC */;
81
+ double FTSPBias = 0.0 /* Delta Tag in Tai-Ji MPC */;
82
+ int FTSPHzn = 0 /* Pred Horizon in Tai-Ji MPC */;
83
+
84
+ /* 以下属性不记入TaiJiMPC4.0的ojp工程文件 */
85
+ /* 即:仅允许用脚本修改,作为临时变量,脚本修改结果不存入.ojp的工程文件。 */
86
+ double ErrWtRngFactor = 0.02 /* 2023-03-05 仅在FreeRange条件下起作用。 */
87
+ /* 区间内CV误差权重因子(ErrorWeightInRange = ErrWtRngFactor*ErrorWeight) */;
88
+ double IncWtRngFactor = 0.02 /* 2023-03-05 仅在FreeRange条件下起作用。 */
89
+ /* 区间内CV增量权重因子(IncrementWeightInRange = IncWtRngFactor*IncrementWeight) */;
90
+ int IntBlock = 200 /* 修改CV的间隔块数(线性间隔),请慎重! */;
91
+ int SetNp = -1 /* 修改CV的预测时域(非负整数),请慎重! */
92
+ /* 默认: -1,表示启动控制器(Start Control)时/模型更换时使用内部默认值。 */
93
+ /* 注意:若要使用内部默认的预测时域,需要:(1)控制器重启(Stop control -> Start control) 或 在线更换模型, (2)SetNp<0 */;
94
+ double EngHI /*注意内部要设置默认值正无穷*/;
95
+ double EngLO /*注意内部要设置默认值负无穷*/;
96
+ double SPFilterTau /*设定值滤波器时间常数*/;
97
+ double SPFilterAlpha /*设定值滤波器超前系数*/;
98
+ double OperatingRange = 1.0 /*默认: 1.0 */;
99
+ };
100
+
101
+ [zpy_ignore]
102
+ struct SetupModelInput
103
+ {
104
+ int InputNum;
105
+ int OutputNum;
106
+ struct UnitModel ControlModel[~];
107
+ struct UnitModel PlantModel[~];
108
+ int ControlModelFlag;
109
+ int PlantModelFlag;
110
+ int ControlInterval;
111
+ astring InputTagName[~];
112
+ astring OutputTagName[~];
113
+ };
114
+
115
+ [zpy_ignore]
116
+ struct SetupModelOutput
117
+ /*where come from?*/
118
+ {
119
+ int iOutput;
120
+ astring szOutput;
121
+ float fOutput;
122
+ double dOutput;
123
+ struct UnitModel uModel;
124
+ };
125
+
126
+ [function]
127
+ struct ControllerSetupModel
128
+ {
129
+ [tuple] struct SetupModelInput Input;
130
+ };
131
+
132
+ [zpy_ignore]
133
+ struct ProcessVarInitInput
134
+ {
135
+ struct InputVariable InputVar[~] /* typInputVariable结构的一维数组,长度InputNum */;
136
+ struct OutputVariable OutputVar[~] /* typOutputVariable结构的一维数组 长度OutputNum */;
137
+ };
138
+
139
+ [function]
140
+ struct ControllerProcessVarInit
141
+ {
142
+ [tuple] struct ProcessVarInitInput Input;
143
+ };
144
+
145
+ [zpy_ignore]
146
+ struct ModifyMutiOutputVariablesInput
147
+ {
148
+ int VarIndex[~];
149
+ struct OutputVariable OutputVar[~];
150
+ };
151
+
152
+ [function]
153
+ struct ControllerModifyMutiOutputVariables
154
+ {
155
+ [tuple] struct ModifyMutiOutputVariablesInput Input;
156
+ };
157
+
158
+ [zpy_ignore]
159
+ struct ModifyMutiInputVariablesInput
160
+ {
161
+ int VarIndex[~];
162
+ struct InputVariable InputVar[~];
163
+ };
164
+
165
+ [function]
166
+ struct ControllerModifyMutiInputVariables
167
+ {
168
+ [tuple] struct ModifyMutiInputVariablesInput Input;
169
+ };
170
+
171
+ [zpy_ignore]
172
+ struct ControllerCalculationInput
173
+ {
174
+ double InputValue[~] /* 输入值数组,长度InputNum */;
175
+ double OutputValue[~] /* 输出值数组,长度OutputNum */;
176
+ int m;
177
+ };
178
+
179
+ [zpy_ignore]
180
+ struct ControllerCalculationOutput
181
+ {
182
+ double InputPredVal[~] /* 返回值,m*InputNum * 1, MV、DV预测值 */;
183
+ double InputSSVal[~] /* 返回值,InputNum * 1, MV、DV稳态值 */;
184
+ int InputPredHorizon[~] /* 返回值,InputNum * 1, MV、DV模型时域 */;
185
+ double OutputPredVal[~] /* 返回值,m*OutputNum* 1, CV预测值 */;
186
+ double OutputSSVal[~] /* 返回值,OutputNum* 1, CV稳态值 */;
187
+ int OutputPredHorizon[~] /* 返回值,OutputNum* 1, CV模型时域 */;
188
+ double InputErrPct[~] /* 返回值,InputNum* 1, MV、DV误差百分比 */;
189
+ double InputIncPct[~] /* 返回值,InputNum* 1, MV、DV增量百分比 */;
190
+ double OutputErrPct[~] /* 返回值,OutputNum* 1, CV误差百分比 */;
191
+ double OutputIncPct[~] /* 返回值,OutputNum* 1, CV增量百分比 */;
192
+ double InputMaxDeltaPrd[~] /* 返回值,InputNum* 1, MX,DV最大预测变化量 */;
193
+ double OutputMaxDeltaPrd[~] /* 返回值,OutputNum* 1, CV最大预测变化量 */;
194
+ };
195
+
196
+ [function]
197
+ struct ControllerCalculation
198
+ {
199
+ [tuple] struct ControllerCalculationInput Input;
200
+ struct ControllerCalculationOutput Output;
201
+ };
202
+
203
+ [zpy_ignore]
204
+ struct SetupLPVModelInput
205
+ {
206
+ int model_id /* 模型ID */;
207
+ double working_point /* 工作点 */;
208
+ int InputNum /* 输入变量总数 */;
209
+ int OutputNum /* 输出变量总数 */;
210
+ struct UnitModel ControlModel[~] /* 控制模型 typModel结构的二维数组 */
211
+ /* 维数:(int输出变量总数, int输入变量总数),用于模型预测 */;
212
+ astring InputTagName[~] /* 输入变量名称数组 */;
213
+ astring OutputTagName[~] /* 输出变量名称数组 */;
214
+ };
215
+
216
+ [function]
217
+ struct ControllerSetupLPVModel
218
+ {
219
+ [tuple] struct SetupLPVModelInput Input;
220
+ };
221
+
222
+ [function]
223
+ struct ControllerPlantRecursion
224
+ {
225
+ double Output[~] /* 返回值,Output double数组 */;
226
+ };
227
+
228
+ [zpy_ignore]
229
+ struct ControllerGetLPVModelStatusOutput
230
+ {
231
+ int LPV_SW /* 返回值,LPV模型开关,0表示关闭,1表示开启 */;
232
+ double working_value /* 返回值,工作点变量的当前值 */;
233
+ int model_id[~] /* 返回值,LPV模型ID */;
234
+ double working_point[~] /* 返回值,ID对应模型的工作点列表 */;
235
+ double current_weight[~] /* 返回值,ID对应模型的权重列表 */;
236
+ };
237
+
238
+ [function]
239
+ struct ControllerGetLPVModelStatus
240
+ {
241
+ struct ControllerGetLPVModelStatusOutput Output;
242
+ };
243
+ }
@@ -0,0 +1,250 @@
1
+ import sys, os, logging, zce, gc
2
+ from datetime import datetime
3
+ from typing import List, Tuple
4
+ from tj010.tj007pyInterface import ControllerInterface
5
+ from tj010.tj007pyInterface.DLL007data import *
6
+
7
+ def SetupLogger():
8
+ logger = logging.getLogger()
9
+ logger.setLevel(logging.DEBUG) # 最低 level
10
+
11
+ # 确保 log 目录存在
12
+ log_dir = "log"
13
+ if not os.path.exists(log_dir):
14
+ os.makedirs(log_dir)
15
+
16
+ # 文件 handler(所有级别)
17
+ log_filename = os.path.join(log_dir, f"tj010_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log")
18
+ file_handler = logging.FileHandler(log_filename, encoding='utf-8')
19
+ file_handler.setLevel(logging.INFO)
20
+
21
+ # stdout handler(DEBUG、INFO)
22
+ stdout_handler = logging.StreamHandler(sys.stdout)
23
+ stdout_handler.setLevel(logging.DEBUG)
24
+ stdout_handler.addFilter(lambda record: record.levelno < logging.WARNING)
25
+
26
+ # stderr handler(WARNING, ERROR, CRITICAL)
27
+ stderr_handler = logging.StreamHandler(sys.stderr)
28
+ stderr_handler.setLevel(logging.WARNING)
29
+
30
+ # 格式(可选)
31
+ formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
32
+ file_handler.setFormatter(formatter)
33
+ stdout_handler.setFormatter(formatter)
34
+ stderr_handler.setFormatter(formatter)
35
+
36
+ # 清空默认 handler(很重要)
37
+ logger.handlers.clear()
38
+ logging.basicConfig(level=logging.DEBUG)
39
+ # 添加 handler
40
+ logger.addHandler(file_handler)
41
+ logger.addHandler(stdout_handler)
42
+ logger.addHandler(stderr_handler)
43
+
44
+ def ControllerCreate():
45
+ # 实例化MPC控制器
46
+ logging.debug("ControllerCreate")
47
+ mpc1 = ControllerInterface()
48
+ mpc1.ControllerFlagInitialization(path = os.getcwd())
49
+ return zce.registe_object(mpc1)
50
+
51
+ def ControllerStop(mpc1):
52
+ logging.debug("ControllerStop")
53
+ #todo unregiste_object
54
+ mpc1.StopControl()
55
+ zce.unregiste_object(mpc1)
56
+
57
+ def ControllerCreateSimple():
58
+ # 实例化MPC控制器
59
+ logging.debug("ControllerCreateSimple")
60
+ mpc1 = ControllerInterface()
61
+ mpc1.ControllerFlagInitialization(path = os.getcwd())
62
+ return mpc1
63
+
64
+ def ControllerStopSimple(mpc1):
65
+ logging.debug("ControllerStopSimple")
66
+ mpc1.StopControl()
67
+
68
+ def ControllerFlagInitialization(mpc1, path, interval):
69
+ logging.debug(f"ControllerFlagInitialization {path}, {interval}")
70
+ mpc1.ControllerFlagInitialization(path, interval)
71
+
72
+ def ControllerSaveMPCObj(mpc1):
73
+ logging.debug("ControllerSaveMPCObj")
74
+ mpc1.save_mpcobj()
75
+
76
+ def ControllerSetupModel(mpc1,
77
+ InputNum: int, # 输入变量总数
78
+ OutputNum: int, # 输出变量总数
79
+ ControlModel: List[UnitModel], # 控制模型 typModel结构的二维数组
80
+ # 维数:(int输出变量总数, int输入变量总数),用于模型预测
81
+ PlantModel: List[UnitModel], #工厂模型 typModel结构的二维数组
82
+ # 维数:(int输出变量总数, int输入变量总数),用于仿真时的工厂模型递推。
83
+ ControlModelFlag: int, # 控制模型标志
84
+ # 为1,表示模型预测时使用的阶跃响应序列由传递函数计算得来
85
+ # 为0,表示模型预测直接使用客户程序给定的阶跃响应序列
86
+ PlantModelFlag: int, # 工厂模型标志
87
+ # 为1,表示仿真时工厂模型递推使用的阶跃响应序列由传递函数计算得来
88
+ # 为0,表示仿真时工厂模型递推直接使用客户程序给定的阶跃响应序列
89
+ ControlInterval: int, # 控制周期, 要与客户程序生成阶跃响应序列时使用的控制周期一致
90
+ InputTagName: List[str], # 输入输出变量名称数组,分别存放于InputTagName和OutputTagName
91
+ OutputTagName: List[str],
92
+ **kargs
93
+ ):
94
+ print(f"ControllerSetupModel, {InputNum}, {OutputNum}, {ControlModelFlag}, {PlantModelFlag}, {ControlInterval}")
95
+ mpc1.SetupModel(InputNum, OutputNum, ControlModel, PlantModel,
96
+ ControlModelFlag, PlantModelFlag, ControlInterval, InputTagName, OutputTagName, **kargs)
97
+
98
+ def ControllerProcessVarInit(mpc1,
99
+ InputVar: List[InputVariable], # typInputVariable结构的一维数组,长度InputNum
100
+ OutputVar: List[OutputVariable], # typOutputVariable结构的一维数组 长度OutputNum
101
+ **kargs
102
+ ) -> None:
103
+ logging.debug(f"ControllerProcessVarInit, {InputVar}, {OutputVar}")
104
+ mpc1.ProcessVariableInitialization(InputVar, OutputVar)
105
+
106
+ def ControllerModifyMutiInputVariables(mpc1, VarIndexList: list[int], InputVarList: list[InputVariable]) -> None:
107
+ logging.debug(f"ControllerModifyMutiInputVariables, {VarIndexList}, {InputVarList}")
108
+ mpc1.ModifyMutiInputVariables(VarIndexList, InputVarList)
109
+
110
+ def ControllerModifyMutiOutputVariables(mpc1, VarIndexList: list[int], OutputVarList: list[OutputVariable]) -> None:
111
+ logging.debug(f"ControllerModifyMutiOutputVariables, {VarIndexList}, {OutputVarList}")
112
+ mpc1.ModifyMutiOutputVariables(VarIndexList, OutputVarList)
113
+
114
+ def ControllerModifyGainFactor(mpc1, gains):
115
+ logging.debug(f"ControllerModifyGainFactor, {gains}")
116
+ mpc1.ModifyGainFactor(gains)
117
+
118
+ def ControllerCalculation(mpc1,
119
+ InputValue: List[float], # 输入变量值,一维数组 长度InputNum
120
+ OutputValue: List[float], # 输出变量值,一维数组 长度OutputNum
121
+ m: int = 20):
122
+ # 计算
123
+ logging.debug(f"ControllerCalculation, {InputValue}, {OutputValue}, {m}")
124
+ ret = mpc1.ControllerCalculation(InputValue, OutputValue, m)
125
+ logging.info(f"ControllerCalculation, after calculation, {OutputValue}")
126
+ return ret
127
+
128
+ def ControllerModelPrediction(mpc1,
129
+ InputValue: List[float], # 输入变量值,一维数组 长度InputNum
130
+ OutputValue: List[float] # 输出变量值,一维数组 长度OutputNum
131
+ ) -> None:
132
+ logging.debug(f"ControllerModelPrediction, {InputValue}, {OutputValue}")
133
+ mpc1.ModelPrediction(InputValue, OutputValue)
134
+ logging.info(f"ControllerModelPrediction, after prediction, {OutputValue}")
135
+
136
+ def ControllerPlantRecursion(mpc1,
137
+ InputValue: List[float], # 输入变量值,一维数组 长度InputNum
138
+ OutputValue: List[float] # 输出变量值,一维数组 长度OutputNum
139
+ ) -> List[float]: # 输出变量值,一维数组 长度OutputNum
140
+ logging.debug(f"ControllerPlantRecursion, {InputValue}, {OutputValue}")
141
+ return mpc1.PlantRecursion(InputValue, OutputValue)
142
+
143
+
144
+ def ControllerSetupLPVModel(mpc1,
145
+ model_id: int, # 模型ID
146
+ working_point: float, # 工作点
147
+ InputNum: int, # 输入变量总数
148
+ OutputNum: int, # 输出变量总数
149
+ ControlModel: List[UnitModel], # 控制模型 typModel结构的二维数组
150
+ # 维数:(int输出变量总数, int输入变量总数),用于模型预测
151
+ InputTagName: List[str], # 输入变量名称数组
152
+ OutputTagName: List[str], # 输出变量名称数组
153
+ **kargs #
154
+ ) -> None:
155
+ logging.debug(f"ControllerSetupLPVModel, {model_id}, {working_point}, {InputNum}, {OutputNum}, {ControlModel}, {InputTagName}, {OutputTagName}")
156
+ mpc1.SetupLPVModel(model_id, working_point, InputNum, OutputNum, ControlModel, InputTagName, OutputTagName, **kargs)
157
+
158
+ def ControllerDeleteLPVModel(mpc1,
159
+ model_id: int # 根据id删除工作点模型
160
+ ) -> None:
161
+ logging.debug(f"ControllerDeleteLPVModel, {model_id}")
162
+ mpc1.DeleteLPVModel(model_id)
163
+
164
+ def ControllerUseBasicMPCModel(mpc1) -> None:
165
+ mpc1.use_basic_MPCmodel()
166
+
167
+ def ControllerUseInterpLPVModel(mpc1,
168
+ working_value: float # 工作点变量的值
169
+ ) -> None:
170
+ mpc1.use_interp_LPVmodel(working_value)
171
+
172
+ def ControllerGetAttr(mpc1, attr_name: str):
173
+ attr_value = getattr(mpc1, attr_name)
174
+ logging.debug(f"ControllerGetAttr, {attr_name}, {attr_value}")
175
+ return attr_value
176
+
177
+ def ControllerSetAttrs(mpc1, attr_dict: dict):
178
+ logging.debug(f"ControllerSetAttrs, {attr_dict}")
179
+
180
+ for attr_name, attr_value in attr_dict.items():
181
+ if hasattr(mpc1, attr_name):
182
+ setattr(mpc1, attr_name, attr_value)
183
+ logging.debug(f"Set {attr_name} to {attr_value} in {mpc1}")
184
+ else:
185
+ logging.error(f"Attribute {attr_name} does not exist in {mpc1}")
186
+
187
+ def ControllerSetupParameters(mpc1, OptionDict):
188
+ logging.debug(f"ControllerSetupParameters, {OptionDict}")
189
+ # 控制器总开关
190
+ mpc1.EconomicOptFlag = OptionDict["EconomicOptFlag"]
191
+ mpc1.DistPredSW = OptionDict["DistPredSW"]
192
+ print("ControllerSetupParameters", mpc1.EconomicOptFlag, mpc1.DistPredSW)
193
+
194
+ def ControllerGetLPVModelStatus(mpc1, dummyInput) -> dict:
195
+ status = mpc1.getLPVmodelStatus()
196
+ logging.debug(f"ControllerGetLPVModelStatus, {status}")
197
+ return (status["LPV_SW"], status["working_value"], status["model_id"], status["working_point"], status["current_weight"])
198
+
199
+ def ControllerGetErrorCode(mpc1, dummyInput) -> int:
200
+ err_code = mpc1.get_error_code()
201
+ logging.debug(f"ControllerGetErrorCode, {err_code}")
202
+ return err_code
203
+
204
+ def ControllerGarbageCollect(mpc1):
205
+ logging.debug("ControllerGarbageCollect")
206
+ gc.collect() # 强制垃圾回收,释放内存
207
+
208
+ def _ControllerPlot(mpc1):
209
+ print("ControllerPlot")
210
+ import tj010.mpcplot as mpcplot
211
+ mpcplot.ShowCurrentParam(mpc1)
212
+
213
+ # 仿真结果绘图
214
+ import importlib.util
215
+
216
+ def is_matplotlib_installed():
217
+ matplotlib_spec = importlib.util.find_spec("matplotlib")
218
+ return matplotlib_spec is not None
219
+
220
+ if is_matplotlib_installed():
221
+ import matplotlib.pyplot as plt
222
+ mpcplot.PlotControllerData(mpc1)
223
+ mpcplot.PlotCurrentModelStp(mpc1)
224
+ plt.show()
225
+
226
+ def RegistMeta():
227
+
228
+ zce.registe_class(UnitModel)
229
+
230
+ zce.registe_class(InputVariable)
231
+
232
+ zce.registe_class(OutputVariable)
233
+
234
+ zce.registe_meta(os.path.join(os.path.dirname(__file__), 'tj010.ptl'))
235
+
236
+ def RegistRpcCallableFunctions():
237
+ import inspect
238
+
239
+ def get_functions():
240
+ return [(name, obj) for name, obj in globals().items() if inspect.isfunction(obj)]
241
+
242
+ # 当前模块中的所有函数
243
+ current_module_functions = get_functions()
244
+ for name, obj in current_module_functions:
245
+ if (name.startswith("Controller")):
246
+ zce.registe_callable(name, obj)
247
+
248
+ #SetupLogger()
249
+ #RegistMeta()
250
+ #RegistRpcCallableFunctions()
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyhostvm
3
+ Version: 0.41.0
4
+ Summary: Python support library for HostVM (win_amd64)
5
+ Home-page: https://github.com/ymwang78/IndustryDataHub
6
+ Author: Yongming Wang
7
+ Author-email: wangym@gmail.com
8
+ License: MIT
9
+ Project-URL: Bug Reports, https://github.com/ymwang78/IndustryDataHub/issues
10
+ Project-URL: Source, https://github.com/ymwang78/IndustryDataHub
11
+ Project-URL: Documentation, https://github.com/ymwang78/IndustryDataHub/wiki
12
+ Keywords: industrial automation,data communication,OPC,modbus,multi-platform
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Topic :: System :: Hardware
19
+ Classifier: Topic :: Communications
20
+ Classifier: Operating System :: Microsoft :: Windows
21
+ Requires-Python: >=3.12
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: pywin32>=305
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: keywords
31
+ Dynamic: license
32
+ Dynamic: project-url
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ * Python Support Library For HostVM
38
+
39
+ 1. tj010_start.py: wrapper for tj010
@@ -0,0 +1,7 @@
1
+ pyhostvm/__init__.py,sha256=6q5bwtbTdl36qwvX_CLtBrgbItFM1W4rXFFwgJPM2wY,23
2
+ pyhostvm/tj010.ptl,sha256=-zDwg1XMpFSxCZvJ5gmhnCQ9laIeLFikNA0mA0gGT1M,12687
3
+ pyhostvm/tj010_start.py,sha256=T8AjjWs3xt6C0HOmNtVj1Y-KiXaF9DgCyycRCPEQuRc,11601
4
+ pyhostvm-0.41.0.dist-info/METADATA,sha256=H4dYHqA93hiVDV5NNA9CR8dilaFyHiK3C6r6KXuSfU0,1377
5
+ pyhostvm-0.41.0.dist-info/WHEEL,sha256=QR8DNjG6Lr6bNErJWJgF4dP2dJ2N7NpY-BWly1OvcTM,97
6
+ pyhostvm-0.41.0.dist-info/top_level.txt,sha256=ezoe9Mak4XeZpyEctSnFWH2aC13pUdF0EpAKuaZsUxk,9
7
+ pyhostvm-0.41.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-win_amd64
5
+
@@ -0,0 +1 @@
1
+ pyhostvm