Building Controls Virtual Test Bed
ADInterfaceMCCReader.java
Go to the documentation of this file.
1 // Connect to ADInterfaceMCC and read data from a ADInterfaceMCC device.
2 
3 /*
4 ********************************************************************
5 Copyright Notice
6 ----------------
7 
8 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
9 Regents of the University of California, through Lawrence Berkeley
10 National Laboratory (subject to receipt of any required approvals from
11 the U.S. Dept. of Energy). All rights reserved.
12 
13 If you have questions about your rights to use or distribute this
14 software, please contact Berkeley Lab's Technology Transfer Department
15 at TTD@lbl.gov
16 
17 NOTICE. This software was developed under partial funding from the U.S.
18 Department of Energy. As such, the U.S. Government has been granted for
19 itself and others acting on its behalf a paid-up, nonexclusive,
20 irrevocable, worldwide license in the Software to reproduce, prepare
21 derivative works, and perform publicly and display publicly. Beginning
22 five (5) years after the date permission to assert copyright is obtained
23 from the U.S. Department of Energy, and subject to any subsequent five
24 (5) year renewals, the U.S. Government is granted for itself and others
25 acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide
26 license in the Software to reproduce, prepare derivative works,
27 distribute copies to the public, perform publicly and display publicly,
28 and to permit others to do so.
29 
30 
31 Modified BSD License agreement
32 ------------------------------
33 
34 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
35 Regents of the University of California, through Lawrence Berkeley
36 National Laboratory (subject to receipt of any required approvals from
37 the U.S. Dept. of Energy). All rights reserved.
38 
39 Redistribution and use in source and binary forms, with or without
40 modification, are permitted provided that the following conditions are met:
41 
42  1. Redistributions of source code must retain the above copyright
43  notice, this list of conditions and the following disclaimer.
44  2. Redistributions in binary form must reproduce the above copyright
45  notice, this list of conditions and the following disclaimer in
46  the documentation and/or other materials provided with the
47  distribution.
48  3. Neither the name of the University of California, Lawrence
49  Berkeley National Laboratory, U.S. Dept. of Energy nor the names
50  of its contributors may be used to endorse or promote products
51  derived from this software without specific prior written permission.
52 
53 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
54 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
56 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
57 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 
65 You are under no obligation whatsoever to provide any bug fixes,
66 patches, or upgrades to the features, functionality or performance of
67 the source code ("Enhancements") to anyone; however, if you choose to
68 make your Enhancements available either publicly, or directly to
69 Lawrence Berkeley National Laboratory, without imposing a separate
70 written license agreement for such Enhancements, then you hereby grant
71 the following license: a non-exclusive, royalty-free perpetual license
72 to install, use, modify, prepare derivative works, incorporate into
73 other computer software, distribute, and sublicense such enhancements or
74 derivative works thereof, in binary and source code form.
75 
76 ********************************************************************
77 */
78 package adInterfaceMCC.actor;
79 import java.util.ArrayList;
80 
83 import ptolemy.actor.TypedIOPort;
84 import ptolemy.data.ArrayToken;
85 import ptolemy.data.DoubleMatrixToken;
86 import ptolemy.data.DoubleToken;
87 import ptolemy.data.MatrixToken;
88 import ptolemy.data.expr.Token;
89 import ptolemy.data.type.ArrayType;
90 import ptolemy.data.type.BaseType;
91 import ptolemy.kernel.CompositeEntity;
92 import ptolemy.kernel.util.IllegalActionException;
93 import ptolemy.kernel.util.NameDuplicationException;
94 import ptolemy.kernel.util.Workspace;
95 
104 public class ADInterfaceMCCReader extends ADInterfaceMCC {
105 
114  public ADInterfaceMCCReader(CompositeEntity container, String name)
115  throws IllegalActionException, NameDuplicationException {
116  super(container, name);
117  proVal = new TypedIOPort(this,"propertyValue",false,true);
118  //proValArr.setTypeEquals(new ArrayType(BaseType.DOUBLE));
119  proVal.setTypeEquals(BaseType.DOUBLE_MATRIX);
120 
121 
122  /*Use trigger port to fire ADInterfaceMCCReader
123  */
124  trigger = new TypedIOPort(this, "trigger", true, false);
125  trigger.setMultiport(true);
126  }
127 
130 
131  public TypedIOPort proVal;
132 
134  public TypedIOPort trigger;
137 
143  public Object clone(Workspace workspace) throws CloneNotSupportedException {
144  ADInterfaceMCCReader newObject = (ADInterfaceMCCReader) (super.clone(workspace));
145  // set the type constraints
146  //newObject.proValArr.setTypeEquals(new ArrayType(BaseType.DOUBLE));
147  newObject.proVal.setTypeEquals(BaseType.DOUBLE_MATRIX);
148  return newObject;
149  }
150 
153 
159  public ArrayList<ADInterfaceMCCObjectType> propertyValueReader(ArrayList<ADInterfaceMCCObjectType> propValArray) throws IllegalActionException
160  {
161  ArrayList<ADInterfaceMCCObjectType> proparr = new ArrayList<ADInterfaceMCCObjectType>();
162 
163  for (int i = 0; i < propValArray.size(); i++)
164  {
165  if (propValArray.get(i).getApplicationTag().equals("READ")){
166  proparr.add(propValArray.get(i));
167  }
168  }
169  return proparr;
170  }
171 
181  public void initialize() throws IllegalActionException
182  {
183  super.initialize();
184 
185  /* Check if application tag is part of the standard,
186  if priority and index are integers*/
188 
189  /* Set trigger state to be true*/
190  fireReader = true;
191  }
192 
193 
202  public void sendToken() throws IllegalActionException
203  {
204  super.sendToken();
205  //proValArr.send(0,new ArrayToken(BaseType.DOUBLE,propval_tok));
206  //proValArr.send(0, MatrixToken.arrayToMatrix(BaseType.DOUBLE, propval_tok, 1, propval_tok.length));
207  proVal.send(0, new DoubleMatrixToken(propval_tok, propval_tok.length, 1));
208  //proValArr.send(0, propval_tok);
209 
210  }
211 
219  public void fire() throws IllegalActionException {
220  super.fire();
221  /*Set trigger state
222  */
223  setTriggerState();
224  if(fireReader){
225 
226  // create a new array with only value for the reader
228 
229  /*Prepare processes to be executed*/
230  proc_arr = adDevMan.getProcesses(prop_arr_reader);
231 
232  /*Prepare the tokens to be sent to outlet port
233  */
235  /*Send tokens to outlet port
236  */
237  sendToken();
238 
239  /*Remove token in last time step*/
240  removeToken();
241  }
242  }
243 
248  protected void setSchemaFileName(){
250  bcvtbhome + FS + "lib" + FS + "ptII" + FS + "adInterfaceMCC" + FS + "ADInterfaceMCC.xsd";
251  }
252 
257  protected void setTriggerState() throws IllegalActionException
258  {
259  if(trigger.numberOfSources()>0)
260  {
261  fireReader = false;
262  if(trigger.hasToken(0))
263  {
264  fireReader = true;
265  }
266  }
267  }
270 
272  protected boolean fireReader;
273 
274 
278  public static ArrayList<ADInterfaceMCCObjectType> prop_arr_reader;
279 }
void setSchemaFileName()
Sets the schema file name.
This class reads the XML configuration file and stores the data in the ADInterfaceMCCObjectType data ...
for i
Definition: compile.m:69
static final String bcvtbhome
String that points to root directory of the BCVTB.
ArrayList< ProcessBuilder > proc_arr
Arraylist containing processes to be executed in console.
void prepareTokensToSend()
Get tokens to send for the next timestep.
void sendToken()
Sends the error signal to the errorSignal port, the error message to the errorMessage port...
ADInterfaceMCCReader(CompositeEntity container, String name)
Construct an actor with the given container and name.
boolean fireReader
Boolean state to trigger ADInterfaceMCCReader.
ArrayList< ADInterfaceMCCObjectType > prop_arr
Arraylist containing ADInterfaceMCCObjectType read from configuration file.
Token[] propval_tok
Token array of property values.
TypedIOPort proVal
The port that sends the array of property value.
static final String FS
File seperator.
Object clone(Workspace workspace)
Override base class defined in ADInterfaceMCC.java.
TypedIOPort trigger
The port that fires ADInterfaceMCCReader.
static ArrayList< ADInterfaceMCCObjectType > prop_arr_reader
ADInterfaceMCCObjectType after considering just the reader objects from Ptolemy.
void fire()
Read ADInterfaceMCC property based on the configuration file or If Plattform is Mac or Linux or If I/...
String schemaFileName
Schema file path.
void validateAttributes()
Validate application tag.
void initialize()
Initialize section, initialize variables, check possible errors.
ArrayList< ADInterfaceMCCObjectType > propertyValueReader(ArrayList< ADInterfaceMCCObjectType > propValArray)
Create a new array with only the elements of the configuration that are for the reader.
void removeToken()
Remove tokens in previous time step.
This is an abstract base class for actors that generates an output stream.
This actor reads from ADInterfaceMCC devices.