Arduino BufferStream Library

Industrial Shields Library
September 3, 2019 by
Arduino BufferStream Library
Boot & Work Corp. S.L., Dani Salvans Quesada

Requirements

Here you have the link to check out the available devices in our website which you can use to test this library:

- WiFi & Bluetooth Controller Family

- 20 I/Os Controller Family 

- Ethernet Controller Family

- GPRS / GSM Controller Family

Here you have the link to download our Boards:

 - Installing the Industrial Shields Boards in the Arduino IDE (Updated)


Explanation

With this library, you can convert any type of data to an Arduino Stream. First of all, you have to include the library.

#include <BufferStream.h>

You can read data from a Stream or write data to a Stream. To read data you have to set the buffer from where you want to read and the size of that buffer.

String data("This is the string!");
ReadBufferStream stream(data.c_str(), data.length());

Now you can read the data of the stream like it was an Arduino Serial.

while (stream.available()) {
  Serial.print((char) stream.read());
}

To write data you have to set the buffer and the size buffer where you want to write.

WriteBufferStream stream(data, 100);

Now you can send or write data like it was an 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')); 


Examples

You can see read and write String examples in the following paragraphs:

ReadString

// 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
}


​Search in our Blog

Arduino BufferStream Library
Boot & Work Corp. S.L., Dani Salvans Quesada September 3, 2019

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>