|
|
![]() |
Microsoft Visual Programming Language |
|
Este documento fue descargado desde: http://msdn.microsoft.com/en-us/library/bb483088.aspx
VPL Introduction Microsoft Visual Programming Language (VPL) is an application development environment designed on a graphical data-flow-based programming model rather than control flow typically found in conventional programming. Rather than series of imperative commands sequentially executed, a data-flow program is more like a series of workers on an assembly line, who do their assigned task as the materials arrive. As a result VPL is well suited to programming a variety of concurrent or distributed processing scenarios. VPL is targeted for beginner programmers with a basic understanding of concepts like variables and logic. However, VPL is not limited to novices. The compositional nature of the programming language may appeal to more advanced programmers for rapid prototyping or code development. In addition, while its toolbox is tailored developing robot applications, the underlying architecture is not limited to programming robots and could be applied to other applications as well. As a result, VPL may appeal to a wide audience of users including students, enthusiasts/hobbyists, as well as possibly web developers and professional programmers.
Figure Sample Microsoft Visual Programming Language (VPL) diagram for simple bump-turn-go wander behavior. A Microsoft Visual Programming Language data-flow consists of a connected sequence of activities represented as blocks with inputs and outputs that can be connected to other activity blocks.
Figure The link arrows between the blocks represent messages that send data from one activity to another. Activities can represent pre-built services, data-flow control, functions, or other code modules. The resulting application is therefore often referred to as orchestration, the sequencing of separate processes.
Activities can also include compositions of other of activities. This makes it possible to compose activities and reuse the composition as a building block. In this sense an application built in VPL is itself an activity. Activity blocks typically include the activity’s name and borders that represent its connection points. An activity block may also include graphics to illustrate the purpose of the activity as well as user interface elements that may enable the user to enter values, assignments, or transformations for data used in an activity.
Activities are connected through their connection pins. A connection pin on the left side of an activity represents connection point for incoming/input messages and a pin on the right represents its connection point for outgoing/output messages.
An activity receives messages containing data through its input connection pins. An activity’s input pins are connection points to its predefined internal functions known as actions or handlers (which can be either as functions provided by a service or nested data-flows).
An activity block activates and processes the incoming message data as soon it receives a valid incoming message. All data sent to the activity is consumed by the activity. For data to be forwarded on through the activity’s output, the receiving activity must replicate the data and put it on its output connection. An activity may have multiple input connection pins and each with its own set of output connection pins. Output connection pins can be one of two kinds: a result output or notification output (sometimes also referred to as a event or publication output). Result outputs are displayed as rectangular connection pins while publication outputs have round connection pins.
A response output pin is used in situations where an outgoing message (data) is sent as the result of an specific incoming action message. Notification pins can send information resulting from an incoming message, but more typically fire a message as the a change their internal state. They can also generate messages multiple times, whereas a result pin only sends out a single message on the receipt of an incoming message. So notification output pins are used for sending message data without having to repeatedly request or poll for the state of an activity. You can start VPL from the Start menu under "Microsoft Robotics Studio". For tutorials on creating VPL diagrams see VPL Tutorials Overview.
GUIA DEL USUARIO Creating a Diagram To start Microsoft Visual Program Language, select its entry on the Start Menu. When VPL loads, you will see a window with a set of menus, tool boxes, and a tabbed diagram page.
The toolboxes display the current file contents of the project and activities you can use to create your diagram. The toolboxes are movable and collapsible, so you can rearrange them within the main VPL window. You can also selectively hide or redisplay a hidden toolbox window using the Toolboxes command on the View menu. To begin a dataflow diagram, drag and drop dataflow activity or service blocks from the toolboxes to the diagram area (tabbed page) and connect them. You can also add a new activity by double clicking its toolbox entry. Hovering over a toolbox entry with the pointer displays a tooltip that includes a description of how the activity may be used. You can cut, copy, paste, or delete activities by selecting the block in the diagram using the commands on the Edit menu or the activities pop-up context menu. The Basic Activities toolbox window The Basic Activities toolbox window includes blocks for controlling dataflow and creating data and variables. Also included is a Comment activity that allows you to place text comment blocks on your diagram.
The Services toolbox window The Services toolbox displays services that are compatible with VPL. When you drag a service from the toolbox that already exists in your diagram, you are asked whether you want to create a new instance of the service or you want to create a reference to the service already in your diagram. For example you might use the same service for a set of sensors or motors, but with different configuration settings. You can change the names of the services you put on your diagram by typing the new name into the text box at the top of the toolbox. The services displayed in this toolbox window depends on the contents of its search filter (query) box. Entering a word causes only those services with that word to appear in the window. The search looks for matches in both the display name of the service as well as its description. A blank search box finds all services. You can enter multiple words (separated with spaces) and the list is filtered by all those words. Putting a + between words causes the filter to assume both words must occur. Using a - excludes the word(s). You can save a search filter by clicking the + (add) button in the All Found heading. This creates a new section in the Services toolbox window with the results of your search filter using the words you used as the search filter. If you want to create a title for your search filter without the filter words, add "= title" to the search text. Now when you click the + add button in the All Found heading, the new section will use just that text. For example if you enter the following: NXT RCX = LEGO services and then click the + (add) button in All Found, you see a new section with just those services whose name or description include those words, but titled as LEGO Services.
The Project window The Project window shows the diagrams and configuration files (for services) included in your project. To close the current view of the diagram, click the X button on the diagram's tab. To redisplay the diagram, double click the name of the diagram in the Project window. If the diagram name is not currently displayed, click the + button to expand the Diagrams entry.
To change the name of your diagram, click on its entry in the Project window and edit its name in the property viewer. To add additional diagrams to your project, display the context pop-up menu for the Diagrams entry and click Add Diagram. To delete a diagram, display the context pop-up menu for the diagram and click Delete.
The Properties window The Properties window displays the properties for the current selected item. This allows you to adjust the settings exposed by that service or activity.
Creating and Editing Activities You can create your own activities with VPL. To do this, drag an Activity icon from the Basic Activities toolbox and open it (using its context pop-up menu or double-clicking the activity block). This will open a new tabbed diagram pane for the activity.
VPL creates a default Action template for you. If the Action page is not displayed when you open the activity, use the Action dropdown just under the tab area. You can then insert other activities and connect them as you did on the your main dataflow diagram.
However, to enable your internal dataflow to be usable in by another dataflow, you must connect the internal dataflow to your activity’s external pins. To do this simply drag a connection from the action pin to the input for the beginning of the dataflow you are creating inside the activity to the Action connection pin on the left border and the ending output to the Result connection pin on the right border.
To define the name and datatype for your activity’s external connection pins, select the Actions and Notifications command from the View menu. To change the name or type select the entry from the list, change their entries and click OK.
If the dataflow you are creating within the activity generates output multiple times, connect its output to a Notification connection. You can use the Actions and Notifications dialog, by clicking the Notifications tab, then click Add button and supply the name and type. After clicking OK, you can now drag a connection from the output of your dataflow to the round notification connection you just created.
You also can use the Actions and Notifications dialog to create additional action handlers for your activity. To add another action handler, click the Actions tab in this dialog and then click the Add button. To switch to the newly created action, select it from the Action dropdown at the top of the Activity’s page. Sometimes you might create an activity that executes some function, but doesn’t need input or output connections. You can use the Start action for a situation like this. VPL automatically includes a Start action page for your activity. You can use this to put in a dataflow you want to execute when your activity starts regardless of what its connections are.
Configuring Services Services require configuration information about how they should start (settings for initial state) and also what "partner services" may also need to be started with the service. These are displayed in the Properties window when the service is selected or you can display Set Configuration page by clicking the Set Configuration command from the Edit menu or the service's context pop-up menu or by double clicking the service block. Depending on the service, you may have one of four options to set the initial configuration of a service.
Set initial configuration Here you set the initial state values for the service (instance) and can also select what partner services (services that provide support for the service) the service uses. For the partners you select you may choose to use the service's definition for how to set up its partners or to select another service to use. A service can have state which includes its configuration. By setting its initial state you configure the service. Configuration can include state properties like serial communications port and baud rate, as well as physical properties like wheel diameter and distance between wheels for a drive service uses to apply its operations. You can set these initial configuration properties either in the Properties window or on the Initial State tab of the Set Configuration page. Some services define partners used for their operation. For example a differential drive service needs two motor services. Optionally it can also use two wheel encoders. You can define what services to use for those partners by dragging them from the toolbox to their entries on the Partners tab of the Set Configuration page or by selecting them from the drop down list in the Properties window. The services you select as partners can also be configured. When you set the initial configuration of a service, VPL add this as a file to your project. If you delete the service, if you have set its initial configuration, VPL will display a warning asking you to confirm the deletion since doing so will also delete the configuration file. You can also delete a configuration file by selecting it and displaying its context pop-up menu and clicking Delete.
Use another service Here you use
another service's implementation. You can select a specific service to use or the
DSS runtime find or create an appropriate service. This enables you to use generic
services in your diagram and simply change the actual service used without changing
your diagram. The service you selected can also be configured. Use a manifest This option
enables to select an existing manifest file to start the service. A manifest
is a special file that describes the services to be started and their configuration.
Use the Import Manifest command to display a list of existing manifests which can
select. You can then select a service that is started by this manifest. You can
also chose to let the DSS runtime find or create an appropriate service. To create
a manifest, see "Robotics Tutorial 3 – Using Abstract Services". None This option indicates you want the DSS runtime to find or create an appropriate service. This is the default option. The option is appropriate for most simple services (for example, the Math Functions, Simple Dialog, or Text-To-Speech services).
Connecting Activities To connect two activity blocks, you drag from the connection pin of one activity to the pin of the other. If there are multiple ways (outputs and inputs) to connect the activities a Connections dialog box will appear so that you can define which of the inputs and outputs you want to connect.
To complete the connection, you select a result output connection from the left list and an action from the right list and click OK. A link will appear between the activities. If there are no connection options, the Connections dialog does not appear. Often the options available for an activity’s output may depend on what its input connection is.
Sometimes connections between activities also requires matching up the data to be passed between the connections. When this occurs a Data Connections dialog appears and displays the message sender’s data options on the left side and the receiver position on the right. Incoming data options can include the default value for its data type (0 for numeric types, false for Boolean types, and null for all other types), the value of the data, or sub-data (data member) values.
You can change a connection from one activity to another by selecting the connection link and dragging the end you want to reconnect. You can also change the connections or data matchups by selecting the pop-up context menu on the connection link. Connection links can be deleted by selecting the link and selecting Delete from the Edit menu or the pop-up context menu for the link (or pressing the Del key).
If an activity supports several input connections (action handlers), you can only connect to one at a time. If you have already connected a link to an activity and you want to connect to one of its other input pins, create a copy (reference) of the activity block and connect to it.
You also cannot have multiple direct connections to the same input connection (action) pin. However, you can use Merge or Join activities to route or consolidate messages from multiple activities to the same input connection pin. An activity can also multiple output connections but you can only connect to one of these at a time. So if an activity has both result and notification output connection pins, you must use separate references of the activity to connect to its other connections. However, you can create multiple connections to the same output pin. You also cannot connect two (or more) notification connections to a Join activity. This is also true between connecting two or more data flows that include notification connections regardless of where they reside in the data flow. However, you can use a Merge activity.
Running And Debugging To run your VPL project, select Start from the Run menu. This will start your application. A dialog box appears with a hyperlink to a debug trace as well as a Stop button to stop your project.
If you click the debug link, a summary Web page is displayed. You can use the buttons on the page to pause and step through the operation your diagram.
Because your
project may complete before you access the debug page, you may not be able to control
its operation. However, you can use the Debug Start command to start your
project and stop at its first block, and enable you to step through the program.
The debug view also allows you to see message values as you step through the diagram.
If you do not see your diagram in the debug page, try using the browser's Refresh
command to reload the page.
To stop your program, click the Stop button in the Run dialog.
Since your project is itself a service, when your project runs VPL launches the DSS runtime and loads your service. To do this, you need a HTTP and TCP port. VPL automatically sets default values for you. However, you can change these values, by clicking the Settings command on the Run menu. You can also get additional debug information on your application, but using a Web browser and setting its address to location of your port and /console/output. A link to this appears on the Debug page. You can also run your VPL application independently from the VPL development environment. To do this use the Compile As a Service command from the Build menu. This will create a service you can run from the DSS runtime using one of the following methods: · Start a DSS node by clicking the Run DSS node entry from the Start menu (under the Microsoft Robotics Studio entry). When the node starts up and the DSS Web page is displayed, click on the Control Panel entry, then type in the name of your project in the Search text box. This should display your project's name with a Create button. Click the Create button and your project will start. · Start the Microsoft Robotics Studio Command Prompt from the Start menu (under the Microsoft Robotics Studio entry). Then type in a command that starts DSS with the /p (port setting) option and the /c: (contract setting) with the name of the contract (which can be found in VPL by clicking on the Diagrams entry in the Project window), the current year, the current month, the filename of your project, and the words "diagram.html". dsshost.exe /p:50000 /c:http://schemas.tempuri.org/2006/12/helloworld/diagram.html
Code Generation Previous versions of MVPL have contained a simple code generation capability that allowed a service wrapper. However, the new code generation feature allows a diagram designed in MVPL to be converted into C# code that will compile to an assembly containing one or more DSS Services. This allows the ease of development to be combined with the power and speed of execution of C#.
In addition, the code that is generated can be used as a starting point for a developer to extend development of a diagram in areas that MVPL does not address, for example, performing complex computations.
Generating Code There are two steps to generating code: configuration; and Generating the code.
Configuring Code Generation The Diagram needs to be correctly configured for code generation. 1. In the Project toolbox click on the Diagrams folder 2. In the Properties toolbox ensure that the KeyLocation property correctly identifies the location of a strong name key (.snk file) this can usually be found in "samples\mrisamples.snk" 3. In the Properties toolbox specify the SourceLocation property. This configures a location where code files will be generated.
Note: These are the same steps for generating C# code as for creating the service wrapper.
Starting Code Generation From the Build menu select “Compile as a Service (No Interpreter)”, this will cause the “Create a Service” dialog box to be displayed. When compilation has completed successfully the message “Compilation complete.” will be displayed. If there is an error in compiling the service (see Known Issues) then an appropriate error message will be displayed. After successfully running the “Compile as a Service (No Interpreter)” command a new assembly will have been created and copied to the "bin" directory. In the location specified in the SourceLocation property there will be several .cs files and a .csproj file. These can be used to inspect and/or modify the generated code and recompile if necessary. Note: Generating the code again, will overwrite any changes made to the generated code without issuing a warning.
Running a Generated Service As with any other service in Microsoft Robotics Studio there are many ways to run a generated service. Note: see Known Issues for details about configuration… 1. Start a DSS node and use the control panel to start the generated service. · run dsshost /p:50000 /t:50001 · navigate to http://localhost:50000/controlpanel · locate your newly generated service in the list of services · click on the appropriate “Create” button in the control panel page. 2. Create a manifest file that references your newly created service by contract (the contract identifier for your service will be typically be found in the generated file DiagramTypes.cs, and can be modified by editing the ContractPrefix setting in the diagram properties before generating the code) and start a DSS node using that manifest in the /m startup parameter 3. Close and re-open MVPL (see Known Issues) and create a new diagram that uses your newly generated service (which will now appear in the Services list). When you run that diagram from MVPL in the usual way that will cause your generated service to run.
Known Issues · Enums are not yet supported. · The List functions are not yet supported. · In certain circumstances an “if” block that is followed by a “merge” can cause incorrect code to be generated. It should be possible to determine if this is the case by examining the code. · A newly generated service does not automatically appear in the service list in MVPL until MVPL has been closed and re-opened. · Services are not generated for .NET Compact Framework (CF) – It is possible to take the service that is generated and convert it to work with .NET CF by following the same procedure that is used when converting any other service to work with .NET CF. The code that is generated does not use methods that are not supported in .NET CF · Configuration information is not included in the generated services. If you have a diagram that orchestrates services and configures them, either by setting initial state and partners directly or by importing a manifest, the generated service will not start correctly. There are two ways to work around this: 1. After you have generated the assembly for the diagram, close MVPL, then re-open it. Create a new diagram and drag the service that was just compiled from the service list. Now configure that service and run the new diagram. This new diagram contains no code, it merely exists to configure the compiled service. 2. Manually create a manifest for the newly generated service that correctly configures the partner services. If you take this approach, you will need to modify the Partner attributes in the generated service code to change their PartnerCreationPolicy from UseExistingOrCreate to UsePartnerListEntry for any partners that need to be configured.
REFERENCE Basic Activities The Microsoft Visual Programming Language includes a set of basic activities that are used to help create a data flow program. These blocks are typically used to connect between service blocks, but can also be connected together.
Activity This activity block is used to enable you to create your own activities that can each have their own set of data flow diagrams. You can use these to create diagrams that can be represented as single blocks in other diagrams. Activities can also be compiled into services that could be used with other services.
Calculate The Calculate activity performs simple arithmetic or logical operations on the expression entered which can include numeric values, the value of the message, its data members, or predetermined values provided by other services on your diagram. For numeric data you can use:
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:
You can also use parenthesis to support precedence (order of evaluation) of the expression you enter. Clicking in the text box of the Calculate box displays a list including the value of the incoming message, any data members, as well as predefined values that may be provided by other services.
Comment The Comment activity enables you to add a block of text to a diagram. Enter the text you want to display in the text box. The Comment block does not support any connections. You can place it anywhere on the diagram.
Data The Data activity is used to supply a simple data value to another activity or service. To define a specific kind of date, select its type from the dropdown under the text box, then enter a value into the text box.
If The If activity provides a choice of outputs to forward the incoming message based on a condition you enter. If the condition is true, the first outgoing connection forwards on the incoming message (and its data). If it is not true, then the Else output is used. The conditional expression can use the following operators for evaluation:
You can also use the same operators Calculate activity, provided that the entire statement will evaluate to true or false. You can add conditions to the activity by clicking the Add (+) button on the activity block. Join The Join activity combines the flow of two (or more) data-flow. It is significantly different from Merge in that the data in the messages from the incoming connections is combined and all messages must be received on all incoming connections before the activity passes on the data. The text 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 (e.g. x.a) to reference a data member (sub-data item).
List The List activity creates an empty list of data items. To create a list, select the type (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.
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
Merge The Merge activity simply merges the flow of two (or more) data-flows together. There is no conditional or dependency on the other branch(es) on when messages are passed on. The activity’s role is simply to pass the message along to the next activity.
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 conditions) to the activity block by clicking the Add (+) button on the activity block.
Variable The Variable activity enables you to create a variable and set or get its value. To choose a variable you select it from the drop down list displayed when you click on the drop button adjacent to the text box.
If you have not defined any variables or you wish to create a new variable, select Define Variables from the list (or from the Edit menu). This will display the Define Variables dialog box where you can add a variable and define its type. Variables types include types of lists. 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 alphanumeric characters. 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 pass in variable on it outgoing connection.
Data Types
The Microsoft Visual Programming Language supports .NET Visual C# style data types.
Vpl Menus File New – Allows you to create a new project. Open – Opens a pre-existing project file. Save – Saves the current project. Save As – Saves the project under a specified name. Recent Projects – Displays and opens recent project files Exit – Quits VPL
|