Your Arduino sketch can request data from a MegunoLink interface panel with a message library and MLPUIMessageProcessor. The steps to set this up are:

  1. create an interface panel and add controls for the user to enter the parameters you wish to request (see getting started building an Arduino interface),
  2. add a MessageLibrary component to the interface panel,
  3. add a MLPUIMessageProcessor component to the interface panel,
  4. set the MLPUIMessageProcessor‘s Library property to the message library created above,
  5. add named messages to the MessageLibrary that will return the information required by the Arduino sketch,
  6. create an InterfacePanel variable in your Arduino sketch and use its CallCommand method, passing in one of the named messages defined in the message library,
  7. handle the command sent to your Arduino sketch by the message library (see processing serial commands with an Arduino).

It is generally easier to send configuration data from controls on an interface panel when the user clicks a button or a connection is opened.

You can also store configuration in the eeprom so it is available when the device starts.

Message library communications

Commands stored in a message library component can be called from your Arduino sketch to request parameters from an interface panel.

Set up Interface Panel Components

Add both a MessageLibrary and MLPUIMessageProcessor to your interface panel. Both can be found in the Communications group of the interface panel designer toolbox. They can be added to your interface panel by dragging them from the toolbox onto the design surface.

The MessageLibrary and MLPUIMessageProcessor live in the component tray at the bottom of the design surface. Unlike buttons and textboxes, they are not visible to the user at run-time.

Link the message library to the message processor component using the processor’s Library property. Select the MLPUIMessageProcessor to view its properties and choose the message processor from the dropdown list on the Library property.

Set up steps for interface panel components

Add a MessageLibrary and MLPUIMessageProcessor then set the Library property of the message processor to link the two together.

Create Messages

Messages that can be called from your Arduino sketch are stored in the message library. Select the message library component and click the ellipsis (Ellipsis) button to open the Message Library Editor.

The Message Library Editor is used to manage the messages stored in the message library. Each message has a:

  • Name, uniquely identifying the message in the library,
  • Command, the response sent to your Arduino sketch when the message is called, and
  • Note, a short text to help you remember what the message is for (optional).
Edit message library

Edit the messages, and associated commands, using the Edit Message Library dialog box.

Use the New button to add a new message. Select the message to edit or delete it. The Command can reference other controls on the interface panel. See creating serial commands for details.

Call the Message and Handle the Response

Use an InterfacePanel variable to call the message from your Arduino sketch:

You’ll also need to handle the response from MegunoLink. Using the CommandHandler from our Arduino library is one solution. Our guide to getting started processing serial commands with an Arduino provides a comprehensive introduction to the command handler.

Leave a Comment

Start typing and press Enter to search