The WrapperSerial class was something I hacked up from code from several places. Started off on the RPI to adapt my Arduino Port of the Phoenix code base (hexapod robots) to the Raspberry Pi. There are threads about this both on the Lynxmotion forums (
http://www.lynxmotion.net/viewtopic.php?f=25&t=8607&start=30 )as well as the Trossen Robotics Forums (
http://forums.trossenrobotics.com/showthread.php?6040-PhantomX-controlled-by-a-Raspberry-Pi). There were a few others up there also interested in this and one of them asked about getting input for the Arbotix Commander (XBee), so I start playing with this. I found some XBee code base and the like some place on the web... And I hacked up some code that appeared to work fine, but I knew that I was also going to want similar code to talk to the SSC-32 (Servo Controller), Debug output, ... So thought it would be nice to have a Serial class. So I hacked up some standard Arduino code (1.0.x) (Print, Stream, ...) to have it compile on the RPI, and then had the simple Wrapper class call into those.
I probably should put some more comments into the Headers :oops:
By default the serial system will probably try to buffer as much data as it can, until some conditions are met. I don't remember fully how the RPI is setup, but these conditions may include things like buffer is full (not sure of buffer size here), Could also include things like max delay (latency)... But they usually include a way to override this, by doing some form of flush operation, so for
example in some of my XBee code you will see things like:
void InitXBee(void)
{
uint8_t abT[10];
char szDevice[] = "/dev/ttyXBEE";
XBeeSerial.begin(szDevice, B38400); // BAUD rate is defined in Hex_CFG.h file...
// Ok lets set the XBEE into API mode...
delay(1000);
XBeeSerial.write("+++");
XBeeSerial.flush();
...
Note: I am using some device rules to give a symbolic name to the tty port that the XBee is on. On The RPI this is currently an FTDI usb device, currently on BBB this is to one of the USARTS on the expansion connectors ttyO2
Hope that helps
Kurt