Requisitos
Aquí tiene los enlaces para ver los dispositivos disponibles en nuestra página web para probar esta librería:
- Familia de controladores WiFi y Bluetooth
- 20 E/S Familia de controladores
- Familia de controladores Ethernet
- Familia de controladores GPRS / GSM
Aquí tiene el enlace para descargar nuestras Boards:
- Instalando las Boards de Industrial Shields en Arduino IDE (Actualizado)
Explicación
Con esta librería puede convertir cualquier tipo de datos a una Arduino Stream. Antes de nada, debe incluir esta librería.
#include <BufferStream.h>
Puede leer datos de una Stream o escribirlos en una. Para leer datos debe establecer el buffer desde donde quiera leer y la medida de este.
String data("This is the string!");
ReadBufferStream stream(data.c_str(), data.length());
Ahora puede leer datos de una stream como si fuera Arduino Serial.
while (stream.available()) {
Serial.print((char) stream.read());
}
Para escribir datos debe establecer el buffer y la medida de este donde usted quiera escribir.
WriteBufferStream stream(data, 100);
Ahora ya puede enviar o escribir datos como si fuera Arduino Serial.
// Add data to stream
stream.print("Hello");
stream.print(' ');
stream.print("WriteStream!");
// Add the '\0' character at the end of the stream
stream.write(uint8_t('\0'));
Ejemplos
A continuación tiene algunos ejemplos para leer y escribir Strings:
// BufferStream library example
// by Industrial Shields
#include <BufferStream.h>
String data("This is the string!");
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Create stream from data
ReadBufferStream stream(data.c_str(), data.length());
// Print data from the stream
Serial.begin(9600UL);
while (stream.available()) {
Serial.print((char) stream.read());
}
Serial.println();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// Nothing to do
}WriteString
// BufferStream library example
// by Industrial Shields
#include <BufferStream.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Create stream from data
char data[100];
WriteBufferStream stream(data, 100);
// Add data to stream
stream.print("Hello");
stream.print(' ');
stream.print("WriteStream!");
// Add the '\0' character at the end of the stream
stream.write(uint8_t('\0'));
// Print data
Serial.begin(9600UL);
Serial.println(data);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// Nothing to do
}