The MLP UI Message Processor component responds to messages sent to an interface panel from an Arduino or other serial source. It allows the Arduino to:

  • changes values in controls on the interface panel
  • get values from controls on the interface panel
  • invoke messages in a message library attached to the message processor

MLP UI Message Processor detects and processes serial messages in the form: {UI:ChannelName|command|command data} Where each message to be processed must be surrounded by braces (‘{‘ and ‘}’) and

  • UI is the message type and is required.
  • :ChannelName sets the message processor channel, and is optional. Channels are useful if you want several interface panels in one project, each handling a different set of commands. In most situations a single panel is enough and the ChannelName field of the MLPUIMessageProcessor can be left blank.
  • command is required, and defines the action that the message processor will take. Supported commands include: SET, GET, CMD
  • command data is the data used by a command. All commands require data.

Examples

The following are examples of messages that will be processed by the MLP UI Message Processor when sent from an Arduino or other serial source.

  • {UI|SET|TextBox.Text=So long and thanks for all the fish}: set the content of a text-box control named TextBox to So long and thanks for all the fish.
  • {UI|SET|Number.Value=42}: set the current value of a numeric up/down control named Number to 42
  • {UI|SET|CheckBox.Checked=True}: check the check-box control named CheckBox
  • {UI|GET|Number.Value}: get the current value of a control named Number
  • {UI|CMD|SendTime}: run the command named SendTime

Setting Control Values

Before you can start setting control properties using the serial connection you need to make sure your interface has a MLPUMessageProcessor control inside the interface you want to communicate with. This can be found in the list of controls when designing your interface.

A message library attached to an Arduino message processor

An MLPUIMessageProcessor must be inserted into the interface panel before the interface can be modified by the serial connection.

The SET command is used to update control properties on the Interface Panel. The general format of the command is: {UI:ChannelName|SET|ControlName.Property=NewValue} or {UI:ChannelName|SET|ControlName.Property=[Expression]}Here NewValue or Expression is the value to assign to the control property. Expression may contain simple expressions, including referencing other controls on the Interface Panel. The ControlName is set in the Interface Panel designer.

Control name set in Interface Panel Designer

A control’s name is set in the Interface Panel designer.

The table below illustrates the properties exposed by controls supported by the Interface Panel. Not all controls have properties that can be changed using the SET command.

The control and component properties available are listed in the table below. The first table shows common properties and the second shows specific properties. Read only properties can not be changed using serial messages.

Interface Panel - Common Control Properties
ControlPropertyTypeRead OnlyDescription
Common to allForeColorStringnControls the foreground colour of the control
BackColorStringnControls the background color of the control
VisibleBooleannWhen set to "True" the control is visible to the user
EnabledBooleannWhen set to "True" the control is enabled
Interface Panel - Specific Control Properties
ControlPropertyTypeRead OnlyDescription
Dynamic LabelTextStringnThe text displayed in the label.
Text boxTextStringnThe text displayed in the control
ReadOnlyBooleannIf "True" then the text box can not be edited by user
TextLengthIntegeryThe length of text displayed in the control
NameStringyThe name of the control
Numeric up/downValueDecimalnThe current value displayed in the control
MinimumDecimalnThe minimum value allowed
MaximumDecimalnThe maximum value
NameStringyThe name of the control
Value listSelectedIndexIntegernThe index of the selected item in the list. First item is index 0. -1 if no items selected.
SelectedNameStringnThe name associated with the selected item. Only supported for single selection lists.
ValueUnsigned IntegernThe value associated with the selected item. When multiple items are selected, returns the values of each selected item or'ed together.
NameStringyThe name of the control
CheckboxCheckedBooleannThe current check state of the control
NameStringyThe name of the control
RadiobuttonCheckedBooleannThe current check state
NameStringyThe name of the control
Trackbar with IndicatorValueIntegernThe current value shown in the control
DelaySendingChangesBooleanyIf "True" serial message is only sent after mouse is released.
MinimumIntegernThe minimum value
MaximumIntegernThe maximum value
NameStringyThe name of the control
Progress barValueIntegernThe current value shown by the control
MinimumIntegernThe minimum value
MaximumIntegernThe maximum value
NameStringyThe name of the control
PictureBoxVisibleBooleannWhen "false", the control is hidden. If true the picture box is visible.

Some Examples

Here are some examples. Note colours can be specified in text, and RGB hex values.

{UI|SET|txt.ForeColor=8855FF}
{UI|SET|txt.BackColor=Blue}
{UI|SET|txt.ForeColor=Red}
{UI|SET|txt.Enabled=False}
{UI|SET|txt.Enabled=True}
{UI|SET|txt.Visible=False}
{UI|SET|txt.Visible=True}

Retrieving Control Values

Control properties can be retrieved from an Interface Panel using the GET command. The general format of the command is: {UI:ChannelName|GET|ControlName.Property|Format} Here ControlName and PropertyName are the name of the control and property required. Format is an optional parameter that can be used to control the format of the result returned.

Property Formatting

The Format parameter in the GET command is passed to the C# ToString function. It may be used to control the formatting of the text returned. For example, the decimal value in a numeric up/down control can be returned with 3 decimal places using: {UI|GET|Number.Value|0.000}

Response Format

When a GET command is received by a message processor, it returns the information requested using the MegunoLink Pro message format. The general format of the message returned is: {UI:ChannelName|set|ControlName.Property=CurrentValue} The channel name is only included in the message return if it is set on the MLPUIMessageProcessor component.

Executing Commands

A message library attached to an Arduino message processor

Attaching a message library to a message processor allows messages to be invoked from the Arduino using the CMD command.

A command in a message library attached to the MLPUIMessageProcessor can be invoked using CMD command. The general format of the command is: {UI:ChannelName|CMD|MessageName} Here MessageName is the name of the message in the message library to be invoked.

For example:

  1. Add a message library named MyMessages to an interface panel
  2. Add a message processor to the interface panel
  3. In the properties for the message processor, select MyMessages for the message library
  4. In the properties for MyMessages edit the Messages collection
    1. Create a new message and name it SendTime
    2. Set the message to: The time is: [DateTime.Now]\n
  5. Send {UI|CMD|SendTime} from the Arduino
  6. MegunoLink Pro will respond with: The time is: 20/02/2014 5:26:18 p.m.
Recent Posts

Leave a Comment

Start typing and press Enter to search