OPCUA在OMpython中的交互仿真
我尝试在python中使用opc ua接口运行openmodelica测试模型。 测试模型:OPCUA在OMpython中的交互仿真,python,modelica,opc-ua,openmodelica,Python,Modelica,Opc Ua,Openmodelica,我尝试在python中使用opc ua接口运行openmodelica测试模型。 测试模型: model test1 input Real x1(start = 0); input Real x2(start = 0); input Real x3(start = 0); output Real y1; output Real y2; output Real y3; equation der(y1) = x1; der(y2) = x2; der(y3)
model test1
input Real x1(start = 0);
input Real x2(start = 0);
input Real x3(start = 0);
output Real y1;
output Real y2;
output Real y3;
equation
der(y1) = x1;
der(y2) = x2;
der(y3) = x3;
initial equation
y1 = 0;
y2 = 1;
y3 = 2;
end test1;
模型运行的纸条(在终端1中执行):
连接到模型的脚本(test1_opcua.py)(在终端2中执行):
总而言之,我有:
Requested secure channel timeout to be 3600000ms, got 600000ms instead
0) QualifiedName(0:Server) -
1) QualifiedName(1:OpenModelica.step) - False
2) QualifiedName(1:OpenModelica.run) - False
3) QualifiedName(1:OpenModelica.realTimeScalingFactor) - 0.0
4) QualifiedName(1:OpenModelica.enableStopTime) - True
5) QualifiedName(1:time) - 0.0
6) QualifiedName(1:y1) - 0.0
7) QualifiedName(1:y2) - 1.0
8) QualifiedName(1:y3) - 2.0
9) QualifiedName(1:der(y1)) - 0.0
10) QualifiedName(1:der(y2)) - 0.0
11) QualifiedName(1:der(y3)) - 0.0
12) QualifiedName(1:x1) - 0.0
13) QualifiedName(1:x2) - 0.0
14) QualifiedName(1:x3) - 0.0
但是在命令modelID[2]。在termina1中设置_值(True)
(我试图启动测试模型)之后,我出现了错误:
Traceback (most recent call last):
File "./fmutest1_opcua.py", line 12, in <module>
answer = omc.sendExpression(cmd)
File "/usr/local/lib/python3.7/dist-packages/OMPython/__init__.py", line 628, in sendExpression
answer = OMTypedParser.parseString(result)
File "/usr/local/lib/python3.7/dist-packages/OMPython/OMTypedParser.py", line 120, in parseString
return omcGrammar.parseString(string)[0]
File "/usr/local/lib/python3.7/dist-packages/pyparsing.py", line 1955, in parseString
raise exc
File "/usr/local/lib/python3.7/dist-packages/pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected end of text, found '"' (at char 15774), (line:150, col:1)
似乎OMPython解析器在解析simulate命令的结果时遇到问题,因为opcua附加标志和附加输出。我建议执行buildModel(tests.test1,stopTime=1000.0),然后使用额外的模拟标志直接从python运行可执行文件。谢谢,如果我从terminal
/tests.test1-embeddedServer=opc ua-embeddedServerPort=4841-rt=1运行模型,它工作正常。我猜模拟输出中的某些内容没有正确转义,因此OMC根据OMPython输出错误数据。似乎OMPython解析器在分析模拟命令的结果时出现问题,因为opcua附加标志和附加输出。我建议执行buildModel(tests.test1,stopTime=1000.0),然后使用额外的模拟标志直接从python运行可执行文件。谢谢,如果我从terminal/tests.test1-embeddedServer=opc ua-embeddedServerPort=4841-rt=1运行模型,它工作正常。我猜模拟输出中的某些内容没有正确转义,因此OMC根据OMPython输出错误数据。
Requested secure channel timeout to be 3600000ms, got 600000ms instead
0) QualifiedName(0:Server) -
1) QualifiedName(1:OpenModelica.step) - False
2) QualifiedName(1:OpenModelica.run) - False
3) QualifiedName(1:OpenModelica.realTimeScalingFactor) - 0.0
4) QualifiedName(1:OpenModelica.enableStopTime) - True
5) QualifiedName(1:time) - 0.0
6) QualifiedName(1:y1) - 0.0
7) QualifiedName(1:y2) - 1.0
8) QualifiedName(1:y3) - 2.0
9) QualifiedName(1:der(y1)) - 0.0
10) QualifiedName(1:der(y2)) - 0.0
11) QualifiedName(1:der(y3)) - 0.0
12) QualifiedName(1:x1) - 0.0
13) QualifiedName(1:x2) - 0.0
14) QualifiedName(1:x3) - 0.0
Traceback (most recent call last):
File "./fmutest1_opcua.py", line 12, in <module>
answer = omc.sendExpression(cmd)
File "/usr/local/lib/python3.7/dist-packages/OMPython/__init__.py", line 628, in sendExpression
answer = OMTypedParser.parseString(result)
File "/usr/local/lib/python3.7/dist-packages/OMPython/OMTypedParser.py", line 120, in parseString
return omcGrammar.parseString(string)[0]
File "/usr/local/lib/python3.7/dist-packages/pyparsing.py", line 1955, in parseString
raise exc
File "/usr/local/lib/python3.7/dist-packages/pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected end of text, found '"' (at char 15774), (line:150, col:1)
FROM debian
EXPOSE 4841
EXPOSE 4842
RUN apt-get update
RUN apt-get install nano -y
RUN apt-get install wget -y
RUN apt-get install gnupg2 -y
RUN apt-get install lsb-release -y
RUN for deb in deb deb-src; do echo "$deb http://build.openmodelica.org/apt `lsb_release -cs` stable"; done | tee /etc/apt/sources.list.d/openmodelica.list
RUN wget -q http://build.openmodelica.org/apt/openmodelica.asc -O- | apt-key add -
RUN apt-get update
RUN apt-get install python3 -y
RUN apt-get install python3-pip -y
RUN apt-get install openmodelica -y
RUN pip3 install https://github.com/OpenModelica/OMPython/archive/master.zip
RUN pip3 install matplotlib
RUN pip3 install opcua
RUN adduser --disabled-password --gecos "" artyom
RUN su artyom
USER artyom
ENV USER artyom
WORKDIR /TPPSim02/python
CMD [ "python3", "./test1_opcua.py"]