| Name | Description |
|---|---|
| Package with base classes for BCVTB interface | |
| Block that exchanges data with the Building Controls Virtual Test Bed | |
| Collection of models that illustrate model use and test models |
Buildings.Utilities.IO.BCVTB.BCVTB
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).
| Type | Name | Default | Description |
|---|---|---|---|
| Time | samplePeriod | Sample period of component [s] | |
| Time | startTime | 0 | First sample time instant [s] |
| String | xmlFileName | "socket.cfg" | Name of the file that is generated by the BCVTB and that contains the socket information |
| Integer | nDblWri | Number of double values to write to the BCVTB | |
| Integer | nDblRea | Number of double values to be read from the BCVTB |
| Type | Name | Description |
|---|---|---|
| input RealInput | uR[nDblWri] | Real inputs to be sent to the BCVTB |
| output RealOutput | yR[nDblRea] | Real outputs received from the BCVTB |
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;