forked from RedhawkSDR/Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainch9.html
More file actions
608 lines (564 loc) · 28.3 KB
/
mainch9.html
File metadata and controls
608 lines (564 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html >
<head><title>9 Sandbox</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"">
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)">
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)">
<!-- html,2,next,javascript,charset="utf-8" -->
<meta name="src" content="main.tex">
<meta name="date" content="2013-03-12 19:46:00">
<link rel="stylesheet" type="text/css" href="main.css">
<script type="text/javascript" src="scripts/shCore.js"></script>
<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
<script type="text/javascript" src="scripts/shBrushJava.js"></script>
<script type="text/javascript" src="scripts/shBrushPython.js"></script>
<script type="text/javascript" src="scripts/shBrushBash.js"></script>
<script type="text/javascript" src="scripts/shBrushXml.js"></script>
<link href="styles/shCore.css" rel="stylesheet" type="text/css" />
<link href="styles/shThemeDefault.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
SyntaxHighlighter.all()
</script>
</head><body
>
<script>
function f() {
document.getElementById('main_content_wrap').focus();
}
if (window.addEventListener) {
window.addEventListener("load", f, false);
} else if (window.attachEvent) {
window.attachEvent("onload", f);
}
</script>
<div class="header">
<ul class="navbar">
<li><a class="logo-small" href="index.html"><img src="images/RedHawk_Logo_ALT_B_121px.png"/></a></li> <li><a href="index.html">Home</a></li>
<li><a href="gettingstarted/main.html">Getting Started</a></li>
<li><a class="active" href="main.html">Documentation</a></li>
<li><a href="download.html">Download</a></li>
<li><a href="support.html">Support</a></li>
</ul>
<div class="pattern right"></div>
<a id="forkme_banner" href="https://github.com/redhawksdr">View on GitHub</a>
</div>
<!-- Custom MAIN CONTENT -->
<div id="main_content_wrap" tabindex="0" class="outer">
<section id="main_content" class="inner">
<!--l. 1--><div class="crosslinks"><p class="noindent">[<a
href="mainch10.html" >next</a>] [<a
href="mainch8.html" >prev</a>] [<a
href="mainch8.html#tailmainch8.html" >prev-tail</a>] [<a
href="#tailmainch9.html">tail</a>] [<a
href="main.html#mainch9.html" >up</a>] </p></div>
<h2 class="chapterHead"><span class="titlemark">Chapter 9</span><br /><a
id="x11-1290009"></a>Sandbox</h2>
<h3 class="sectionHead"><span class="titlemark">9.1 </span> <a
id="x11-1300009.1"></a>Introduction</h3>
<!--l. 7--><p class="noindent" >The REDHAWK Sandbox is a Python package that can be used for testing <a
href="mainli2.html#glo:component">Components</a> and for
inspecting running <a
href="mainli2.html#glo:domain">Domains</a>. The Sandbox tools also provide a means for passing <a
href="mainap3.html#bulkio">BulkIO</a> data to
and from <a
href="mainli2.html#glo:component">Components</a> as well as plotting data pushed to uses (output) <a
href="mainli2.html#glo:port">Ports</a>. This
chapter discusses how to instantiate and test a <a
href="mainli2.html#glo:component">Component</a> using the provided Sandbox
tools.
<!--l. 11--><p class="noindent" >The Sandbox is Python-centric, so a basic knowledge of Python may be necessary for its basic use.
Accordingly, the following descriptions of the Sandbox and its usage assume a basic understanding
of Python and <a
href="mainap3.html#sca">SCA</a> <a
href="mainli2.html#glo:component">Components</a>.
<!--l. 1--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">9.2 </span> <a
id="x11-1310009.2"></a>Setup</h3>
<!--l. 2--><p class="noindent" >In order to run the Sandbox, REDHAWK must be installed and the <span
class="cmtt-12">OSSIEHOME </span>and <span
class="cmtt-12">SDRROOT</span>
environment variables must be set correctly (see <a
href="mainch2.html#x4-150002.6">Section 2.6</a>).
<!--l. 5--><p class="noindent" >In order to graphically plot data within the Sandbox, the path to the <span
class="cmtt-12">eclipse </span>directory of the
installed REDHAWK <a
href="mainap3.html#ide">IDE</a> must be specified. This can be done with the <span
class="cmtt-12">IDELocation() </span>function
within the Sandbox or by setting the environment variable <span
class="cmtt-12">RH</span><span
class="cmtt-12">_IDE </span>prior to use (see <a
href="mainch2.html#x4-160002.7">Section
2.7</a>).
<!--l. 8--><p class="noindent" >To use the Sandbox the following programs do <span class="uline">not</span> need to be running:
<ul class="itemize1">
<li class="itemize"><span
class="cmtt-12">omniNames</span>
</li>
<li class="itemize"><span
class="cmtt-12">omniEvents</span>
</li>
<li class="itemize"><span
class="cmtt-12">DomainManager</span>
</li>
<li class="itemize"><span
class="cmtt-12">DeviceManager</span></li></ul>
<!--l. 1--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">9.3 </span> <a
id="x11-1320009.3"></a>Starting the Sandbox</h3>
<!--l. 2--><p class="noindent" >The REDHAWK Sandbox, like any other Python module, may be used in another Python program
or run directly within the Python interpreter. The following examples assume that the Sandbox is
being used within the Python interpreter.
<!--l. 5--><p class="noindent" >To begin, start a Python interpreter session and import the Sandbox:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
$ python
>>> from ossie.utils import sb
]]></script>
<!--l. 12--><p class="noindent" >As with any other Python module, the built-in functions <span
class="cmtt-12">dir() </span>and <span
class="cmtt-12">help() </span>are useful when
searching for available commands.
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> dir(sb)
>>> help(sb)
]]></script>
<!--l. 19--><p class="noindent" >Though arguably not part of the startup process, it is worth noting that the <span
class="cmtt-12">start() </span>method must
be called on the Sandbox for processing to begin.
<!--l. 21--><p class="noindent" >After instatiating the desired <a
href="mainli2.html#glo:component">Components</a> and Data Sources/Sinks, the start method should be
called:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sb.start()
]]></script>
<!--l. 1--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">9.4 </span> <a
id="x11-1330009.4"></a>Working with Components</h3>
<!--l. 3--><p class="noindent" >The <span
class="cmtt-12">show() </span>command is used in order to display running <a
href="mainli2.html#glo:component">Components</a>, connections between
<a
href="mainli2.html#glo:component">Components</a>, and the <span
class="cmtt-12">SDRROOT</span>:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sb.show()
]]></script>
<!--l. 9--><p class="noindent" >To view which <a
href="mainli2.html#glo:component">Components</a> are available in <span
class="cmtt-12">SDRROOT</span>:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sb.catalog()
]]></script>
<!--l. 15--><p class="noindent" >The code below provides an example of <a
href="mainli2.html#glo:component">Component</a> interaction in the Sandbox:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> my_comp = sb.Component('<component name>')
>>> my_comp
<ossie.utils.sb.domainless.Component object at 0xb4f898cc>
>>> my_comp.api()
Component [example]:
Provides (Input) Ports ==============
Port Name Port Interface
--------- --------------
input_s IDL:BULKIO/dataShort:1.0
Uses (Output) Ports ==============
Port Name Port Interface
--------- --------------
output_s IDL:BULKIO/dataShort:1.0
Properties ==============
Property Name (Data Type) [Default Value] Current Value
------------- ----------- --------------- -------------
my_float (float/SF/32f) [None] None
my_string (string) [None] None
some_shorts (ShortSeq) [None] None
>>> my_comp.my_float
>>> my_comp.my_float = 5.0
>>> my_comp.my_float
5.0
>>> my_comp.api()
Component [example]:
Provides (Input) Ports ==============
Port Name Port Interface
--------- --------------
input_s IDL:BULKIO/dataShort:1.0
Uses (Output) Ports ==============
Port Name Port Interface
--------- --------------
output_s IDL:BULKIO/dataShort:1.0
Properties ==============
Property Name (Data Type) [Default Value] Current Value
------------- ----------- --------------- -------------
my_float (float/SF/32f) [None] 5.0
my_string (string) [None] None
some_shorts (ShortSeq) [None] None
]]></script>
<!--l. 67--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1340009.4"></a>Connecting Components</h5>
<!--l. 69--><p class="noindent" >Connecting <a
href="mainli2.html#glo:component">Components</a> is done by invoking a <span
class="cmtt-12">connect() </span>function on the uses-side (output-side)
<a
href="mainli2.html#glo:component">Component</a> with the provides-side (input-side) <a
href="mainli2.html#glo:component">Component</a> as the argument of the call.
Note that if the connections are ambiguous (more than one <a
href="mainli2.html#glo:port">Port</a> on either the uses
or provides side have matching types), an error will occur. To resolve the ambiguity,
<span
class="cmtt-12">usesPortName </span>and/or <span
class="cmtt-12">providesPortName </span>needs to be specified as arguments to the
function.
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> another_comp = sb.Component('repeater')
>>> my_comp.connect(another_comp)
True
]]></script>
<!--l. 79--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1350009.4"></a>Setting Component Log Levels</h5>
<!--l. 81--><p class="noindent" >The log level of the <a
href="mainli2.html#glo:component">Component</a> may be set using the <span
class="cmtt-12">execparams </span>argument in the <a
href="mainli2.html#glo:component">Component</a>
constructor.
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>> myComponent = sb.Component("component name",
execparams={"DEBUG_LEVEL":1})
]]></script>
<!--l. 1--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">9.5 </span> <a
id="x11-1360009.5"></a>Built-in Sources and Sinks</h3>
<!--l. 3--><p class="noindent" >REDHAWK includes a variety of helpers that allow a developer to inject data into or extract data
from <a
href="mainli2.html#glo:component">Components</a> deployed through the Sandbox. The following section describes each of these
helpers and how they are used.
<!--l. 6--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">9.5.1 </span> <a
id="x11-1370009.5.1"></a>Data Sources</h4>
<!--l. 8--><p class="noindent" >The <span
class="cmtt-12">DataSource </span>module provides a mechanism for producing <a
href="mainap3.html#bulkio">BulkIO</a> data to be sent to a
provides (input) <a
href="mainli2.html#glo:port">Port</a>. Once instantiated, a Python vector of data can be pushed to the
<span
class="cmtt-12">DataSource</span>.
<!--l. 11--><p class="noindent" >An example instantiation and use of the Data Source module can be seen below:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> input_source = sb.DataSource()
>>> input_source.connect(my_comp)
>>> my_data = range(10000)
>>> input_source.push(my_data)
]]></script>
<!--l. 20--><p class="noindent" >When the <span
class="cmtt-12">DataSource </span>sends data, it will attempt to match the data type to the type of the
associated provides (input) <a
href="mainli2.html#glo:port">Port</a>. Alternatively, the data type may be set explicitly in the
<span
class="cmtt-12">DataSource </span>constructor. Note that the default type for the <span
class="cmtt-12">DataSource </span>is <span
class="cmtt-12">short</span>, which implies
that values over 32768 may induce an exception.
<!--l. 24--><p class="noindent" >The default setting for number of bytes per <span
class="cmtt-12">pushPacket() </span>is 512000 bytes. Data is broken up into
chunks of this size before being sent via the <a
href="mainli2.html#glo:port">Port</a>’s <span
class="cmtt-12">pushPacket() </span>method. To change this default
size, set the <span
class="cmtt-12">bytesPerPush </span>argument in the <span
class="cmtt-12">DataSource </span>constructor.
<!--l. 28--><p class="noindent" >A specific module is provided for reading data from a file. This module, <span
class="cmtt-12">FileSource</span>, is used and
instantiated much like the <span
class="cmtt-12">DataSource </span>module. The most significant difference between the two
modules is the presence of a file name in the <span
class="cmtt-12">FileSource </span>constructor.
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> input_file = sb.FileSource('~/short_file.tmp')
]]></script>
<!--l. 36--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1380009.5.1"></a>Adding Keywords in Data Sources</h5>
<!--l. 38--><p class="noindent" ><a
href="mainap3.html#sri">SRI</a> keywords may be generated and sent with data from the <span
class="cmtt-12">DataSource </span>module.
<!--l. 40--><p class="noindent" >An example generate/send can be seen below:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> kw = sb.SRIKeyword("SOME_RF",155000000.0,'double')
>>> kw2 = sb.SRIKeyword("EFFECTIVE_BITS_PER_SAMPLE",16,'long')
>>> keywords = [kw, kw2]
>>> input_data = sb.DataSource()
>>> data = range(1000)
>>> input_data.connect(my_comp)
>>> sb.start()
>>> input_data.push(data,SRIKeywords=keywords)
]]></script>
<!--l. 53--><p class="noindent" >The <span
class="cmtt-12">SRIKeyword() </span>constructor takes in the following arguments:
<ul class="itemize1">
<li class="itemize">name - A string representing the name of the keyword being set.
</li>
<li class="itemize">value - The value to be set.
</li>
<li class="itemize">format - A string indicating the data type of the value. Valid data types are short,
ushort, float, double, long, ulong, longlong, ulonglong, char, octet, string, boolean.</li></ul>
<!--l. 61--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1390009.5.1"></a>Sending Messages to a Component</h5>
<!--l. 63--><p class="noindent" ><a
href="mainli2.html#glo:message">Messages</a> can be sent to <a
href="mainli2.html#glo:component">Components</a> using the <span
class="cmtt-12">MessageSource </span>module. <a
href="mainli2.html#glo:message">Messages</a> sent to the
<span
class="cmtt-12">sendMessage() </span>method can be one of four types: struct, dictionary, <a
href="mainap3.html#corba">CORBA</a> Any, and data types
that can be mapped to a <a
href="mainap3.html#corba">CORBA</a> Any.
<!--l. 66--><p class="noindent" >The default <a
href="mainli2.html#glo:message">Message</a> id is <span
class="cmtt-12">sb</span><span
class="cmtt-12">_struct</span>:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> mySource = MessageSource()
>>> myComponet = sb.Component("test_message_rx_cpp")
>>> mySource.connect(myComponent)
>>> sb.start()
>>> msg = {"val1":"test string", "val2":123}
>>> mySource.sendMessage(msg)
]]></script>
<!--l. 78--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">9.5.2 </span> <a
id="x11-1400009.5.2"></a>Data Sinks</h4>
<!--l. 80--><p class="noindent" >The Sandbox provides a <span
class="cmtt-12">DataSink </span>module, which simply reads data from a uses (output) <a
href="mainli2.html#glo:port">Port</a>.
Below is an example instantiation and use of the <span
class="cmtt-12">DataSink </span>module. In this example, data sent
from <span
class="cmtt-12">myComponet</span>’s uses (output) <a
href="mainli2.html#glo:port">Port</a> is written to the <span
class="cmtt-12">received</span><span
class="cmtt-12">_data </span>variable.
<!--l. 84--><p class="noindent" ><a
href="mainap3.html#sri">SRI</a> associated with the packet can be viewed using the <span
class="cmtt-12">sri() </span>method:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> output_data = sb.OutputData()
>>> myComponent.connect(output_data)
>>> received_data = output_data.getData()
>>> received_sri = output_data.sri()
]]></script>
<!--l. 93--><p class="noindent" >To block until a certain amount of data is received, specify the data length as an argument to the
<span
class="cmtt-12">getData() </span>method:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> received_data = output_data.getData(100)
]]></script>
<!--l. 99--><p class="noindent" >The <span
class="cmtt-12">eos() </span>method will indicate whether or not an End of Stream (<a
href="mainap3.html#eos">EOS</a>) was received:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> output_data.eos()
False
]]></script>
<!--l. 106--><p class="noindent" >The <span
class="cmtt-12">eos</span><span
class="cmtt-12">_block </span>argument may be used to configure the <span
class="cmtt-12">getData() </span>method to block until an <a
href="mainap3.html#eos">EOS</a>
is received:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> received_data = output_data.getData(eos_block=True)
]]></script>
<!--l. 112--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1410009.5.2"></a>Writing a File</h5>
<!--l. 114--><p class="noindent" >Similar to the <span
class="cmtt-12">DataSource</span>’s <span
class="cmtt-12">FileSource </span>counterpart, the <span
class="cmtt-12">DataSink </span>has an associated <span
class="cmtt-12">FileSink</span>
module for writing data to a file:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> output_file = sb.FileSink('~/some_file.tmp')
>>> another_comp.connect(output_file)
]]></script>
<!--l. 121--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1420009.5.2"></a>Displaying Messages</h5>
<!--l. 123--><p class="noindent" ><a
href="mainli2.html#glo:message">Messages</a> may be displayed using the <span
class="cmtt-12">MessageSink </span>module. Data sent to a running <span
class="cmtt-12">MessageSink</span>
will be printed in the Python interpreter.
<!--l. 126--><p class="noindent" >Below is an example of <span
class="cmtt-12">MessageSink </span>usage:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> myComponent = sb.Component("test_message_send_cpp")
>>> myMessageSink = MessageSink()
>>> myComponent.connect(myMessageSink)
>>> sb.start()
]]></script>
<!--l. 135--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">9.5.3 </span> <a
id="x11-1430009.5.3"></a>Usage Examples</h4>
<!--l. 137--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1440009.5.3"></a>Plotting Data Example</h5>
<!--l. 139--><p class="noindent" >Note that for plotting data, the REDHAWK <a
href="mainap3.html#ide">IDE</a> must be installed and the path to the <span
class="cmtt-12">eclipse</span>
directory of the installed <a
href="mainap3.html#ide">IDE</a> must be specified to the Sandbox.
<!--l. 141--><p class="noindent" >This can be done through the <span
class="cmtt-12">IDELocation() </span>function:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sb.IDELocation('/path/to/ide/eclipse')
]]></script>
<!--l. 147--><p class="noindent" >This can also be done by setting the <span
class="cmtt-12">RH</span><span
class="cmtt-12">_IDE </span>environment variable prior to starting the Python
session. (See <a
href="mainch2.html#x4-160002.7">Section 2.7</a>)
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> input_source = sb.DataSource()
>>> my_data = range(10000)
>>> my_plot = sb.Plot()
>>> input_source.connect(my_plot)
>>> input_source.push(my_data)
]]></script>
<!--l. 159--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1450009.5.3"></a>Continuous Data Flow Example</h5>
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> input_source.push(my_data,loop=True)
]]></script>
<ul class="itemize1">
<li class="itemize">To see a falling raster of the data being pushed, click on “Show Raster” in the upper
right of the plot window
</li>
<li class="itemize">To stop looping data, do the following:</li></ul>
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> input_source.stop()
]]></script>
<!--l. 174--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1460009.5.3"></a>File Data Plotting Example</h5>
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> input_file = sb.FileSource('~/short_file.tmp',midasFile=True)
>>> my_plot = sb.Plot()
>>> input_file.connect(my_plot)
>>> input_file.start()
]]></script>
<!--l. 183--><p class="noindent" >
<h5 class="subsubsectionHead"><a
id="x11-1470009.5.3"></a>Passing a Struct to sendMessage Example</h5>
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
from ossie.utils import sb
from ossie.properties import simple_property
class MessageProp(object):
val1 = simple_property(id_="val1",
type_="string",
defvalue="trm")
val2 = simple_property(id_="val2",
type_="double",
defvalue=1211)
def __init__(self):
"""Construct an initialized instance of this struct
definition"""
for attrname, classattr in type(self).__dict__.items():
if type(classattr) == simple_property:
classattr.initialize(self)
def __str__(self):
"""Return a string representation of this structure"""
d = {}
d["val1"] = self.val1
d["val2"] = self.val2
return str(d)
def getId(self):
return "message_prop"
def isStruct(self):
return True
def getMembers(self):
return [("val1",self.val1),("val2",self.val2)]
testmessage = MessageProp()
testmessage.val1 = "test string"
testmessage.val2 = 123
a = sb.MessageSource()
b = sb.Component("test_message_rx_cpp")
a.connect(b)
sb.start()
a.sendMessage(testmessage)
]]></script>
<!--l. 1--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">9.6 </span> <a
id="x11-1480009.6"></a>Miscellaneous</h3>
<!--l. 3--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">9.6.1 </span> <a
id="x11-1490009.6.1"></a>Saving and Loading Waveforms</h4>
<!--l. 5--><p class="noindent" >The <a
href="mainli2.html#glo:component">Components</a> making up a <a
href="mainli2.html#glo:waveformapplication">Waveform</a> can be loaded into the workspace by passing the path
and name of the <a
href="mainli2.html#glo:waveformapplication">Waveform</a>’s <a
href="mainap3.html#sad">SAD</a> <a
href="mainap3.html#xml">XML</a> file to the <span
class="cmtt-12">loadSadFile() </span>method. Note that <span
class="cmtt-12">usesdevice</span>
relationships are ignored when loading a <a
href="mainap3.html#sad">SAD</a> file onto the Sandbox.
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sb.loadSadFile("/path/to/sad/file/waveform.sad.xml")
]]></script>
<!--l. 12--><p class="noindent" >The instantiated <a
href="mainli2.html#glo:component">Components</a> and their associated connections can also be saved as a <a
href="mainli2.html#glo:waveformapplication">Waveform</a>.
To perform this operation, pass the desired <a
href="mainli2.html#glo:waveformapplication">Waveform</a> name to the <span
class="cmtt-12">generateSADXML()</span>
method.
<!--l. 15--><p class="noindent" >This method will return an <a
href="mainap3.html#xml">XML</a> string representing the contents of the <a
href="mainap3.html#sad">SAD</a> file; this string may
then be written to a file:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sadString = sb.generateSADXML("waveform_name")
>>> fp=open("/path/to/sad/file/waveform_name.sad.xml","w")
>>> fp.write(sadString)
>>> fp.close()
]]></script>
<!--l. 24--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">9.6.2 </span> <a
id="x11-1500009.6.2"></a>Debug Statements and Standard Out</h4>
<!--l. 26--><p class="noindent" >Standard out and standard error can be redirected to a file:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sb.redirectSTDOUT("/path/to/file/file.txt")
]]></script>
<!--l. 32--><p class="noindent" >Debug statements can be toggled on or off, or set explicitly.
<!--l. 34--><p class="noindent" >To toggle the on/off status of the debug statements, call the <span
class="cmtt-12">debug() </span>method with no
arguments:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sandbox.debug()
]]></script>
<!--l. 40--><p class="noindent" >Alternatively, to set the debug output status explicitly, pass <span
class="cmtt-12">True </span>or <span
class="cmtt-12">False </span>to the <span
class="cmtt-12">debug()</span>
method:
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> sandbox.debug(True)
]]></script>
<!--l. 1--><div class="crosslinks"><p class="noindent">[<a
href="mainch10.html" >next</a>] [<a
href="mainch8.html" >prev</a>] [<a
href="mainch8.html#tailmainch8.html" >prev-tail</a>] [<a
href="mainch9.html" >front</a>] [<a
href="main.html#mainch9.html" >up</a>] </p></div>
<!--l. 1--><p class="noindent" ><a
id="tailmainch9.html"></a>
<div class=license>
<hr>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" /></a><br /><span xmlns:dct="http:// purl.org/dc/terms/" property="dct:title">REDHAWK Documentation</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.
</div>
</body></html>