The Message class provides methods to send data and commands to message monitor and message logger visualizers. Message monitors write data to a text window while message loggers write data to a disk file. Message provides fine control over the data written. Refer to the raw monitor and logging visualizers for visualizers that write all data received to a text window or log file respectively.

To use message functions:

  1. Add #include "MegunoLink.h" to the top of your Arduino program
  2. Create a Message variable.
  3. Call methods on the Message variable such as SendData.

Data sent with the Message class will be received by both message monitor and message logger visualizers. Use message channels to send separate data to different visualizer windows.

Message Library Example

This simple example sends the millis() time and two ADC measurements. The comma-separated data starts with the Begin() and finishes with the End() method. Between these two calls, standard Serial.print(…) methods add content to the message that will be sent. The numbers are all separated by commas and could be easily pasted into Excel.

Every 100 measurements it sends a separator using the Send(…) method. For single values with labels, you don’t need to use the Begin() and End() methods.

CSV Arduino Data

The example Arduino program sends comma separated values to the message monitor

Methods

Message methods are:

Detailed Descriptions

The parameters for each method are described below. Optional parameters are surrounded by []‘s. Text parameters support in memory strings (const char*) and flash memory strings (F(…)) where available.

Message constructor

Creates a Message variable, which can be used to send data and control message monitor and message logger visualizers.
Message([MessageDestination], [ChannelName], [Destination])

Parameters
Name Type Required? Description
MessageDestination MessageDestination No Applies to message monitor visualizer only. One of Message::Text, Message::Speak, or Message::TextAndSpeak, which tells MegunoLink whether to add the message data to the text buffer or speak it using the text-to-speech engine, or both. Defaults to Message::Text.
ChannelName Text No sets the channel used for all methods called on the variable. If missing, data is sent to the default channel
Destination Print No the stream used for all methods called on the variable. If missing, data is sent to the standard Serial port

Sending values

Sends a value, with an optional label, to the Message Monitor.
Send(Value)
Send(Label, Value)

Parameters
Name Type Required? Description
Value TValue No The value to send. Supports any type that can be used in Serial.print(…).
Label Text No A label for the value.

Start block

Starts a message block. This method sends the first part of the message command. Content sent to the serial stream before the End() method is called will all be written to the message monitor/ message logger.
Begin()

This method takes no parameters.

End block

Completes a message block. Any content sent between the Begin() and End command will be send to the Message Monitor.
End()

This method takes no parameters.

See start block above for an example.

Clear message buffer

Sends a command to clear the message monitor text window. No effect on the message logger.
Clear()

This method takes no parameters.

Set log filename

Changes the log filename and begins logging. The LogTo command will only be accepted by MegunoLink if the Allow serial commands to start and stop logging and the Allow serial commands to set filename options are enabled in the Configure Log Path dialog. Only applies to the message logger visualizer.
LogTo(Filename)

Parameters
Name Type Required? Description
Filename Text Yes The name of the file to write the log to. Filename is combined with the BaseFolder and Folder set in the message logger visualizer to set the path where the log file will be written.

Start Logging

Starts writing the serial stream to the selected log file. Only applies to the message logger visualizer. The StartLogging command will only be accepted by MegunoLink if the Allow serial commands to start and stop logging option is enabled in the Configure Log Path dialog.
StartLogging()

This method takes no parameters.

Stop Logging

Stops writing the serial stream to the selected log file. Only applies to the message logger visualizer. The StopLogging command will only be accepted by MegunoLink if the Allow serial commands to start and stop logging option is enabled in the Configure Log Path dialog.
StopLogging()

This method takes no parameters.

See start logging above for an example.

Flush log

Writes any log content buffered in memory to the log file. Only applies to the message logger visualizer. The Flush command will only be accepted by MegunoLink if the Allow serial commands to start and stop logging option is enabled in the Configure Log Path dialog.
Flush()

This method takes no parameters.

Start typing and press Enter to search