Bserial Library for the Arduino

  • Library file for buffered serial communication, current Arduino version 1.01

This is a cut down version of NewSoftSerial as the BV devices do not need such sophistication and it cuts the size down quite a bit. The ASI devices do however need buffered serial and so the SoftSerial library will not do. You can substitute this library for the NewSoftSerial if required but it will need all of the puts and putch changing for print. The class uses some C code that does all of the work and there is a good opportunity to write the put and get in assembler thus possibly improving the speed. It has a 32 byte circular buffer that will stop receiving when it becomes full.

BSerial(receivePin, transmitPin)

Sets the tx and rx pins.


Sets baud rate and clears buffer. This works up to 38400 on the Nano but that is without doing anything else. The rate need not be a fixed standard rate. For your system it may be advisable to adjust it slightly – see appendix.

handshake(uint8_t rtsPin, uint8_t ctsPin)

This method can be left out and the hardware handshaking will be ignored. RTS is an output that is set normally high. If the buffer should become full then the line goes low. This will indicate to the connected device to stop sending bytes until it goes high again. The CTS pin is an input and if activated must be held high by the connected device, if the line is put low the Arduino will stop sending characters and wait for the line to be put high again. It is more normal for this pin alone to be active as the connected device is usually slower then the Arduino.

If only one is required then set the other to 0xff. Foe example if pin 9 was used for the CTS the method would look like this:
handshake(0xff, 9);


Resets the buffer back to 0, effectively empties it.

putch(char c)

Puts a single character to the serial output.

unsigned char puts(char *s)

Puts a string to the serial interface and returns the number of bytes sent. This is limited to a maximum of 255 bytes, the method will return after that.

unsigned char buffer()

Returns the number of characters waiting in the buffer.

char getch()

Gets a single character from the buffer. NOTE that this method will return -1 if there are no characters in the buffer.