Basic Activities

Glossary Item Box

VPL Reference: Data TypesVPL MenusUtilities Overview

See Also Microsoft Robotics Developer Studio Send feedback on this topic

Basic Activities

The Microsoft Visual Programming Language (VPL) includes a set of basic activities that are used to help create a dataflow program. These blocks are typically used to connect between service blocks, but can also be connected together.

Bb466256.Activity(en-us,MSDN.10).png

Activity

The Activity block, sometimes referred to as a Custom Activity, allows you to create your own activities that can each have their own set of internal dataflow diagrams.

You can use these to create diagrams that can be represented as single blocks in other diagrams and are used in the same way as the built-in activities.

These custom activities can also be compiled into services that can be used with other services or in other VPL diagrams.

Bb466256.Calculate(en-us,MSDN.10).png

Calculate

The Calculate activity performs simple arithmetic or logical operations on the expression entered into the textbox. The expression can include numeric values, the value from the incoming message, its data members, or predetermined values provided by other services on your diagram.

For numeric data you can use:

+

add

-

subtract/minus

*

multiply

/

divide

%

mod (The modulus operation returns the remainder after a division)

The plus (+) operator can also be used to concatenate, combine, strings. This can also be used to combine text, string, and numeric data by using double quotes, e.g. The answer is + x/4.

For logical operators you can use:

&&

AND

||

OR

!

NOT

You can also use parenthesis to support precedence (the order of evaluation) of the expression entered.

Clicking in the textbox of the Calculate block displays a list including the value of the incoming message, any data members in the message, the state variables, as well as predefined values that may be provided by other services.

Bb466256.Comment(en-us,MSDN.10).png

Comment

The Comment activity enables you to add a block of text to a diagram for documentation purposes. It is good practise to add comments to your code to assist other people to understand the program and also to aid your own memory if you have to change the program at a later date.

Enter the text of the comment in the textbox.

The Comment block does not support any connections. You can place it anywhere on the diagram.

You can collapse a comment by clicking on the arrow at the right-hand side of its title bar.

Bb466256.Data(en-us,MSDN.10).png

Data

The Data activity is used to supply a simple data value to another activity or service. To define a specific kind of data, select its type from the drop-down under the textbox, then enter a value into the textbox. Note that if you add a string value you do not need to enclose it in quotation marks.

Bb466256.If(en-us,MSDN.10).png

If

The If activity provides a choice of outputs to forward the incoming message to based on a test condition that you enter. If the condition is true, the the incoming message (with its data) is forwarded to the first outgoing connection (the top pin). If it is false (i.e. not true), then the Else output is used.

The conditional expression can use the following operators for evaluation:

= or ==

equals

!= or <>

not equals

<

less than

>

greater than

<=

less than or equals

>=

greater than or equals

You can also use the same operators in the Calculate activity, provided that the entire statement will evaluate to true or false.

You can add conditions to the If activity by clicking the Add (+) button on the activity block. Each new condition has its own output pin. So you can have several different conditional expressions in the one If block. Conditions are evaluated from top to bottom and the first one to have a result of true will be used.

Bb466256.Join(en-us,MSDN.10).png

Join

The Join activity combines the flow from two (or more) dataflows.

It is significantly different from Merge in that the data in the messages from the incoming connections is combined and messages must be received on all incoming connections before the activity passes on the data.

The text the you enter into the text boxes here are names of the local variables that represent the messages. You can use the variables directly or use dot notation to reference a data member. For example, value.field refers to the data member called "field" in the variable called "value".

One use for a Join is to construct a complex data type that is required as input to an operation on a service. Several different messages can provided the data members and the final result is sent to the service in a single message.

Bb466256.List(en-us,MSDN.10).png

List

The List activity creates an empty list of data items.

To create a list, select the data type for the items from the drop-down list of choices on the Activity block, or in the Properties view.

To add entries to the list, use the List Functions activity.

To store a list for use elsewhere in your diagram, create a list variable using the Variable activity.

Bb466256.ListFunctions(en-us,MSDN.10).png

List Functions

The List Functions activity enables you to modify an existing list.

Use the drop-down list on the block to select what function you want to apply to a list.

Bb466256.Merge(en-us,MSDN.10).png

Merge

The Merge activity simply merges the flow of two or more dataflows together. There is no condition or dependency on the other branch(es) on when messages are passed along. The activity’s role is simply to pass the messages along to the next activity.

Bb466256.Switch(en-us,MSDN.10).png

Switch

The Switch activity can be used to route messages based on the whether the incoming message matches the expression entered into the text box.

You can add Case branches (match values) to the activity block by clicking the Add (+) button on the activity block.

The Switch is similar to an If, but the test condition checks whether the incoming data value matches (is equal to) each of the values in the text boxes. So the text boxes only contain values. On the other hand, an If can have completely different test conditions for each output pin.

Bb466256.Variable(en-us,MSDN.10).png

Variable

The Variable activity enables you to set or get the value of a variable.

To choose a variable select it from the drop-down list displayed by clicking on the down-arrow button at the right-hand end of the text box.

If you have not defined any variables or wish to create a new variable, select Define Variables from the drop-down list, or select Variables from the Edit menu. This will display the Define Variables dialog box where you can add a variable and define its type. Variable data types include integers (int), double precision floating-point numbers (double), strings of characters (string), types of Lists, etc. See Data Types for the full list.

Variable names are case-sensitive. So when referencing a variable always be careful to use the same case. Names must also start with a letter and include only alphabetic or numeric characters. No punctuation characters are allowed except for the underscore (_).

Variable activities are simple constructs that support a GetValue connection, to get its value, as well as a SetValue connection, to set its value. When using the SetValue connection, the output connection of the activity also passes a variable on its outgoing connection.

See Also 

VPL Reference: Data TypesVPL MenusUtilities Overview

 

 

© 2012 Microsoft Corporation. All Rights Reserved.