Data Sheet
Avoid Buffer Overflow
In the section ‘Increase Output Rate’ on page 18 we mentioned how to increase the data output rate of TransducerM. To be able
to fully make use of the output data stream and avoid buffer overflow in your host system, the following tips are suggested.
In your code handling low-level serial data, simply add a few more calls to ‘On_SerialRX’ as defined in the section ‘C++
Library (Recommended, Full API)’ on page 22 and read out the buffer in a faster way, as shown below:
/**
* Low-level Serial Port Data Receive Function
* In a micro-controller, this is usually an interrupt function.
*/
void HelloMotionModule::On_Low_Level_Serial_Hardware_Event(){
char* rxData;
int rxSize;
// Real Serial Port: Set ‘rxData’ to point to the low-level serial buffer and get the buffer size:
Low_Level_Serial_Hardware_Read(rxData, &rxSize);
// Call the Data processing method as defined in section
// ‘C++ Library (Recommended, Full API)’ on page 22:
On_SerialRX(rxData, &rxSize);
// < WHEN AND WHY IT OVERFLOW >
// If you still experience low receiving data rate even if you have made the changes
// according to the section ‘Increase Output Rate’ on page 18,
// this means the low-level system serial buffer is larger than the entire length of
// a data package from TransducerM. Due to the fact that ‘On_SerialRx’ will return as soon
// as a valid package is found, this will result in too much residual data in the buffer which
// accumulates over time causing buffer overflow.
//
// < SOLUTION >
// The simplest way to overcome this is by calling the ‘On_SerialRX’ multiple times like below
// to make sure the processing of data within the buffer is at least not slower
// than its accumulation:
On_SerialRX(0, 0);
On_SerialRX(0, 0);
On_SerialRX(0, 0);
On_SerialRX(0, 0);
On_SerialRX(0, 0);
}
This tip is useful especially in some host system which embeds its own very large internal serial port buffer (usually the case
with Linux system).
Copyright © 2015-2019 SYD Dynamics ApS | www.syd-dynamics.com Page 24 / 33