Buildings.Utilities.IO.BCVTB

Package with functions to communicate with the Building Controls Virtual Test Bed

Information


This package contains an interface to the 
Building Controls Virtual Test Bed
(BCVTB).
The BCVTB is a middleware that is based on 
Ptolemy II.
Ptolemy II is a software framework to study modeling, simulation, and design of concurrent, real-time, embedded systems, with focus on the assembly of concurrent components and the use of heterogeneous mixtures of models of computation that govern the interactions between components. The BCVTB adds functionalities to Ptolemy II that allows coupling Modelica, 
EnergyPlus and
MATLAB/Simulink
for data exchange during the time step integration.

Package Content

NameDescription
Buildings.Utilities.IO.BCVTB.BaseClasses BaseClasses Package with base classes for BCVTB interface
Buildings.Utilities.IO.BCVTB.BCVTB BCVTB Block that exchanges data with the Building Controls Virtual Test Bed
Buildings.Utilities.IO.BCVTB.Examples Examples Collection of models that illustrate model use and test models


Buildings.Utilities.IO.BCVTB.BCVTB Buildings.Utilities.IO.BCVTB.BCVTB

Block that exchanges data with the Building Controls Virtual Test Bed

Buildings.Utilities.IO.BCVTB.BCVTB

Information


Block that exchanges data with the 
Building Controls Virtual Test Bed.

At the start of the simulation, this block establishes a socket connection using the Berkeley Software Distribution socket (BSD socket). At each sampling interval, data are exchanged between Modelica and the Building Controls Virtual Test Bed. When Dymola terminates, a signal is sent to the Building Controls Virtual Test Bed so that it can gracefully terminate.


Extends from Modelica.Blocks.Interfaces.DiscreteBlock (Base class of discrete control blocks).

Parameters

TypeNameDefaultDescription
TimesamplePeriod Sample period of component [s]
TimestartTime0First sample time instant [s]
StringxmlFileName"socket.cfg"Name of the file that is generated by the BCVTB and that contains the socket information
IntegernDblWri Number of double values to write to the BCVTB
IntegernDblRea Number of double values to be read from the BCVTB

Connectors

TypeNameDescription
input RealInputuR[nDblWri]Real inputs to be sent to the BCVTB
output RealOutputyR[nDblRea]Real outputs received from the BCVTB

Modelica definition

model BCVTB 
  "Block that exchanges data with the Building Controls Virtual Test Bed"
  extends Modelica.Blocks.Interfaces.DiscreteBlock;
  parameter String xmlFileName = "socket.cfg" 
    "Name of the file that is generated by the BCVTB and that contains the socket information";
  parameter Integer nDblWri(min=0) 
    "Number of double values to write to the BCVTB";
  parameter Integer nDblRea(min=0) 
    "Number of double values to be read from the BCVTB";
  Modelica.Blocks.Interfaces.RealInput uR[nDblWri] 
    "Real inputs to be sent to the BCVTB";
  Modelica.Blocks.Interfaces.RealOutput yR[nDblRea] 
    "Real outputs received from the BCVTB";

 Integer flaRea "Flag received from BCVTB";
 Modelica.SIunits.Time simTimRea 
    "Current simulation time received from the BCVTB";
 Integer retVal "Return value from the BSD socket data exchange";
protected 
  parameter Integer socketFD(fixed=false) 
    "Socket file descripter, or a negative value if an error occured";
  constant Integer flaWri=0;
initial algorithm 
  socketFD :=Buildings.Utilities.IO.BCVTB.BaseClasses.establishClientSocket(
    xmlFileName=xmlFileName);
    // check for valid socketFD
     assert(socketFD >= 0, "Socket file descripter for BCVTB must be positive.\n" +
                         "   A negative value indicates that no connection\n" +
                         "   could be established. Check file 'utilSocket.log'.\n" +
                         "   Received: socketFD = " + integerString(socketFD));
   flaRea :=0;
algorithm 
  when {sampleTrigger} then
    assert(flaRea == 0, "BCVTB interface attempts to exchange data after Ptolemy reached final its final time.\n" +
                        "   Aborting simulation. Check file final time in Modelica and in Ptolemy.\n" +
                        "   Received: flaRea = " + integerString(flaRea));

    // exchange data
    (flaRea, simTimRea, yR, retVal) :=
      Buildings.Utilities.IO.BCVTB.BaseClasses.exchangeReals(
      socketFD=socketFD,
      flaWri=flaWri,
      simTimWri=time,
      dblValWri=uR,
      nDblWri=size(uR, 1),
      nDblRea=size(yR, 1));
    // check for valid return flags
    assert(flaRea >= 0, "BCVTB sent a negative flag to Modelica during data transfer.\n" +
                        "   Aborting simulation. Check file 'utilSocket.log'.\n" +
                        "   Received: flaRea = " + integerString(flaRea));
    assert(retVal >= 0, "Obtained negative return value during data transfer with BCVTB.\n" +
                        "   Aborting simulation. Check file 'utilSocket.log'.\n" +
                        "   Received: retVal = " + integerString(retVal));
  end when;
   // close socket connnection
   when terminal() then
      Buildings.Utilities.IO.BCVTB.BaseClasses.closeClientSocket(
                                                        socketFD);
   end when;

end BCVTB;

HTML-documentation generated by Dymola Fri May 15 10:15:40 2009.