Use the SerialConnection component to automatically send a message to your Arduino sketch when MegunoLink connects. This is commonly used to send configuration information to your Arduino program from controls on an interface panel or to instruct your Arduino sketch to begin sending data to MegunoLink.

To send a message automatically when you open a serial connection:

    1. create an interface panel and add controls for the user to enter the parameters you wish to send,
    2. add a SerialConnection component to the interface panel,
    3. set the SerialConnection‘s OnConnectSend property to the message MegunoLink should send when the connection is opened,
    4. set the Delay property, if necessary, to provide time for your Arduino program to get ready (some devices may be reset when a connection is opened).
Send on connect
MegunoLink can send messages with parameters from an interface panel when a connection is opened.

Set up the Serial Connection Component

Add a SerialConnection component to your interface panel by dragging it from the toolbox onto the design surface in the interface panel designer.

The SerialConnection components lives in the component tray at the bottom of the design surface. Unlike buttons and textboxes, it is not visible to the user at run-time.

Send on connection user interface

Add a SerialConnection component and set the OnConnectSend properties to send a message to your Arduino sketch whenever MegunoLink opens a connection.

Create a Message

Select the SerialConnection component to view its properties. Set the OnConnectSend to the message that MegunoLink should send when a connection to the device is opened. A typical message could include a command name and parameters obtained from controls on the interface panel, such as: !SetParameters [numOnTime.Value] [numOffTime.Value]\r\n.

Type the message directly into the property grid or click the ellipsis (Ellipsis) to open the message editor window.

Implement a command handler in your Arduino sketch to take an appropriate action when the message is received.

Set a Delay

If your command is not received reliably by your Arduino device it may not be ready to process commands as soon as the connection is opened. Many devices are reset, for example, when a serial connection is opened and are not ready to process commands until the bootloader times out and the setup() function is complete.

Set the Delay property on the SerialConnection component using the property editor in the interface panel designer. MegunoLink will wait until the delay has passed after the connection has been opened before sending the message. A delay of 1000 – 3000 ms (1 – 3 seconds) is usually sufficient.

Leave a Comment

Start typing and press Enter to search