2017-05-31 12 views
1

私はopenmodelicaインターフェイスを持っています。openmodelicaの出力ブロックから入力ブロックへの接続方法は?

block InputInterfaceBlock 

    CPSModel.ConnectionObjects.SocketConnection con =  CPSModel.ConnectionObjects.SocketConnection("/pathToSocket/rpcSocket"); 

    Modelica.Blocks.Interfaces.RealOutput y annotation(
    Placement(visible = true, transformation(origin = {194, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); 

algorithm 
    while true loop 
    y := CPSModel.Functions.readFromSocket(con); 
    print("Message from server : " + String(y) + "\n"); 
    end while; 

    annotation(
    __OpenModelica_simulationFlags(jacobian = "coloredNumerical", s = "dassl", lv = "LOG_STATS"), 
uses(Modelica(version = "3.2.2")), 
Icon(graphics = {Text(origin = {4, -1}, extent = {{-62, 73}, {62, -73}}, textString = "Input\nInterface", fontName =   "DejaVu Sans Mono Bold")})); 

    annotation(
    Placement(visible = true, transformation(origin = {-70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); 
end InputInterfaceBlock; 

Iパスに定義されているソケットから読み出しインターフェースブロック(InputInterfaceBlock)を有します。このインターフェイスブロックを別のブロック(OutputInterfaceBlock)に接続します。

block OutputInterfaceBlock 

    CPSModel.ConnectionObjects.SocketConnection con = CPSModel.ConnectionObjects.SocketConnection("pathToModel/rpcSocket"); 

    Modelica.Blocks.Interfaces.RealInput y annotation(
    Placement(visible = true, transformation(origin = {194, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); 

algorithm 
    print("Trying to send : " + String(y) + "\n"); 
     CPSModel.Functions.writeToSocket(con, y); 
     print("Message send to server." + "\n"); 

annotation(
    __OpenModelica_simulationFlags(jacobian = "coloredNumerical", s = "dassl", lv = "LOG_STATS"), 
uses(Modelica(version = "3.2.2")), 
Icon(graphics = {Text(origin = {4, -1}, extent = {{-62, 73}, {62, -73}}, textString = "Output\nInterface", fontName = "DejaVu Sans Mono")})); 
    annotation(
    Placement(visible = true, transformation(origin = {-70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); 
end OutputInterfaceBlock; 

マイモデルは次のとおりです。

model MechatronicSystem 

    CPSModel.Models.InputInterfaceBlock Input annotation(
     Placement(visible = true, transformation(origin = {-90, 8}, extent = {{-28, -28}, {28, 28}}, rotation = 0))); 

    CPSModel.Models.OutputInterfaceBlock Output annotation(
     Placement(visible = true, transformation(origin = {72, 12}, extent = {{28, 28}, {-28, -28}}, rotation = 0))); 

equation 
    connect(Input.y, Output.y) annotation(
    Line(points = {{-60, 8}, {44, 8}, {44, 12}, {42, 12}}, color = {0, 0, 127})); 
annotation(
     uses(Modelica(version = "3.2.2"))); 
end MechatronicSystem; 

私がモデルにソケットからInputInterfaceBlockでデータを受け取ることができますが、私はOutputInterfaceBlockにそのデータを送信しようとします。 OutputInterfaceBlockに届いていません。私はそれを修正するにはどうすればよい

答えて

3

InputInterfaceBlockにはwhile trueループが使用されていますが、Modelicaのさまざまなアルゴリズムはコルーチンではなく通常のアルゴリズムです。

when sample(0.1,0.1) then ... end when;に置き換えることもできますし、同様に0.1秒ごとにコードを実行することもできます。

whileループは、モデルがInputInterfaceBlockにスタックされ、OutputInterfaceBlockが呼び出されないようにします。

関連する問題