summaryrefslogtreecommitdiff
path: root/grc/blocks/variable_function_probe.xml
blob: 269966c70d6d8b2a6b405db9536f7ea566e1b5c3 (plain)
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
<?xml version="1.0"?>
<!--
###################################################
##Variable function probe
###################################################
 -->
<block>
	<name>Function Probe</name>
	<key>variable_function_probe</key>
	<import>import time</import>
	<import>import threading</import>
	<var_make>self.$(id) = $(id) = $value</var_make>
	<make>#slurp
def _$(id)_probe():
	while True:
		val = self.$(block_id()).$(function_name())($(function_args()))
		try: self.set_$(id)(val)
		except AttributeError, e: pass
		time.sleep(1.0/($poll_rate))
_$(id)_thread = threading.Thread(target=_$(id)_probe)
_$(id)_thread.daemon = True
_$(id)_thread.start()</make>
	<callback>self.set_$(id)($value)</callback>
	<param>
		<name>Value</name>
		<key>value</key>
		<value>0</value>
		<type>raw</type>
	</param>
	<param>
		<name>Block ID</name>
		<key>block_id</key>
		<value>my_block_0</value>
		<type>string</type>
	</param>
	<param>
		<name>Function Name</name>
		<key>function_name</key>
		<value>get_number</value>
		<type>string</type>
	</param>
	<param>
		<name>Function Args</name>
		<key>function_args</key>
		<value></value>
		<type>string</type>
		<hide>#if $function_args() then 'none' else 'part'#</hide>
	</param>
	<param>
		<name>Poll Rate (Hz)</name>
		<key>poll_rate</key>
		<value>10</value>
		<type>real</type>
	</param>
	<doc>
Periodically probe a function and set its value to this variable.

Set the values for block ID, function name, and function args appropriately: \
Block ID should be the ID of another block in this flow graph. \
Function name should be the name of a class method on that block. \
Function args are the parameters passed into that function. \
For a function with no arguments, leave function args blank. \
When passing a string for the function arguments, quote the string literal: '"arg"'.

The values will used literally, and generated into the following form:
self.block_id.function_name(function_args)

To poll a stream for a level, use this with the probe signal block.
	</doc>
</block>