I'm porting a C++ program from Visual Studio 2010 on Windows to Ubuntu 12.04. It uses this SerialClass.cpp and .h library to connect to the Arduino on Windows:
http://playground.arduino.cc/Interfacing/CPPWindows
I've removed all dependencies on this library except this call to ReadData:
// read a raw byte
if (SP->ReadData(incomingData + readResult,1) == 1)
readResult++;
else
continue;
I'm looking for a function, library, or a way to rewrite ReadData to do the same thing in Linux. Any advice? Thanks!
Here's ReadData from Serial.cpp:
int Serial::ReadData(char *buffer, unsigned int nbChar)
{
//Number of bytes we'll have read
DWORD bytesRead;
//Number of bytes we'll really ask to read
unsigned int toRead;
//Use the ClearCommError function to get status info on the Serial port
ClearCommError(this->hSerial, &this->errors, &this->status);
//Check if there is something to read
if(this->status.cbInQue>0)
{
//If there is we check if there is enough data to read the required number
//of characters, if not we'll read only the available characters to prevent
//locking of the application.
if(this->status.cbInQue>nbChar)
{
toRead = nbChar;
}
else
{
toRead = this->status.cbInQue;
}
//Try to read the require number of chars, and return the number of read bytes on success
if(ReadFile(this->hSerial, buffer, toRead, &bytesRead, NULL) && bytesRead != 0)
{
return bytesRead;
}
}
//If nothing has been read, or that an error was detected return -1
return -1;
}