Building Controls Virtual Test Bed
BACnetReader.java
Go to the documentation of this file.
1 // Connect to BACnet and read data from a BACnet 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 bacnet.actor;
80 import bacnet.util.BACnet;
82 import ptolemy.actor.TypedIOPort;
83 import ptolemy.data.ArrayToken;
84 import ptolemy.data.Token;
85 import ptolemy.data.IntToken;
86 import ptolemy.data.StringToken;
87 import ptolemy.data.BooleanToken;
88 import ptolemy.data.type.ArrayType;
89 import ptolemy.data.type.BaseType;
90 import ptolemy.kernel.CompositeEntity;
91 import ptolemy.kernel.util.IllegalActionException;
92 import ptolemy.kernel.util.InternalErrorException;
93 import ptolemy.kernel.util.NameDuplicationException;
94 import ptolemy.kernel.util.Workspace;
95 import ptolemy.kernel.util.StringAttribute;
96 import java.lang.Exception;
97 import java.util.ArrayList;
98 import java.io.IOException;
99 import java.io.File;
100 import java.io.StringWriter;
101 import java.io.PrintWriter;
102 import org.xml.sax.SAXParseException;
103 import org.xml.sax.SAXException;
104 import javax.xml.XMLConstants;
105 import javax.xml.validation.SchemaFactory;
106 import javax.xml.parsers.ParserConfigurationException;
107 import javax.naming.OperationNotSupportedException;
109 //BACnetReader
110 
119 public class BACnetReader extends BACnet {
120 
129  public BACnetReader(CompositeEntity container, String name)
130  throws IllegalActionException, NameDuplicationException {
131  super(container, name);
132  proValArr = new TypedIOPort(this,"propertyValueArray",false,true);
133  proValArr.setTypeEquals(new ArrayType(BaseType.STRING));
134 
135  /*Use trigger port to fire BACnetReader
136  */
137  trigger = new TypedIOPort(this, "trigger", true, false);
138  trigger.setMultiport(true);
139  }
140 
143 
144  public TypedIOPort proValArr;
145 
147  public TypedIOPort trigger;
150 
156  public Object clone(Workspace workspace) throws CloneNotSupportedException {
157  BACnetReader newObject = (BACnetReader) (super.clone(workspace));
158  // set the type constraints
159  newObject.proValArr.setTypeEquals(new ArrayType(BaseType.STRING));
160  return newObject;
161  }
162 
172  public void initialize() throws IllegalActionException
173  {
174  super.initialize();
175 
176  /*Preapre processes to be executed
177  */
178  proc_arr = bacDevMan.getProcesses(prop_arr);
179  /* Set trigger state to be true
180  */
181  fireReader = true;
182  }
183 
184 
193  public void sendToken() throws IllegalActionException
194  {
195  super.sendToken();
196  proValArr.send(0,new ArrayToken(BaseType.STRING,propval_tok));
197  }
198 
207  public void fire() throws IllegalActionException {
208  super.fire();
209  /*Set trigger state
210  */
211  setTriggerState();
212  if(fireReader){
213  /*Prepare the tokens to be sent to outlet port
214  */
216  /*Send tokens to outlet port
217  */
218  sendToken();
219 
220  /*Remove token in last time step*/
221  removeToken();
222  }
223  }
224 
229  protected void setSchemaFileName(){
231  bcvtbhome + FS + "lib" + FS + "ptII" + FS + "bacnet" + FS + "BACnetReader.xsd";
232  }
233 
238  protected void setTriggerState() throws IllegalActionException
239  {
240  if(trigger.numberOfSources()>0)
241  {
242  fireReader = false;
243  if(trigger.hasToken(0))
244  {
245  fireReader = true;
246  }
247  }
248  }
251 
253  protected boolean fireReader;
254 
255 
256 }
String schemaFileName
Schema file path.
Definition: BACnet.java:897
TypedIOPort trigger
The port that fires BACnetReader.
void sendToken()
Sends the error signal to the errorSignal port, the error message to the errorMessage port...
Object clone(Workspace workspace)
Override base class defined in BACnet.java.
boolean fireReader
Boolean state to trigger BACnetReader.
This class reads the XML configuration file and stores the data in the BACnetObjectType data type...
void fire()
Read BACnet property based on the configuration file If globalwi binary cannot be found or If I/O err...
void removeToken()
Remove tokens in previous time step.
Definition: BACnet.java:841
void initialize()
Initialize section, initialize variables, check possible errors.
This is an abstract base class for actors that generates an output stream.
Definition: BACnet.java:117
static final String FS
File seperator.
Definition: BACnet.java:957
This class is used to create objects that have the information from the xml configuration file...
This actor reads from BACnet devices.
ArrayList< BACnetCompleteProperty > prop_arr
Arraylist containing BACnetCompleteProperty read from configuration file.
Definition: BACnet.java:916
TypedIOPort proValArr
The port that sends the array of property value.
void setTriggerState()
Set trigger state.
void prepareTokensToSend()
Get tokens to send for the next timestep.
Definition: BACnet.java:784
ArrayList< ProcessBuilder > proc_arr
Arraylist containing processes to be executed in console.
Definition: BACnet.java:920
static final String bcvtbhome
String that points to root directory of the BCVTB.
Definition: BACnet.java:963
Token[] propval_tok
Token array of property values.
Definition: BACnet.java:933
BACnetReader(CompositeEntity container, String name)
Construct an actor with the given container and name.
void setSchemaFileName()
Sets the schema file name.