1

I have an openmodelica interface.

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 have an interface block (InputInterfaceBlock) which reads from a socket which is defined in the path. I want this interface block to connect to another block (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;

My model is as follows.

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;

I can receive the data in the InputInterfaceBlock from the socket to the model, but when I try to send that data to OutputInterfaceBlock. It is not getting received in the OutputInterfaceBlock.

How can I fix it ?

1 Answer 1

3

You are using a while true loop in InputInterfaceBlock, but the different algorithms in Modelica are not co-routines but normal algorithms.

You could replace that with when sample(0.1,0.1) then ... end when; or similarly, which will run the code every 0.1s seconds.

The while-loop causes the model should be stuck in InputInterfaceBlock and OutputInterfaceBlock not be called.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.