Libraries \ Messenger

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Class

Messenger

Name

copyString()

Examples
#include <Messenger.h>


// Instantiate Messenger object with the message function and the default separator 
// (the space character)
Messenger message = Messenger(); 

// Define the max size of the string
// The size must be big enough to hold the longest string you are expecting
#define MAXSIZE 30 

// Create a char array (string) to hold the received string
char string[MAXSIZE]; 

// Define messenger function
void messageCompleted() {
  // This loop will echo each element of the message separately
  while ( message.available() ) {
    message.copyString(string,MAXSIZE);
    Serial.print(string); // Echo the string
    Serial.println(); // Terminate the message with a carriage return
  }
}

void setup() {
  // Initiate Serial Communication
  Serial.begin(115200); 
  message.attach(messageCompleted);
}

void loop() {
  // The following line is the most effective way of 
  // feeding the serial data to Messenger
  while ( Serial.available() ) message.process( Serial.read() );
}
Description Copies the element as a string into the the array pointed by the target char array. The maximum size must match the size of the target char array. The element is removed from the completed message.
Syntax
copyString(string, size)
Parameters
string The target char array.
size Maximum size of the array
Returns None
Usage Application
Updated on July 07, 2011 11:11:04pm PDT

Creative Commons License