Hey all.
Have a crude serial read going on now. I modified the Class here with a change in the read function to read 1 byte or wait until it has data in the queue.
And created a Parser that looks at that char and compares its to a newline '\n' or a carriage return '\r' or add to a buffer.
Works for the purpose.(going to buy a wifi card soon anyway).
One more issue was that the board was sending too many temp messages and flooding the queue, Which left me wondering why the temperature was not increasing
as quick as it was on the Love o meter's LED lights, And in the arduino's IDE viewer.
heres me hack or the serial read.
.
//we dont return un till we get data now
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);
//we will spin on the empty buffer
while(status.cbInQue < 1)
{
Sleep(200);
ClearCommError(hSerial, &errors, &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
// {
// return -1;
// 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;
}
//--------------------------------------------------------------------------
//this will read data 1 byte at a time until it gets to the carrage return
//then it will return the message
//---------------------------------------------------------------------------
int Serial::ParseData(char *outbuffer, int buffersize)
{
static int pos = 0;
int rpos;
char readch;
while(ReadData(&readch, 1) > 0)
// if(readch > 0)
{
switch (readch)
{
case '\n': // Ignore new-lines
break;
case '\r': // Return on CR
rpos = pos;
pos = 0; // Reset position index ready for next time
return rpos;
default:
if (pos < buffersize-1)
{
outbuffer[pos++] = readch;
outbuffer[pos] = 0;
}
}
}
return -1;
}//end ParseData
////////////////////////////////////////////////////////////////////////////////////